Fred808 commited on
Commit
c9ec26e
·
verified ·
1 Parent(s): 59de6a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -1
app.py CHANGED
@@ -59,6 +59,8 @@ except FileNotFoundError:
59
  logging.error("engagement_metrics.json not found. Please ensure the file exists.")
60
  exit()
61
 
 
 
62
  # Load solved.json (your company's hashtags and captions)
63
  logging.info("Loading your company's solved data...")
64
  try:
@@ -308,7 +310,39 @@ if __name__ == "__main__":
308
  except Exception as e:
309
  logging.error(f"Error processing image: {e}")
310
 
311
- # Time-Series Model: Optimal Posting Times (using Prophet)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
312
  logging.info("Training time-series model for optimal posting times using Prophet...")
313
  time_series_data = engagement_summary[['posting_time', 'engagement_rate']].rename(columns={'posting_time': 'ds', 'engagement_rate': 'y'})
314
 
 
59
  logging.error("engagement_metrics.json not found. Please ensure the file exists.")
60
  exit()
61
 
62
+
63
+
64
  # Load solved.json (your company's hashtags and captions)
65
  logging.info("Loading your company's solved data...")
66
  try:
 
310
  except Exception as e:
311
  logging.error(f"Error processing image: {e}")
312
 
313
+ # Analyze engagement data separately
314
+ logging.info("Analyzing engagement data separately...")
315
+ engagement_summary = your_df.groupby('posting_time').agg({
316
+ 'likes': 'sum',
317
+ 'comments': 'sum',
318
+ 'shares': 'sum',
319
+ 'engagement_rate': 'mean'
320
+ }).reset_index()
321
+
322
+ # Convert posting_time to datetime in engagement data
323
+ logging.info("Converting posting_time to datetime...")
324
+ your_df['posting_time'] = pd.to_datetime(your_df['posting_time'], format='%Y-%m-%d %H:%M:%S', errors='coerce')
325
+
326
+ # Plot engagement rate over time
327
+ plt.figure(figsize=(10, 6))
328
+ plt.plot(engagement_summary['posting_time'], engagement_summary['engagement_rate'])
329
+ plt.title('Engagement Rate Over Time')
330
+ plt.xlabel('Time')
331
+ plt.ylabel('Engagement Rate')
332
+ plt.show()
333
+
334
+ # Handle missing values in engagement data
335
+ your_df.fillna({
336
+ 'likes': 0,
337
+ 'comments': 0,
338
+ 'shares': 0
339
+ }, inplace=True)
340
+
341
+ # Calculate engagement_rate
342
+ your_df['engagement_rate'] = your_df['likes'] + your_df['comments'] + your_df['shares']
343
+
344
+
345
+ # Time-Series Model: Optimal Posting Times (using Prophet)
346
  logging.info("Training time-series model for optimal posting times using Prophet...")
347
  time_series_data = engagement_summary[['posting_time', 'engagement_rate']].rename(columns={'posting_time': 'ds', 'engagement_rate': 'y'})
348