Refactoring calculator code

This commit is contained in:
Dominic Ferrando
2025-09-14 14:22:17 -04:00
parent e3c4a5c285
commit aacfcccb9a
5 changed files with 6033 additions and 279 deletions
+5 -22
View File
@@ -1,14 +1,11 @@
import { calcAttributeLevels, calcPlayerLevel, computeLevels } from "./calculator/calc.ts";
import { Activity, BenchmarkPerformance, Player } from "./calculator/util.ts";
import { calcAllAttributeLevels, calcPlayerLevel } from "./calculator/calc.ts";
import { ActivityPerformance, Player } from "./calculator/util.ts";
import { Printful } from "./commerce/printful.ts"
import { Webflow } from "./commerce/webflow.ts";
interface CalcRequest {
player: Player,
performances: {
activity: Activity,
performance: number,
}[]
performances: ActivityPerformance[]
}
export class ClientResponse extends Response {
@@ -39,24 +36,10 @@ const server = Bun.serve({
const calcReq: CalcRequest = await req.json();
const { player, performances } = calcReq;
const computedPerformances: BenchmarkPerformance[] = [];
for (const p of performances) {
computedPerformances.push({
activity: p.activity,
performance: p.performance,
levels: computeLevels(
player.age,
player.weightKG,
player.gender,
p.activity
)
})
}
return ClientResponse.json({
levels: {
attributes: calcAttributeLevels(player, computedPerformances),
player: calcPlayerLevel(player, computedPerformances)
attributes: calcAllAttributeLevels(player, performances),
player: calcPlayerLevel(player, performances)
}
})
}