Skip to content

Commit 14ec180

Browse files
author
Ubuntu
committed
fix basic doc format
1 parent 1164ff8 commit 14ec180

File tree

1 file changed

+31
-25
lines changed

1 file changed

+31
-25
lines changed

eshop_anomaly_kpi_basic.py

+31-25
Original file line numberDiff line numberDiff line change
@@ -303,18 +303,18 @@
303303
tops = tops.append(cut2)
304304

305305
# 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)
318318
tops_table = tops_table.append(tops)
319319

320320
tops_table = tops_table.reset_index(drop=True)
@@ -339,17 +339,20 @@
339339
else:
340340
f.write('Best performing traffic \n\n')
341341
for sou in tops_table.source.unique():
342-
session_slice = sess[sess.source == sou]
342+
session_slice = sess[sess.source == sou]
343343
category_slice = tops_table[(tops_table.source == sou) & (tops_table.is_best == 1)]
344344
norm = norms[norms.source == sou]
345345
f.write('- {0} \n'.format(sou))
346346
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')
353356

354357
f.write('Worst performing traffic \n\n')
355358
for sou in tops_table.source.unique():
@@ -358,12 +361,15 @@
358361
norm = norms[norms.source == sou]
359362
f.write('- {0} \n'.format(sou))
360363
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')
367373

368374

369375

0 commit comments

Comments
 (0)