tra-analysis/data analysis/matches/Untitled.ipynb
2019-03-08 21:55:52 -06:00

152 lines
4.5 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'reload' is not defined",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-1-b21f5957e8b4>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mcsv\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0msys\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 6\u001b[1;33m \u001b[0mreload\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msys\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 7\u001b[0m \u001b[0msys\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msetdefaultencoding\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'utf-8'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 8\u001b[0m \u001b[1;31m# Use a service account\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mNameError\u001b[0m: name 'reload' is not defined"
]
}
],
"source": [
"import firebase_admin\n",
"from firebase_admin import credentials\n",
"from firebase_admin import firestore\n",
"import csv\n",
"# Use a service account\n",
"cred = credentials.Certificate(r'../keys/fsk.json')\n",
"firebase_admin.initialize_app(cred)\n",
"\n",
"db = firestore.client()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"teams=db.collection('data').document('team-2022').collection(\"Midwest 2019\").get()\n",
"full=[]\n",
"tms=[]\n",
"for team in teams:\n",
" data=[]\n",
" tms.append(team.id)\n",
" reports=db.collection('data').document('team-2022').collection(\"Midwest 2019\").document(team.id).collection(\"matches\").get()\n",
" for report in reports:\n",
" data.append(db.collection('data').document('team-2022').collection(\"Midwest 2019\").document(team.id).collection(\"matches\").document(report.id).get().to_dict())\n",
" full.append(data)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"full[0]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def expcsv(loc,data):\n",
" with open(loc+'.csv', 'w', newline='') as csvfile:\n",
" w = csv.writer(csvfile, delimiter=',', quotechar=\"\\\"\", quoting=csv.QUOTE_MINIMAL)\n",
" for i in data:\n",
" w.writerow(i)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def keymatch(ld):\n",
" keys=set([])\n",
" for i in ld:\n",
" for j in i.keys():\n",
" keys.add(j)\n",
" kl=list(keys)\n",
" data=[]\n",
" for i in kl:\n",
" data.append([i])\n",
" for i in kl:\n",
" for j in ld:\n",
" try:\n",
" (data[kl.index(i)]).append(j[i])\n",
" except:\n",
" (data[kl.index(i)]).append(\"\")\n",
" return data\n",
"wn=[]\n",
"for i in full:\n",
" wn.append(keymatch(i))\n",
"for i in range(len(wn)):\n",
" expcsv(tms[i],wn[i])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"keys=set([])\n",
"keys.add('a')\n",
"keys.add('b')\n",
"keys.add('c')\n",
"keys.add('d')\n",
"list(keys)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}