-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent_activity_analyzer.py
49 lines (35 loc) · 1.25 KB
/
event_activity_analyzer.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
import json
import datetime
import os
from os import listdir
from os.path import isfile, join, isdir
folder_path = 'data'
filenames = [f for f in listdir(folder_path) if isfile(os.path.join(folder_path, f))]
# Placeholder for json objects
json_obj_array = []
for filename in filenames:
filepath = os.path.join(folder_path, filename)
# Read the json combined document line by line
with open(filepath) as fp:
line = fp.readline()
cnt = 1
while line:
loaded_json = json.loads(line.strip())
json_obj_array.append(loaded_json)
line = fp.readline()
cnt += 1
app_removed_users = []
for count, json_obj in enumerate(json_obj_array):
# device_id = json_obj['user_dim']['device_info']['resettable_device_id']
events = json_obj['event_dim']
for event in events:
event['utc_time'] = datetime.datetime.fromtimestamp(int(event['timestamp_micros'][:10])).strftime('%Y-%m-%d %H:%M:%S')
if event['name'] == 'app_remove':
app_removed_users.append(json_obj)
break
"""
Now you can find all the users and their activities (who have deleted their app : app-remove) from;
app_removed_users
"""
# TODO
print('completed.')