-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataFormatters.py
66 lines (53 loc) · 1.95 KB
/
dataFormatters.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
56
57
58
59
60
61
62
63
64
65
66
from statistics import mean
def graph(data):
#print(package)
#all data = {labelset: []}
datasets = []
graphFormat = {}
for results in data['results']:
event = results['event']
#print(event)
if event not in graphFormat:
graphFormat.update({event : [results]})
else:
graphFormat[event].append(results)
labels = []
dataList = {'labels':'', 'datasets':''}
for event, data in graphFormat.items():
chartSet = {'label':'', 'data':[]}
chartSet['label'] = event
for eventData in data:
individualData = {'x':'', 'y':''}
individualData['x'] = eventData['date']
individualData['y'] = eventData['percentile']
chartSet['data'].append(individualData)
'''
labelObject = {'meet':eventData['meet'], 'event':eventData['event'], 'result':eventData['result'], 'season':eventData['season']}
labels.
'''
datasets.append(chartSet)
dataList['labels'] = labels
dataList['datasets'] = datasets
return dataList
def cards(data):
#print(package)
cardFormat = {}
cardData = {'results':{}, 'averagePercent':''}
for results in data['results']:
event = results['event']
#print(event)
if event not in cardFormat:
cardFormat.update({event : {'results':[results], 'averagePercent':'hee'}})
#print('new')
else:
cardFormat[event]['results'].append(results)
#print('added')
for events in cardFormat:
#print(cardFormat[events])
resultpercentileList = []
for results in cardFormat[events]["results"]:
#print(results)
resultpercentileList.append(float(results['percentile'].replace('%', '')))
percentile = mean(resultpercentileList)
cardFormat[events]['averagePercent'] = str(percentile).split(".")[0] + "%"
return(cardFormat)