Skip to content

Commit 69bf7d2

Browse files
authored
Merge pull request #491 from The-Purple-Warehouse/main
[staging deploy] Change accuracy to interval system
2 parents 2195ed6 + 17784f4 commit 69bf7d2

3 files changed

Lines changed: 134 additions & 93 deletions

File tree

helpers/scouting.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ export function randomBolts() {
264264
}
265265
}
266266

267+
let pendingAccuracy = new Set();
268+
267269
export async function addEntry(
268270
contributingTeam: string,
269271
contributingUsername: string,
@@ -447,7 +449,9 @@ export async function addEntry(
447449
}
448450
});
449451
await entry.save();
450-
await updateAccuracy(event);
452+
if(!event.endsWith("-prac")) {
453+
pendingAccuracy.add(event);
454+
}
451455
}
452456
return entry;
453457
}
@@ -763,7 +767,16 @@ export async function getTeamData(
763767
}
764768
}
765769

770+
export async function updatePendingAccuracy() {
771+
let events = [...pendingAccuracy] as any;
772+
for(let i = 0; i < events.length; i++) {
773+
pendingAccuracy.delete(events[i]);
774+
await updateAccuracy(events[i]);
775+
}
776+
}
777+
766778
export async function updateAccuracy(event: string) {
779+
console.log("calculating accuracy for event", event);
767780
let { data, categories, teams } = await getAllRawDataByEvent(event);
768781
let matches: any = {};
769782
for (let i = 0; i < data.length; i++) {

index.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { addAPIHeaders } from "./helpers/utils";
1515

1616
import config from "./config";
1717
import { registerComponentsWithinDirectory } from "./helpers/componentRegistration";
18-
import { getStats, initializeCategories } from "./helpers/scouting";
18+
import { getStats, initializeCategories, updatePendingAccuracy } from "./helpers/scouting";
1919

2020
// import loginRouter from "./routers/login"; // contains base route "/"
2121
import defaultRouter from "./routers/default"; // contains base route "/"
@@ -207,6 +207,19 @@ app.use(router.routes());
207207
app.use(router.allowedMethods());
208208
app.use(serve("./static", {}));
209209

210+
let calculatingAccuracy = false;
211+
setInterval(async () => {
212+
if(!calculatingAccuracy) {
213+
calculatingAccuracy = true;
214+
console.log("calculating accuracy");
215+
await updatePendingAccuracy();
216+
console.log("done calculating accuracy");
217+
calculatingAccuracy = false;
218+
} else {
219+
console.log("skipping accuracy");
220+
}
221+
}, 1000 * 60); // 1 minute
222+
210223
const httpServer = createServer(app.callback());
211224

212225
(async () => {

package-lock.json

Lines changed: 106 additions & 91 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)