mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-23 11:57:50 -05:00
* Initial * CSS lint * Test CI * Add 1v1, 2v2, and 3v3 Tags (#1771) * Initial * CSS lint * Test CI * Rename step --------- Co-authored-by: xi <104683822+ximk@users.noreply.github.com>
30 lines
977 B
TypeScript
30 lines
977 B
TypeScript
import { sql } from "~/db/sql";
|
|
import type { Ability, MainWeaponId } from "~/modules/in-game-lists";
|
|
|
|
// TODO: could consider removing private builds from this
|
|
const query = (includeWeaponId: boolean) => /* sql */ `
|
|
select "BuildAbility"."ability", sum("BuildAbility"."abilityPoints") as "abilityPointsSum"
|
|
from "BuildAbility"
|
|
left join "BuildWeapon" on "BuildAbility"."buildId" = "BuildWeapon"."buildId"
|
|
${
|
|
includeWeaponId
|
|
? /* sql */ `where "BuildWeapon"."weaponSplId" = @weaponSplId`
|
|
: ""
|
|
}
|
|
group by "BuildAbility"."ability"
|
|
`;
|
|
|
|
const findByWeaponIdStm = sql.prepare(query(true));
|
|
const findAllStm = sql.prepare(query(false));
|
|
|
|
export interface AverageAbilityPointsResult {
|
|
ability: Ability;
|
|
abilityPointsSum: number;
|
|
}
|
|
|
|
export function averageAbilityPoints(weaponSplId?: MainWeaponId | null) {
|
|
const stm = typeof weaponSplId === "number" ? findByWeaponIdStm : findAllStm;
|
|
|
|
return stm.all({ weaponSplId }) as Array<AverageAbilityPointsResult>;
|
|
}
|