tra-analysis/data analysis/test.py

98 lines
2.3 KiB
Python
Raw Normal View History

2019-03-21 01:18:55 +00:00
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
import csv
import numpy as np
# Use a service account
cred = credentials.Certificate('keys/keytemp.json')
#add your own key as this is public. email me for details
firebase_admin.initialize_app(cred)
db = firestore.client()
teams=db.collection('data').document('team-2022').collection("Central 2019").get()
full=[]
tms=[]
for team in teams:
2019-03-21 20:14:24 +00:00
2019-03-21 01:18:55 +00:00
tms.append(team.id)
reports=db.collection('data').document('team-2022').collection("Central 2019").document(team.id).collection("matches").get()
2019-03-21 20:14:24 +00:00
2019-03-21 01:18:55 +00:00
for report in reports:
2019-03-21 20:14:24 +00:00
data=[]
2019-03-21 01:18:55 +00:00
data.append(db.collection('data').document('team-2022').collection("Central 2019").document(team.id).collection("matches").document(report.id).get().to_dict())
2019-03-21 20:14:24 +00:00
full.append(data)
2019-03-21 01:18:55 +00:00
quant_keys = []
list_teams = ["2022", "16", "2451"]
out = []
2019-03-21 19:38:53 +00:00
var = {}
2019-03-21 01:18:55 +00:00
for i in range(len(full)):
for j in range(len(full[i])):
for key in list(full[i][j].keys()):
2019-03-21 02:36:49 +00:00
2019-03-21 01:18:55 +00:00
if "Quantitative" in key:
2019-03-21 19:38:53 +00:00
2019-03-21 01:18:55 +00:00
quant_keys.append(key)
2019-03-21 19:38:53 +00:00
2019-03-21 01:18:55 +00:00
if full[i][j].get(key).get('teamDBRef')[5:] in list_teams:
2019-03-21 19:38:53 +00:00
var = {}
2019-03-21 03:15:31 +00:00
measured_vars = []
2019-03-21 19:38:53 +00:00
2019-03-21 02:36:49 +00:00
for k in range(len(list(full[i][j].get(key).keys()))):
individual_keys = list(full[i][j].get(key).keys())
2019-03-21 20:06:54 +00:00
2019-03-21 19:38:53 +00:00
var[individual_keys[k]] = full[i][j].get(key).get(individual_keys[k])
2019-03-21 03:15:31 +00:00
2019-03-21 20:25:36 +00:00
out.append(var)
2019-03-21 20:06:54 +00:00
2019-03-21 19:38:53 +00:00
sorted_out = []
for i in out:
j_list = []
key_list = []
sorted_keys = sorted(i.keys())
for j in sorted_keys:
key_list.append(i[j])
j_list.append(j)
sorted_out.append(key_list)
var_index = 0
team_index = 0
big_out = []
2019-03-21 20:06:54 +00:00
for j in range(len(i)):
big_out.append([])
for t in range(len(list_teams)):
big_out[j].append([])
2019-03-21 19:38:53 +00:00
for i in sorted_out:
team_index = list_teams.index(sorted_out[sorted_out.index(i)][j_list.index('teamDBRef')][5:])
for j in range(len(i)):
big_out[j][team_index].append(i[j])
2019-03-21 03:15:31 +00:00
2019-03-21 20:25:36 +00:00
for i in range(len(big_out)):
with open('data/' + j_list[i] + '.csv', "w+", newline = '') as file:
writer = csv.writer(file, delimiter = ',')
writer.writerows(big_out[i])
2019-03-21 02:36:49 +00:00