Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -54,68 +54,39 @@ def generate_main_accounts(updated_data=None):
|
|
| 54 |
return "Missing required files. Please upload all necessary files.", None
|
| 55 |
|
| 56 |
try:
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
{key: record[key] for key in record if key != "Shift"} # Remove the Shift column
|
| 66 |
-
for record in updated_data if record["Shift"] == shift.capitalize()
|
| 67 |
-
]
|
| 68 |
-
for shift in ["overnight", "day", "prime"]
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
UPDATED_ASSIGNMENTS["creator_names"] = list(
|
| 72 |
-
set(record["Main Account"] for record in updated_data if "Main Account" in record)
|
| 73 |
-
)
|
| 74 |
-
|
| 75 |
-
save_processed_files(UPDATED_ASSIGNMENTS, PROCESSED_FOLDER)
|
| 76 |
-
return "Assignments updated successfully!", pd.DataFrame(updated_data)
|
| 77 |
-
|
| 78 |
-
# Debugging: Verify creators file before processing
|
| 79 |
-
print("DEBUG: Original Creators File Columns")
|
| 80 |
-
creators_df = pd.read_excel(creators_file)
|
| 81 |
-
print(creators_df.columns)
|
| 82 |
-
|
| 83 |
-
# Ensure creators file has correct columns
|
| 84 |
-
column_mapping = {
|
| 85 |
-
"Creator": "Creator",
|
| 86 |
-
"Total earnings": "Total earnings",
|
| 87 |
-
"Subscription": "Subscription",
|
| 88 |
-
"Active Fans": "ActiveFans",
|
| 89 |
-
"Total active fans": "ActiveFans",
|
| 90 |
}
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
required_columns = ["Creator", "ActiveFans"]
|
| 98 |
-
missing_columns = [col for col in required_columns if col not in creators_df.columns]
|
| 99 |
-
if missing_columns:
|
| 100 |
-
raise KeyError(f"Missing required columns in creators file: {missing_columns}")
|
| 101 |
|
| 102 |
-
# Save
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
save_processed_files(main_assignments, PROCESSED_FOLDER)
|
| 107 |
|
| 108 |
-
#
|
| 109 |
preview_data = []
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
preview_data.append(record)
|
| 115 |
|
| 116 |
-
preview_df = pd.
|
| 117 |
return "Main accounts generated successfully!", preview_df
|
|
|
|
| 118 |
except Exception as e:
|
|
|
|
| 119 |
return f"Error during main account generation: {e}", None
|
| 120 |
|
| 121 |
|
|
@@ -124,6 +95,7 @@ def generate_main_accounts(updated_data=None):
|
|
| 124 |
|
| 125 |
|
| 126 |
|
|
|
|
| 127 |
# Global variable to store updated assignments from the main account generation
|
| 128 |
UPDATED_ASSIGNMENTS = {}
|
| 129 |
|
|
|
|
| 54 |
return "Missing required files. Please upload all necessary files.", None
|
| 55 |
|
| 56 |
try:
|
| 57 |
+
# Step 1: Assign main accounts
|
| 58 |
+
updated_chatter_files, account_data = assign_main_accounts(creators_file, chatter_files)
|
| 59 |
+
print("DEBUG: Updated Chatter Files and Account Data Successfully Generated")
|
| 60 |
+
|
| 61 |
+
# Save processed files
|
| 62 |
+
UPDATED_ASSIGNMENTS = {
|
| 63 |
+
"chatter_files": updated_chatter_files,
|
| 64 |
+
"account_data": account_data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
}
|
| 66 |
+
for idx, chatter_df in enumerate(updated_chatter_files):
|
| 67 |
+
chatter_df.to_excel(
|
| 68 |
+
os.path.join(PROCESSED_FOLDER, f"Updated_{['overnight', 'day', 'prime'][idx]}_file.xlsx"),
|
| 69 |
+
index=False
|
| 70 |
+
)
|
| 71 |
+
account_data.to_excel(os.path.join(PROCESSED_FOLDER, "creators_file.xlsx"), index=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
+
# Save Creator and ActiveFans to a separate file
|
| 74 |
+
creator_output_file = os.path.join(PROCESSED_FOLDER, "Creators_ActiveFans.xlsx")
|
| 75 |
+
account_data.to_excel(creator_output_file, index=False)
|
| 76 |
+
print(f"DEBUG: Saved Creator-ActiveFans data to {creator_output_file}")
|
|
|
|
| 77 |
|
| 78 |
+
# Step 2: Combine for preview
|
| 79 |
preview_data = []
|
| 80 |
+
shift_names = ["Overnight", "Day", "Prime"]
|
| 81 |
+
for idx, chatter_df in enumerate(updated_chatter_files):
|
| 82 |
+
chatter_df["Shift"] = shift_names[idx]
|
| 83 |
+
preview_data.append(chatter_df)
|
|
|
|
| 84 |
|
| 85 |
+
preview_df = pd.concat(preview_data, ignore_index=True)
|
| 86 |
return "Main accounts generated successfully!", preview_df
|
| 87 |
+
|
| 88 |
except Exception as e:
|
| 89 |
+
print(f"Error during main account generation: {e}")
|
| 90 |
return f"Error during main account generation: {e}", None
|
| 91 |
|
| 92 |
|
|
|
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
+
|
| 99 |
# Global variable to store updated assignments from the main account generation
|
| 100 |
UPDATED_ASSIGNMENTS = {}
|
| 101 |
|