forked from SecondRobotics/SimTourneyBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrebuilt.ts
More file actions
134 lines (122 loc) · 4.04 KB
/
Copy pathrebuilt.ts
File metadata and controls
134 lines (122 loc) · 4.04 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
130
131
132
133
134
import fs from "fs/promises";
import fsSync from "fs";
import type { GoogleSpreadsheetRow } from "google-spreadsheet";
import type { Match } from "../match/rebuilt";
const ENERGIZED_RP_THRESHOLD = 360;
const SUPERCHARGED_RP_THRESHOLD = 500;
const TRAVERSAL_RP_THRESHOLD = 50;
const AUTO_CLIMB_POINTS = 15;
export async function getMatchData(
scheduledMatch: GoogleSpreadsheetRow,
dataDirectory: string,
matchNumber: number
): Promise<Match> {
if (!fsSync.existsSync(dataDirectory)) {
throw new Error(`Data directory ${dataDirectory} does not exist`);
}
if (!fsSync.existsSync(`${dataDirectory}/Auto_R.txt`)) {
throw new Error(
`Data directory ${dataDirectory} is not populated with data`
);
}
const red1 = scheduledMatch["Red 1"];
const red2 = scheduledMatch["Red 2"];
const red3 = scheduledMatch["Red 3"];
const blue1 = scheduledMatch["Blue 1"];
const blue2 = scheduledMatch["Blue 2"];
const blue3 = scheduledMatch["Blue 3"];
const [
redAutoString,
blueAutoString,
redAutoFuelString,
blueAutoFuelString,
redAutoLvl1String,
blueAutoLvl1String,
redTeleString,
blueTeleString,
redTeleFuelString,
blueTeleFuelString,
redEndString,
blueEndString,
redScoreString,
blueScoreString,
] = await Promise.all([
fs.readFile(`${dataDirectory}/Auto_R.txt`, "utf-8"),
fs.readFile(`${dataDirectory}/Auto_B.txt`, "utf-8"),
fs.readFile(`${dataDirectory}/Auto_Fuel_R.txt`, "utf-8"),
fs.readFile(`${dataDirectory}/Auto_Fuel_B.txt`, "utf-8"),
fs.readFile(`${dataDirectory}/Auto_lvl_1_R.txt`, "utf-8"),
fs.readFile(`${dataDirectory}/Auto_lvl_1_B.txt`, "utf-8"),
fs.readFile(`${dataDirectory}/Tele_R.txt`, "utf-8"),
fs.readFile(`${dataDirectory}/Tele_B.txt`, "utf-8"),
fs.readFile(`${dataDirectory}/Tele_Fuel_R.txt`, "utf-8"),
fs.readFile(`${dataDirectory}/Tele_Fuel_B.txt`, "utf-8"),
fs.readFile(`${dataDirectory}/End_R.txt`, "utf-8"),
fs.readFile(`${dataDirectory}/End_B.txt`, "utf-8"),
fs.readFile(`${dataDirectory}/Score_R.txt`, "utf-8"),
fs.readFile(`${dataDirectory}/Score_B.txt`, "utf-8"),
]);
// Parse values
const redAuto = parseInt(redAutoString.trim());
const blueAuto = parseInt(blueAutoString.trim());
const redAutoFuel = parseInt(redAutoFuelString.trim());
const blueAutoFuel = parseInt(blueAutoFuelString.trim());
const redAutoLvl1 = parseInt(redAutoLvl1String.trim());
const blueAutoLvl1 = parseInt(blueAutoLvl1String.trim());
const redTele = parseInt(redTeleString.trim());
const blueTele = parseInt(blueTeleString.trim());
const redTeleFuel = parseInt(redTeleFuelString.trim());
const blueTeleFuel = parseInt(blueTeleFuelString.trim());
const redEnd = parseInt(redEndString.trim());
const blueEnd = parseInt(blueEndString.trim());
const redScore = parseInt(redScoreString.trim());
const blueScore = parseInt(blueScoreString.trim());
// Calculate total fuel (auto + tele)
const redTotalFuel = redAutoFuel + redTeleFuel;
const blueTotalFuel = blueAutoFuel + blueTeleFuel;
// Calculate ranking points
let redBonusRP = 0;
let blueBonusRP = 0;
// Energized RP - 360+ total fuel
if (redTotalFuel >= ENERGIZED_RP_THRESHOLD) {
redBonusRP += 1;
}
if (blueTotalFuel >= ENERGIZED_RP_THRESHOLD) {
blueBonusRP += 1;
}
// Supercharged RP - 500+ total fuel
if (redTotalFuel >= SUPERCHARGED_RP_THRESHOLD) {
redBonusRP += 1;
}
if (blueTotalFuel >= SUPERCHARGED_RP_THRESHOLD) {
blueBonusRP += 1;
}
// Traversal RP - 50+ climb points (end climb points + (auto climbs * 15))
const redClimbPoints = redEnd + redAutoLvl1 * AUTO_CLIMB_POINTS;
const blueClimbPoints = blueEnd + blueAutoLvl1 * AUTO_CLIMB_POINTS;
if (redClimbPoints >= TRAVERSAL_RP_THRESHOLD) {
redBonusRP += 1;
}
if (blueClimbPoints >= TRAVERSAL_RP_THRESHOLD) {
blueBonusRP += 1;
}
return {
matchNumber,
red1,
red2,
red3,
blue1,
blue2,
blue3,
redScore,
blueScore,
redAuto,
blueAuto,
redTele,
blueTele,
redEnd,
blueEnd,
redBonusRP,
blueBonusRP,
};
}