Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Real-Septicake committed Mar 9, 2024
2 parents 05b4fc5 + bcb9901 commit b4a5f9b
Showing 1 changed file with 1 addition and 95 deletions.
96 changes: 1 addition & 95 deletions scripts/BetterCSVParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,25 +184,6 @@ def isolateLocations(outputPath: str) -> CSV:
file.close()
return newCSV

def calcAmpedVsUnampedExact(totalCycles: int, speakerScore: int) -> list[int]:
for unamped in range(totalCycles + 1):
amped = totalCycles - unamped
if unamped * 2 + amped * 5 == speakerScore:
return [unamped * 2, amped * 5]
return None

def calcAmpedVsUnampedClosest(totalCycles: int, speakerScore: int) -> tuple[int, list[int]]:
minDiff: int = 1e16
res: list[int] = []
for unamped in range(totalCycles + 1):
amped = totalCycles - unamped
diff = abs(speakerScore - (unamped * 2 + amped * 5))
if(diff < minDiff):
minDiff = diff
res = [unamped * 2, amped * 5]

return (minDiff, res)

def allianceToList(scores: AllianceScores, matchLevel: str, matchNum: str, alliance: str) -> list[str]:
row = []
row.append(matchLevel)
Expand All @@ -223,81 +204,6 @@ def allianceToList(scores: AllianceScores, matchLevel: str, matchNum: str, allia

return row

def allianceScores(alliance: AllianceScores) -> None:
alliance.total = alliance.leaves + alliance.autoAmp + alliance.teleopAmp + alliance.stageTotal + alliance.teleopSpeakerPoints

scores = calcAmpedVsUnampedExact(alliance.teleopSpeakerScores, alliance.teleopSpeakerPoints - alliance.autoSpeaker)

if scores == None:
scores = calcAmpedVsUnampedClosest(alliance.teleopSpeakerScores, alliance.teleopSpeakerPoints - alliance.autoSpeaker)
alliance.difference = scores[0]
alliance.teleopUnampedSpeaker = scores[1][0]
alliance.teleopAmpedSpeaker = scores[1][1]
alliance.harmony = alliance.stageTotal - alliance.stage - alliance.trap
else:
alliance.difference = 0
alliance.teleopUnampedSpeaker = scores[0]
alliance.teleopAmpedSpeaker = scores[1]
alliance.harmony = alliance.stageTotal - alliance.stage - alliance.trap

def isolateAllianceScores(csv: CSV) -> CSV:
newCSV = CSV()
headers = ['Match Level', 'Match #', 'Alliance', 'Total Score', 'Leaves Start', 'Auto Amp Points', 'Auto Speaker Points', 'Teleop Amp Points', 'Speaker Cycles', 'Teleop Unamped Points', 'Teleop Amped Points', 'Stage Points', 'Harmony Points', 'Difference', 'Trap Points']
newCSV.append(headers)
red = AllianceScores()
blue = AllianceScores()
prevMatch = prevMatch = int(csv[1][findHeader(csv, 'Match #')])
for i in range(1, len(csv)):
if int(csv[i][findHeader(csv, 'Match #')]) != prevMatch:
allianceScores(red)
allianceScores(blue)

redRow = allianceToList(red, csv[i - 1][findHeader(csv, 'Match Level')], str(prevMatch), 'red')
blueRow = allianceToList(blue, csv[i - 1][findHeader(csv, 'Match Level')], str(prevMatch), 'blue')

newCSV.append(redRow)
newCSV.append(blueRow)

red = AllianceScores()
blue = AllianceScores()

prevMatch = int(csv[i][findHeader(csv, 'Match #')])
start = csv[i][findHeader(csv, 'Robot')]
alliance = blue if isBlueAlliance(start) else red

alliance.teleopSpeakerPoints = int(csv[i][findHeader(csv, 'Speaker Score')])
alliance.leaves += int(csv[i][findHeader(csv, 'Leave Starting Zone')]) * 2
alliance.autoAmp += int(csv[i][findHeader(csv, 'Auto Amp Scores')]) * 2
autoSpeaker = csv[i][findHeader(csv, 'Auto Scoring Locations')].split(',')
alliance.autoSpeaker += (len(autoSpeaker) if autoSpeaker[0] != '' else 0) * 5
teleopScores = csv[i][findHeader(csv, TELE_SCORE_LOCS)].split(',')
teleopSpeaker = 0
teleopAmp = 0
for loc in teleopScores:
if loc == 'a':
teleopAmp += 1
elif loc == '':
continue
else:
teleopSpeaker += 1
alliance.teleopAmp += teleopAmp
alliance.teleopSpeakerScores += teleopSpeaker
alliance.stageTotal = int(csv[i][findHeader(csv, 'Stage Score')])
stageValue = csv[i][findHeader(csv, 'Final Status')]
alliance.stage += 4 if stageValue == 's' else 3 if stageValue == 'o' else 1 if stageValue == 'p' else 0
alliance.climbing += 1 if stageValue == 's' or 'o' else 0
alliance.trap += int(csv[i][findHeader(csv, 'Note in Trap')]) * 5

allianceScores(red)
allianceScores(blue)

redRow = allianceToList(red, csv[len(csv) - 1][findHeader(csv, 'Match Level')], str(prevMatch), 'red')
blueRow = allianceToList(blue, csv[len(csv) - 1][findHeader(csv, 'Match Level')], str(prevMatch), 'blue')

newCSV.append(redRow)
newCSV.append(blueRow)
return newCSV

def addAllianceToData(csv: CSV) -> CSV:
newCSV = CSV()
newCSV.append(csv[0])
Expand Down Expand Up @@ -333,7 +239,7 @@ def writeOutputToFile(fileName: str, func):
writeOutputToFile("TeleopMisses", isolateTeleMisses)
writeOutputToFile("AutoPickups", isolateAutoPickupLocations)
writeOutputToFile("AutoScores", isolateAutoScores)
writeOutputToFile("AllianceScores", isolateAllianceScores)
# writeOutputToFile("AllianceScores", isolateAllianceScores)
writeOutputToFile("DataWithAlliance", addAllianceToData)

with open(output_path + "/AllLocations.csv", 'w', encoding='utf-8') as csvFile: # All locations requires special handling
Expand Down

0 comments on commit b4a5f9b

Please sign in to comment.