-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.py
19 lines (18 loc) · 1001 Bytes
/
tools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
def aggregate_time(period,log):
aggregatedTime = {}
for event in log:
aggregateTimeEvent = event["created_at"].replace(second=0,microsecond=0)
if period=="year" :
aggregateTimeEvent = event["created_at"].replace(month=0, day=0, hour = 0, minute=0,second=0,microsecond=0)
elif period=="month":
aggregateTimeEvent = event["created_at"].replace(day=0, hour = 0, minute=0,second=0,microsecond=0)
elif period=="day":
aggregateTimeEvent = event["created_at"].replace(hour = 0, minute=0,second=0,microsecond=0)
elif period=="hour":
aggregateTimeEvent = event["created_at"].replace(minute=0,second=0,microsecond=0)
stringAggregateTimeEvent = aggregateTimeEvent.strftime("%Y-%m-%d %H:%M:%S")
if stringAggregateTimeEvent in aggregatedTime:
aggregatedTime[stringAggregateTimeEvent] += 1
else:
aggregatedTime[stringAggregateTimeEvent] = 1
return aggregatedTime