-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetricsHandler.py
55 lines (44 loc) · 2.12 KB
/
metricsHandler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import datetime
result = {}
def process_metrics_data(data, start="", to =""):
result["SessionInstancesLaunched"] = find_sum(data,"SessionInstancesLaunched", start = start, to =to )
result["Attendees"] = find_sum(data,"Attendees", start = start, to =to )
result["AttendeesUnique"] = find_sum(data,"AttendeesUnique", start = start, to =to )
result["Recordings"] = find_sum(data,"Recordings", start = start, to =to )
result["SessionInstancesPeak"] = find_max(data,"SessionInstancesPeak", start = start, to =to )
result["AttendeesPeak"] = find_max(data, "AttendeesPeak", start = start, to =to )
result["SessionTime"] = find_time_sum(data,"SessionTime", start = start, to =to )
result["RecordingsDuration"] = find_time_sum(data,"RecordingsDuration", start = start, to =to )
def find_sum(data, key, start, to ):
sum = 0
for item in data:
item_date = datetime.datetime.strptime(item[next(iter(item))], '%m/%d/%Y')
if (item_date >= start):
if (item_date <= to ):
sum += int(item[key])
return(f'{sum:,}')
def find_time_sum(data, key, start , to ):
list_time = []
for item in data:
item_date = datetime.datetime.strptime(item[next(iter(item))], '%m/%d/%Y')
if (item_date >= start):
if (item_date <= to):
list_time.append(item[key])
duration = datetime.timedelta()
for i in list_time:
(h, m, s) = i.split(':')
d = datetime.timedelta(hours=int(h), minutes=int(m), seconds=int(s))
duration += d
totsec = duration.total_seconds()
h = int(totsec//3600)
m = int((totsec % 3600) // 60)
sec = int((totsec % 3600) % 60)
return("{0}:{1}:{2}".format((h), m, sec))
def find_max(data, key, start, to):
values = []
for item in data:
item_date = datetime.datetime.strptime(item[next(iter(item))], '%m/%d/%Y')
if (item_date >= start ):
if (item_date <= to ):
values.append(int(item[key]))
return(f'{max(values):,}')