forked from frcteam195/scouting_python_2022
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateMatches.py
More file actions
129 lines (113 loc) · 4.8 KB
/
Copy pathcreateMatches.py
File metadata and controls
129 lines (113 loc) · 4.8 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import mariadb as mariaDB
import sys
import argparse
database = ''
csvFilename = ''
parser = argparse.ArgumentParser()
parser.add_argument("-db", "--database", help = "Choices: aws-prod, aws-dev, pi-192, pi-10, localhost", required=True)
args = parser.parse_args()
input_database = args.database
if input_database == "aws-prod":
database = "aws-prod"
elif input_database == "aws-dev":
database = "aws-dev"
elif input_database == "pi-192":
database = "pi-192"
elif input_database == "pi-10":
database = "pi-10"
elif input_database == "localhost":
database = "localhost"
else:
print(input_database + " is not a invalid database choice. See --help for choices")
sys.exit()
print ("Connecting to " + database)
if database == "aws-dev":
print("Input database " + input_database)
conn = mariaDB.connect(user='admin',
passwd='Einstein195',
host='frcteam195testinstance.cmdlvflptajw.us-east-1.rds.amazonaws.com',
database='team195_scouting')
cursor = conn.cursor()
elif database == "pi-10":
conn = mariaDB.connect(user='admin',
passwd='team195',
host='10.0.20.195',
database='team195_scouting')
cursor = conn.cursor()
elif database == "pi-192":
conn = mariaDB.connect(user='admin',
passwd='team195',
host='192.168.1.195',
database='team195_scouting')
cursor = conn.cursor()
elif database == "localhost":
conn = mariaDB.connect(user='admin',
passwd='team195',
host='localhost',
database='team195_scouting')
cursor = conn.cursor()
elif database == "aws-prod":
conn = mariaDB.connect(user='admin',
passwd='Einstein195',
host='frcteam195.cmdlvflptajw.us-east-1.rds.amazonaws.com',
database='team195_scouting')
cursor = conn.cursor()
else:
print ("oops - Harish would not approve of that!")
sys.exit()
# def wipeBAS():
# cursor.execute("DELETE FROM BlueAllianceSchedule;")
# cursor.execute("ALTER TABLE BlueAllianceSchedule AUTO_INCREMENT = 1;")
# conn.commit()
# wipeBAS()
query = "SELECT Events.EventID, Events.BAEventID FROM Events WHERE Events.CurrentEvent = 1; "
cursor.execute(query)
eventData = cursor.fetchall()
# print(eventData)
eventID = eventData[0][0]
BAEventID = eventData[0][1]
# eventID = [item[0] for item in eventData]
# BAEventID = [item[1] for item in eventData]
# print(eventID)
# print(BAEventID)
query = "SELECT BlueAllianceSchedule.* FROM BlueAllianceSchedule;"
# print(query)
cursor.execute(query)
rsBAMatches = cursor.fetchall()
# print(rsBAMatches[0][7])
if rsBAMatches[0][7] != BAEventID:
print("BAEventIDs do not match between BA-Schedule table and Events table")
quit()
# Find matches from the Matches table and add new records to the MatchScouting table if they do not already exist
for row in rsBAMatches:
rsMatchRecord = {'EventID': eventID, 'MatchNo': row[0],
'RedTeam1': row[1], 'RedTeam2': row[2], 'RedTeam3': row[3],
'BlueTeam1': row[4], 'BlueTeam2': row[5], 'BlueTeam3': row[6]}
# print(rsMatchRecord)
query = "SELECT COUNT(*) FROM Matches WHERE Matches.MatchNo = " \
+ str(row[0]) + " AND Matches.EventID = " + str(eventID) + ";"
# print(query)
cursor.execute(query)
count = cursor.fetchall()
# print(count[0][0])
if count[0][0] == 0:
items = rsMatchRecord.items()
columns = str(tuple([x[0] for x in items])).replace("'", "")
values = str(tuple([x[1] for x in items]))
cursor.execute("INSERT INTO Matches "
+ columns + " VALUES "
+ values + ";")
conn.commit()
#
#
# # Fix Team #s for the six alliance stations. This is good in case a team number changed or was entered incorrectly
updateQuery = "UPDATE Matches INNER JOIN BlueAllianceSchedule ON (Matches.MatchNo = BlueAllianceSchedule.MatchNo) " \
"SET Matches.RedTeam1 = BlueAllianceSchedule.RedTeam1, " \
"Matches.RedTeam2 = BlueAllianceSchedule.RedTeam2, " \
"Matches.RedTeam3 = BlueAllianceSchedule.RedTeam3, " \
"Matches.RedTeam1 = BlueAllianceSchedule.RedTeam1, " \
"Matches.RedTeam2 = BlueAllianceSchedule.RedTeam2, " \
"Matches.RedTeam3 = BlueAllianceSchedule.RedTeam3 " \
"WHERE Matches.EventID = " + str(eventID) + " ;"
cursor.execute(updateQuery)
conn.commit()