|
303 | 303 | tops = tops.append(cut2)
|
304 | 304 |
|
305 | 305 | # print(len(tops))
|
306 |
| -try: |
307 |
| - if len(tops) != 0: |
308 |
| - tops = tops.reset_index(drop=True) |
309 |
| - tops['first_session'] = sess['session_start'].min() |
310 |
| - tops['last_session'] = sess['session_start'].max() |
311 |
| - tops['period_begin'] = sess['period_begin'].max() |
312 |
| - tops['period_end'] = sess['period_end'].max() |
313 |
| - tops['overall_begin'] = BEG_DATE |
314 |
| - tops['overall_end'] = END_DATE |
315 |
| -except: |
316 |
| - print('__getitem__ problem has occured. currently working on it \n Results should be pretty normal though \n') |
317 |
| - tops = tops.reset_index(drop=True) |
| 306 | +# try: |
| 307 | +# if len(tops) != 0: |
| 308 | +# tops = tops.reset_index(drop=True) |
| 309 | +# tops['first_session'] = sess['session_start'].min() |
| 310 | +# tops['last_session'] = sess['session_start'].max() |
| 311 | +# tops['period_begin'] = sess['period_begin'].max() |
| 312 | +# tops['period_end'] = sess['period_end'].max() |
| 313 | +# tops['overall_begin'] = BEG_DATE |
| 314 | +# tops['overall_end'] = END_DATE |
| 315 | +# except: |
| 316 | +# print('__getitem__ problem has occured. currently working on it \n Results should be pretty normal though \n') |
| 317 | +# tops = tops.reset_index(drop=True) |
318 | 318 | tops_table = tops_table.append(tops)
|
319 | 319 |
|
320 | 320 | tops_table = tops_table.reset_index(drop=True)
|
|
339 | 339 | else:
|
340 | 340 | f.write('Best performing traffic \n\n')
|
341 | 341 | for sou in tops_table.source.unique():
|
342 |
| - session_slice = sess[sess.source == sou] |
| 342 | + session_slice = sess[sess.source == sou] |
343 | 343 | category_slice = tops_table[(tops_table.source == sou) & (tops_table.is_best == 1)]
|
344 | 344 | norm = norms[norms.source == sou]
|
345 | 345 | f.write('- {0} \n'.format(sou))
|
346 | 346 | f.write('- {0} % sessions with this source \n\n'.format(round(len(session_slice) / lenq * 100), 2))
|
347 |
| - for index, row in category_slice.iterrows(): |
348 |
| - f.write('-- had {0}% traffic coming from {1}, {2} coming from {3}, {4} \n with target_kpi {5} \n'.format(round(row['length'] / len(session_slice) * 100, 2), row.medium, row.campaign, row.ipcountry, row.device_type, row.target_kpi)) |
349 |
| - f.write('--- bounce_rate ({2}) is {0} % diff from norm which is {1} \n'.format(round((row['bounce_rate'] - norm['bounce_rate'].iloc[0]) / norm['bounce_rate'].iloc[0] * 100, 2), round(norm['bounce_rate'].iloc[0], 2), round(row['bounce_rate'], 2))) |
350 |
| - f.write('--- med_duration ({2}) is {0} % diff from norm which is {1} \n'.format(round((row['med_duration'] - norm['med_duration'].iloc[0]) / norm['med_duration'].iloc[0] * 100, 2), round(norm['med_duration'].iloc[0], 2), round(row['med_duration'], 2))) |
351 |
| - f.write('--- conversion_rate ({2}) is {0} % diff from norm which is {1} \n'.format(round((row['conversion_rate'] - norm['conversion_rate'].iloc[0]) / norm['conversion_rate'].iloc[0] * 100, 2), round(norm['conversion_rate'].iloc[0], 2), round(row['conversion_rate'], 2))) |
352 |
| - f.write('\n') |
| 347 | + for kpi_value in kpi: |
| 348 | + category_slice_kpi = category_slice[category_slice.target_kpi == kpi_value] |
| 349 | + f.write('-- top by {0} \n\n'.format(kpi_value)) |
| 350 | + for index, row in category_slice_kpi.iterrows(): |
| 351 | + f.write('-- had {0}% traffic coming from {1}, {2} coming from {3}, {4} \n'.format(round(row['length'] / len(session_slice) * 100, 2), row.medium, row.campaign, row.ipcountry, row.device_type)) |
| 352 | + f.write('--- bounce_rate ({2}) is {0} % diff from norm which is {1} \n'.format(round((row['bounce_rate'] - norm['bounce_rate'].iloc[0]) / norm['bounce_rate'].iloc[0] * 100, 2), round(norm['bounce_rate'].iloc[0], 2), round(row['bounce_rate'], 2))) |
| 353 | + f.write('--- med_duration ({2}) is {0} % diff from norm which is {1} \n'.format(round((row['med_duration'] - norm['med_duration'].iloc[0]) / norm['med_duration'].iloc[0] * 100, 2), round(norm['med_duration'].iloc[0], 2), round(row['med_duration'], 2))) |
| 354 | + f.write('--- conversion_rate ({2}) is {0} % diff from norm which is {1} \n'.format(round((row['conversion_rate'] - norm['conversion_rate'].iloc[0]) / norm['conversion_rate'].iloc[0] * 100, 2), round(norm['conversion_rate'].iloc[0], 2), round(row['conversion_rate'], 2))) |
| 355 | + f.write('\n') |
353 | 356 |
|
354 | 357 | f.write('Worst performing traffic \n\n')
|
355 | 358 | for sou in tops_table.source.unique():
|
|
358 | 361 | norm = norms[norms.source == sou]
|
359 | 362 | f.write('- {0} \n'.format(sou))
|
360 | 363 | f.write('- {0} % sessions with this source \n\n'.format(round(len(session_slice) / lenq * 100), 2))
|
361 |
| - for index, row in category_slice.iterrows(): |
362 |
| - f.write('-- had {0}% traffic coming from {1}, {2} coming from {3}, {4} \n with target_kpi {5} \n'.format(round(row['length'] / len(session_slice) * 100, 2), row.medium, row.campaign, row.ipcountry, row.device_type, row.target_kpi)) |
363 |
| - f.write('--- bounce_rate ({2}) is {0} % diff from norm which is {1} \n'.format(round((row['bounce_rate'] - norm['bounce_rate'].iloc[0]) / norm['bounce_rate'].iloc[0] * 100, 2), round(norm['bounce_rate'].iloc[0], 2), round(row['bounce_rate'], 2))) |
364 |
| - f.write('--- med_duration ({2}) is {0} % diff from norm which is {1} \n'.format(round((row['med_duration'] - norm['med_duration'].iloc[0]) / norm['med_duration'].iloc[0] * 100, 2), round(norm['med_duration'].iloc[0], 2), round(row['med_duration'], 2))) |
365 |
| - f.write('--- conversion_rate ({2}) is {0} % diff from norm which is {1} \n'.format(round((row['conversion_rate'] - norm['conversion_rate'].iloc[0]) / norm['conversion_rate'].iloc[0] * 100, 2), round(norm['conversion_rate'].iloc[0], 2), round(row['conversion_rate'], 2))) |
366 |
| - f.write('\n') |
| 364 | + for kpi_value in kpi: |
| 365 | + category_slice_kpi = category_slice[category_slice.target_kpi == kpi_value] |
| 366 | + f.write('-- top by {0} \n\n'.format(kpi_value)) |
| 367 | + for index, row in category_slice_kpi.iterrows(): |
| 368 | + f.write('-- had {0}% traffic coming from {1}, {2} coming from {3}, {4} \n'.format(round(row['length'] / len(session_slice) * 100, 2), row.medium, row.campaign, row.ipcountry, row.device_type, row.target_kpi)) |
| 369 | + f.write('--- bounce_rate ({2}) is {0} % diff from norm which is {1} \n'.format(round((row['bounce_rate'] - norm['bounce_rate'].iloc[0]) / norm['bounce_rate'].iloc[0] * 100, 2), round(norm['bounce_rate'].iloc[0], 2), round(row['bounce_rate'], 2))) |
| 370 | + f.write('--- med_duration ({2}) is {0} % diff from norm which is {1} \n'.format(round((row['med_duration'] - norm['med_duration'].iloc[0]) / norm['med_duration'].iloc[0] * 100, 2), round(norm['med_duration'].iloc[0], 2), round(row['med_duration'], 2))) |
| 371 | + f.write('--- conversion_rate ({2}) is {0} % diff from norm which is {1} \n'.format(round((row['conversion_rate'] - norm['conversion_rate'].iloc[0]) / norm['conversion_rate'].iloc[0] * 100, 2), round(norm['conversion_rate'].iloc[0], 2), round(row['conversion_rate'], 2))) |
| 372 | + f.write('\n') |
367 | 373 |
|
368 | 374 |
|
369 | 375 |
|
|
0 commit comments