-
Notifications
You must be signed in to change notification settings - Fork 0
/
test4.py
46 lines (38 loc) · 1.42 KB
/
test4.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
import json
from backend.datasource import DataSource
dataSource = DataSource('./sample.json')
data = dataSource.get_data()['aggregations']['audits_over_time']['buckets']
# print(data)
chartList = []
#names = []
for record in data:
for v in record:
buckets = []
# print(record)
# print('\n')
dateOfEachBucket = record['key_as_string']
# print(dateOfEachBucket)
if isinstance(record[v], dict):
b = {}
b.update({'DATE': dateOfEachBucket, 'buckets': record[v]['buckets']})
buckets.append(b)
for bucket in buckets:
dateOfBucket = bucket['DATE']
# print('\n')
containers = []
for value in bucket['buckets']:
if value['key'] == 'DE_ADDRESS':
# print(value)
# print(value['by_user']['sum_other_doc_count'])
# print('\n')
containers.append(value['by_user']['buckets'])
chartDict = {}
for k in containers:
i=1
for l in k:
# names.append(l['key'])
chartDict.update({'DATE': dateOfBucket, "label" + str(i): str(l['doc_count']),
'OTHERS': str(value['by_user']['sum_other_doc_count'])})
i = i+1
chartList.append(chartDict)
print(json.dumps(chartList))