Gabriel Sabau commited on
Commit
d271c73
·
1 Parent(s): 504cdb5

feat: updated ECPM formula

Browse files
Files changed (2) hide show
  1. requirements.txt +2 -1
  2. utils/gradio_utils.py +13 -6
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  seaborn
2
- python-dotenv
 
 
1
  seaborn
2
+ python-dotenv
3
+ pandas
utils/gradio_utils.py CHANGED
@@ -256,9 +256,8 @@ def compute_offer(csv_file, days_lookback, min_sent, domain, offer_type, x_list)
256
 
257
  cols = ['Campanie', 'Oferta', 'Nume', 'Server', 'User',
258
  'Lista Custom', 'Data', 'HClicks', 'Clicks', 'Unscribers', 'Openers',
259
- 'Click Open', 'Leads', 'CLike', 'Complains', 'Traps', 'Send', 'ECPM']
260
- # df_all = raw_df[raw_df['Nume'].str.contains('|'.join(cmp_list))] #1
261
- # df_all = df_all[df_all['Domeniu'] == 'Comcast'] #2
262
  exclude_list = df_all[(df_all['Data'] > (pd.Timestamp('now') - pd.Timedelta(days=days_lookback))) \
263
  & (df_all['Domeniu'] == domain)]['Oferta'].unique()
264
  df_all = df_all[~df_all['Oferta'].isin(exclude_list)]
@@ -270,7 +269,8 @@ def compute_offer(csv_file, days_lookback, min_sent, domain, offer_type, x_list)
270
 
271
  df_all['Click Open'] = df_all['Click Open'].str.replace('%', '').astype(float)
272
  df_all['ECPM'] = df_all['ECPM'].astype(float)
273
-
 
274
 
275
  # Limit the characters in the "Nume" column
276
  # df_all["Nume"] = df_all["Nume"].apply(_limit_chars)
@@ -318,11 +318,18 @@ def compute_offer(csv_file, days_lookback, min_sent, domain, offer_type, x_list)
318
  final_df.reset_index(inplace=True)
319
  elif offer_type == "Offers - IDs only":
320
  df_all['offer_id'] = df_all['Nume'].str.extract(r'(\d{3,4}$)')
 
321
  final_df = df_all.groupby(["offer_id"])\
322
- .agg( times_sent=('offer_id', 'count'), send_avg=('Send', 'mean'), ECPM=('ECPM', 'mean'))\
323
- .sort_values(['ECPM', 'times_sent'], ascending=False)
 
 
324
  final_df['send_avg'] = final_df['send_avg'].astype(int)
 
325
  final_df['ECPM'] = final_df['ECPM'].round(2).astype(float)
 
 
 
326
  final_df.reset_index(inplace=True)
327
  else:
328
  final_df = pd.DataFrame()
 
256
 
257
  cols = ['Campanie', 'Oferta', 'Nume', 'Server', 'User',
258
  'Lista Custom', 'Data', 'HClicks', 'Clicks', 'Unscribers', 'Openers',
259
+ 'Click Open', 'Leads', 'CLike', 'Complains', 'Traps', 'Send', 'ECPM', 'Comision', 'Domeniu']
260
+
 
261
  exclude_list = df_all[(df_all['Data'] > (pd.Timestamp('now') - pd.Timedelta(days=days_lookback))) \
262
  & (df_all['Domeniu'] == domain)]['Oferta'].unique()
263
  df_all = df_all[~df_all['Oferta'].isin(exclude_list)]
 
269
 
270
  df_all['Click Open'] = df_all['Click Open'].str.replace('%', '').astype(float)
271
  df_all['ECPM'] = df_all['ECPM'].astype(float)
272
+ df_all['Comision'] = df_all['Comision'].astype(float)
273
+ df_all['Send'] = df_all['Send'].astype(int)
274
 
275
  # Limit the characters in the "Nume" column
276
  # df_all["Nume"] = df_all["Nume"].apply(_limit_chars)
 
318
  final_df.reset_index(inplace=True)
319
  elif offer_type == "Offers - IDs only":
320
  df_all['offer_id'] = df_all['Nume'].str.extract(r'(\d{3,4}$)')
321
+
322
  final_df = df_all.groupby(["offer_id"])\
323
+ .agg( times_sent=('offer_id', 'count'), send_avg=('Send', 'mean'), total_sent=('Send', 'sum'),\
324
+ USD=('Comision', 'sum'))
325
+
326
+ final_df['USD'] = final_df['USD'].round(2).astype(float)
327
  final_df['send_avg'] = final_df['send_avg'].astype(int)
328
+ final_df['ECPM'] = ( ( final_df['USD'] * 33.33 ) / final_df['total_sent'] ) * 1000
329
  final_df['ECPM'] = final_df['ECPM'].round(2).astype(float)
330
+
331
+ final_df.sort_values(by='ECPM', ascending=False, inplace=True)
332
+
333
  final_df.reset_index(inplace=True)
334
  else:
335
  final_df = pd.DataFrame()