Skip to content

Commit d93f8d6

Browse files
committed
updato servero
1 parent 8d6e8b5 commit d93f8d6

2 files changed

Lines changed: 87 additions & 44 deletions

File tree

src/handler/analysis/analysisConstants.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const metricsCategory: Metric[] = [
8484
];
8585

8686
// To differentiate auton and teleop events, benefit of the doubt given to auto
87-
const autoEnd = 18;
87+
const autoEnd = 23;
8888

8989
const specificMatchPageMetrics = [];
9090

@@ -153,7 +153,9 @@ const accuracyToPercentage: Record<number, number> = {
153153
5: 95,
154154
};
155155

156-
export const accuracyToPercentageInterpolated = (avg: number | null | undefined): number => {
156+
export const accuracyToPercentageInterpolated = (
157+
avg: number | null | undefined,
158+
): number => {
157159
avg = Math.max(0, Math.min(5, avg));
158160

159161
if (avg === null || avg === undefined) return 0;

src/handler/analysis/coreAnalysis/averageAllTeamFast.ts

Lines changed: 83 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ const config = {
6060
if (vals.length > 0)
6161
perTournamentAvg.push(vals.reduce((a, b) => a + b, 0) / vals.length);
6262
}
63-
return perTournamentAvg.length ? weightedTourAvgLeft(perTournamentAvg) : 0;
63+
return perTournamentAvg.length
64+
? weightedTourAvgLeft(perTournamentAvg)
65+
: 0;
6466
}
6567

6668
if (metric === Metric.accuracy) {
@@ -87,7 +89,9 @@ const config = {
8789
);
8890
}
8991
}
90-
return perTournamentPercents.length ? weightedTourAvgLeft(perTournamentPercents) : 0;
92+
return perTournamentPercents.length
93+
? weightedTourAvgLeft(perTournamentPercents)
94+
: 0;
9195
}
9296

9397
if (metric === Metric.fuelPerSecond) {
@@ -123,7 +127,8 @@ const config = {
123127
return duration > 0 ? totalFuel / duration : 0;
124128
});
125129

126-
const avgRate = perReportRates.reduce((a, b) => a + b, 0) / perReportRates.length;
130+
const avgRate =
131+
perReportRates.reduce((a, b) => a + b, 0) / perReportRates.length;
127132
return avgRate;
128133
}
129134

@@ -152,11 +157,14 @@ const config = {
152157
return scored + fed;
153158
});
154159
if (totalsPerMatch.length > 0) {
155-
const avgMatch = totalsPerMatch.reduce((a, b) => a + b, 0) / totalsPerMatch.length;
160+
const avgMatch =
161+
totalsPerMatch.reduce((a, b) => a + b, 0) / totalsPerMatch.length;
156162
perTournamentAvg.push(avgMatch);
157163
}
158164
}
159-
const weighted = perTournamentAvg.length ? weightedTourAvgLeft(perTournamentAvg) : 0;
165+
const weighted = perTournamentAvg.length
166+
? weightedTourAvgLeft(perTournamentAvg)
167+
: 0;
160168

161169
return weighted;
162170
}
@@ -185,11 +193,14 @@ const config = {
185193
return total;
186194
});
187195
if (totalsPerMatch.length > 0) {
188-
const avgMatch = totalsPerMatch.reduce((a, b) => a + b, 0) / totalsPerMatch.length;
196+
const avgMatch =
197+
totalsPerMatch.reduce((a, b) => a + b, 0) / totalsPerMatch.length;
189198
perTournamentAvg.push(avgMatch);
190199
}
191200
}
192-
return perTournamentAvg.length ? weightedTourAvgLeft(perTournamentAvg) : 0;
201+
return perTournamentAvg.length
202+
? weightedTourAvgLeft(perTournamentAvg)
203+
: 0;
193204
}
194205

195206
if (metric === Metric.outpostIntakes) {
@@ -203,10 +214,15 @@ const config = {
203214
},
204215
});
205216
if (reports.length === 0) return 0;
206-
const perReportCounts = reports.map((r) =>
207-
r.events.filter((e) => e.action === "INTAKE" && e.position === "OUTPOST").length,
217+
const perReportCounts = reports.map(
218+
(r) =>
219+
r.events.filter(
220+
(e) => e.action === "INTAKE" && e.position === "OUTPOST",
221+
).length,
222+
);
223+
return (
224+
perReportCounts.reduce((a, b) => a + b, 0) / perReportCounts.length
208225
);
209-
return perReportCounts.reduce((a, b) => a + b, 0) / perReportCounts.length;
210226
}
211227

212228
if (metric === Metric.timeFeeding) {
@@ -220,7 +236,9 @@ const config = {
220236
if (reports.length === 0) return 0;
221237
const perReport = reports.map((r) => {
222238
const feedEvents = r.events
223-
.filter((e) => e.action === "START_FEEDING" || e.action === "STOP_FEEDING")
239+
.filter(
240+
(e) => e.action === "START_FEEDING" || e.action === "STOP_FEEDING",
241+
)
224242
.sort((a, b) => a.time - b.time);
225243
let total = 0;
226244
for (let i = 0; i < feedEvents.length; i += 2) {
@@ -248,7 +266,10 @@ const config = {
248266
if (reports.length === 0) return 0;
249267
const perReportContact = reports.map((r) => {
250268
const evs = r.events
251-
.filter((e) => e.action === "START_DEFENDING" || e.action === "STOP_DEFENDING")
269+
.filter(
270+
(e) =>
271+
e.action === "START_DEFENDING" || e.action === "STOP_DEFENDING",
272+
)
252273
.sort((a, b) => a.time - b.time);
253274
let total = 0;
254275
for (let i = 0; i < evs.length; i += 2) {
@@ -260,7 +281,9 @@ const config = {
260281
});
261282
const perReportCamping = reports.map((r) => {
262283
const evs = r.events
263-
.filter((e) => e.action === "START_CAMPING" || e.action === "STOP_CAMPING")
284+
.filter(
285+
(e) => e.action === "START_CAMPING" || e.action === "STOP_CAMPING",
286+
)
264287
.sort((a, b) => a.time - b.time);
265288
let total = 0;
266289
for (let i = 0; i < evs.length; i += 2) {
@@ -270,8 +293,10 @@ const config = {
270293
}
271294
return evs.length ? total : 0;
272295
});
273-
const contactAvg = perReportContact.reduce((a, b) => a + b, 0) / perReportContact.length;
274-
const campingAvg = perReportCamping.reduce((a, b) => a + b, 0) / perReportCamping.length;
296+
const contactAvg =
297+
perReportContact.reduce((a, b) => a + b, 0) / perReportContact.length;
298+
const campingAvg =
299+
perReportCamping.reduce((a, b) => a + b, 0) / perReportCamping.length;
275300
if (metric === Metric.contactDefenseTime) return contactAvg;
276301
if (metric === Metric.campingDefenseTime) return campingAvg;
277302
return contactAvg + campingAvg;
@@ -289,23 +314,31 @@ const config = {
289314
},
290315
});
291316
if (reports.length === 0) return 0;
292-
const times: number[] = [];
293-
reports.forEach((r) => {
294-
const first = r.events
295-
.filter((e) => e.action === "CLIMB" && (e.time ?? 0) <= autoEnd)
296-
.map((e) => e.time ?? 0)
297-
.sort((a, b) => a - b)[0];
298-
if (first !== undefined) {
299-
// convert to remaining auto time (auto = 18s)
300-
times.push(autoEnd - first);
301-
}
302-
});
303-
return times.length ? times.reduce((a, b) => a + b, 0) / times.length : 0;
317+
const times: number[] = [];
318+
reports.forEach((r) => {
319+
const first = r.events
320+
.filter((e) => e.action === "CLIMB" && (e.time ?? 0) <= autoEnd)
321+
.map((e) => e.time ?? 0)
322+
.sort((a, b) => a - b)[0];
323+
if (first !== undefined) {
324+
// convert to remaining auto time (auto = 23s)
325+
times.push(autoEnd - first);
326+
}
327+
});
328+
return times.length ? times.reduce((a, b) => a + b, 0) / times.length : 0;
304329
}
305330

306-
if (metric === Metric.l1StartTime || metric === Metric.l2StartTime || metric === Metric.l3StartTime) {
331+
if (
332+
metric === Metric.l1StartTime ||
333+
metric === Metric.l2StartTime ||
334+
metric === Metric.l3StartTime
335+
) {
307336
const required =
308-
metric === Metric.l1StartTime ? "L1" : metric === Metric.l2StartTime ? "L2" : "L3";
337+
metric === Metric.l1StartTime
338+
? "L1"
339+
: metric === Metric.l2StartTime
340+
? "L2"
341+
: "L3";
309342
const reports = await prismaClient.scoutReport.findMany({
310343
where: {
311344
teamMatchData: { tournamentKey: sourceTnmtFilter },
@@ -319,17 +352,22 @@ const config = {
319352
if (reports.length === 0) return 0;
320353
const times: number[] = [];
321354
reports.forEach((r) => {
322-
const firstTeleop = r.events
323-
.filter((e) => e.action === "CLIMB" && (e.time ?? 0) > autoEnd && (e.time ?? 0) <= 158)
324-
.map((e) => e.time ?? 0)
325-
.sort((a, b) => a - b)[0];
326-
if (firstTeleop !== undefined) {
327-
// convert to remaining match time (match = 158s)
328-
const remaining = 158 - firstTeleop;
329-
times.push(remaining >= 0 ? remaining : 0);
330-
}
331-
});
332-
return times.length ? times.reduce((a, b) => a + b, 0) / times.length : 0;
355+
const firstTeleop = r.events
356+
.filter(
357+
(e) =>
358+
e.action === "CLIMB" &&
359+
(e.time ?? 0) > autoEnd &&
360+
(e.time ?? 0) <= 158,
361+
)
362+
.map((e) => e.time ?? 0)
363+
.sort((a, b) => a - b)[0];
364+
if (firstTeleop !== undefined) {
365+
// convert to remaining match time (match = 158s)
366+
const remaining = 158 - firstTeleop;
367+
times.push(remaining >= 0 ? remaining : 0);
368+
}
369+
});
370+
return times.length ? times.reduce((a, b) => a + b, 0) / times.length : 0;
333371
}
334372

335373
if (metric === Metric.defenseEffectiveness) {
@@ -360,7 +398,10 @@ const config = {
360398
metric === Metric.teleopPoints
361399
? ({ time: { gt: autoEnd }, action: "STOP_SCORING" } as any)
362400
: metric === Metric.autoPoints
363-
? ({ time: { lte: autoEnd }, action: "STOP_SCORING" } as any)
401+
? ({
402+
time: { lte: autoEnd },
403+
action: "STOP_SCORING",
404+
} as any)
364405
: ({ action: "STOP_SCORING" } as any),
365406
select: { points: true, time: true },
366407
},
@@ -391,7 +432,7 @@ const config = {
391432
perTournamentValues[tnmt].push(matchTotal / row.scoutReports.length);
392433
}
393434
const perTournamentAverages = Object.values(perTournamentValues).map(
394-
(arr) => (arr.reduce((a, b) => a + b, 0) / arr.length) || 0,
435+
(arr) => arr.reduce((a, b) => a + b, 0) / arr.length || 0,
395436
);
396437
return perTournamentAverages.length
397438
? weightedTourAvgLeft(perTournamentAverages)

0 commit comments

Comments
 (0)