tra-analysis/data analysis/scoutflex2019.py
2019-03-21 22:52:08 -05:00

61 lines
2.2 KiB
Python

# -*- coding: utf-8 -*-
"""
Created on Wed Mar 20 12:21:31 2019
@author: creek
"""
from google.cloud import firestore
from google.oauth2 import service_account
import pprint
from pylatex import Document, Section, Subsection, Command
from pylatex.utils import italic, NoEscape
import requests
def generate_team_report(team):
doc = Document('basic')
matches = team.reference.collection(u'matches').get()
matchnums = []
for match in matches:
matchnums.append(match.id)
with doc.create(Section('Qualification matches scouted')):
for matchnum in matchnums:
doc.append(str(matchnum))
with doc.create(Section('Details')):
hab = "Hab 1"
balls = 42
hatches = 0
count = 0
for match in matches:
for analysis in match:
if analysis.key().startswith('Quant'):
balls = balls + analysis['cargoBalls']
hatches = hatches + analysis['hatchPanels']
count = count + 1
if analysis.key().startswith('Qual'):
strategy = analysis['StrategyType']
strongObject = analysis['TeleopStrongObject']
if count > 0:
doc.append("Average balls: " + str(float(balls)/count))
doc.append("Average hatches: " + str(float(hatches)/count))
doc.append("Strategy Type: " + str(strategy))
doc.append("Strongest object in teleop: " + str(strongObject))
doc.preamble.append(Command('title', team.id))
doc.preamble.append(Command('author', 'Generated by Team 2022'))
doc.preamble.append(Command('date', NoEscape(r'\today')))
doc.append(NoEscape(r'\maketitle'))
doc.generate_pdf(filepath="C://Users//creek//Documents//" + str(team.id), clean_tex=False)
credentials = service_account.Credentials.from_service_account_file('keys/firebasekey.json')
db = firestore.Client(project="titanscoutandroid", credentials=credentials)
teams_ref = db.collection(u'data').document(u'team-2022').collection(u'Central 2019')
teams = teams_ref.get()
for team in teams:
generate_team_report(team)