3morrrrr commited on
Commit
190fcf3
·
verified ·
1 Parent(s): 9c5d5a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -58
app.py CHANGED
@@ -120,68 +120,41 @@ def generate_main_accounts(updated_data=None):
120
  # Global variable to store updated assignments from the main account generation
121
  UPDATED_ASSIGNMENTS = {}
122
 
123
- def generate_schedule(chatter_files, account_data):
124
- """
125
- Generate schedules for different shifts (Overnight, Day, Prime) using chatter and account data.
126
- """
127
- schedules = {}
128
-
129
- # Debugging: Log columns of the account data
130
- print("DEBUG: Account Data Columns")
131
- print(account_data.columns)
132
-
133
- # Validate required columns in the account data
134
- if not {"Creator", "ActiveFans"}.issubset(account_data.columns):
135
- raise KeyError(f"The account data must contain 'Creator' and 'ActiveFans' columns. Found: {list(account_data.columns)}")
136
-
137
- shift_names = ["Overnight", "Day", "Prime"]
138
-
139
- for idx, chatter_df in enumerate(chatter_files):
140
- shift_name = shift_names[idx]
141
-
142
- # Debugging: Print initial chatter data
143
- print(f"DEBUG: Initial {shift_name} Chatter Data:")
144
- print(chatter_df.head())
145
-
146
- # Clean chatter data
147
- chatter_df = clean_chatter_data(chatter_df)
148
-
149
- # Debugging: Print cleaned chatter data
150
- print(f"DEBUG: Cleaned {shift_name} Chatter Data:")
151
- print(chatter_df.head())
152
-
153
- # Create a blank schedule template
154
- schedule = create_schedule_template(account_data)
155
-
156
- # Debugging: Print initial schedule template
157
- print(f"DEBUG: Initial Schedule Template for {shift_name}:")
158
- print(schedule.head())
159
-
160
- # Assign main accounts to the schedule
161
- schedule = assign_main_accounts_to_schedule(schedule, chatter_df)
162
-
163
- # Debugging: Print schedule after assigning main accounts
164
- print(f"DEBUG: Schedule After Assigning Main Accounts for {shift_name}:")
165
- print(schedule.head())
166
-
167
- # Assign days off based on chatter preferences
168
- schedule = assign_off_days(schedule, chatter_df)
169
-
170
- # Debugging: Print schedule after assigning off days
171
- print(f"DEBUG: Schedule After Assigning Off Days for {shift_name}:")
172
- print(schedule.head())
173
 
174
- # Randomly fill the remaining slots while respecting constraints
175
- schedule = randomly_fill_slots(schedule, chatter_df)
 
 
 
 
 
 
176
 
177
- # Debugging: Print final schedule for the shift
178
- print(f"DEBUG: Final Schedule for {shift_name}:")
179
- print(schedule.head())
 
 
 
 
 
 
 
 
 
 
 
 
180
 
181
- # Save the schedule
182
- schedules[shift_name] = schedule.to_dict(orient="records")
 
 
 
 
183
 
184
- return schedules
185
 
186
 
187
 
 
120
  # Global variable to store updated assignments from the main account generation
121
  UPDATED_ASSIGNMENTS = {}
122
 
123
+ def generate_full_schedule():
124
+ global UPDATED_ASSIGNMENTS
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
 
126
+ # Check if UPDATED_ASSIGNMENTS is populated
127
+ if UPDATED_ASSIGNMENTS:
128
+ # Convert the in-memory assignments to DataFrames
129
+ chatter_files = []
130
+ for shift in ["overnight", "day", "prime"]:
131
+ if shift in UPDATED_ASSIGNMENTS:
132
+ df = pd.DataFrame(UPDATED_ASSIGNMENTS[shift])
133
+ chatter_files.append(df)
134
 
135
+ creators_file = pd.DataFrame({"Creator": UPDATED_ASSIGNMENTS.get("creator_names", [])})
136
+ else:
137
+ # Fall back to reading processed files
138
+ chatter_files = [
139
+ pd.read_excel(os.path.join(PROCESSED_FOLDER, "Updated_overnight_file.xlsx")),
140
+ pd.read_excel(os.path.join(PROCESSED_FOLDER, "Updated_day_file.xlsx")),
141
+ pd.read_excel(os.path.join(PROCESSED_FOLDER, "Updated_prime_file.xlsx")),
142
+ ]
143
+ creators_file = pd.read_excel(os.path.join(PROCESSED_FOLDER, "creators_file.xlsx"))
144
+
145
+ # Debugging: Ensure chatter files and creators file are populated
146
+ print("DEBUG: Chatter Files and Creators File for Schedule Generation")
147
+ for chatter_file in chatter_files:
148
+ print(chatter_file.head())
149
+ print(creators_file.head())
150
 
151
+ try:
152
+ # Generate schedules using in-memory or processed data
153
+ full_schedules = generate_schedule(chatter_files, creators_file)
154
+ return full_schedules
155
+ except Exception as e:
156
+ return f"Error generating full schedule: {e}"
157
 
 
158
 
159
 
160