Merge pull request #12 from tresabhi/main

This commit is contained in:
TrèsAbhi authored and GitHub committed 2023-06-24 21:47:28 -05:00
commit 8882c28267
4 files changed
+6 -31

No files matched your search

+1 -1
View File
@@ -11,7 +11,7 @@ import { StatType } from '../renderers/stats.js';
export default {
inProduction: true,
inDevelopment: false,
inDevelopment: true,
inPublic: true,
command: addStatsSubCommandGroups(
-9
View File
@@ -6,15 +6,6 @@ import { PERIOD_NAMES } from './resolvePeriod.js';
export type Period = 'today' | '30' | '60' | '90' | 'career' | 'custom';
export const RELATIVE_PERIOD_NAMES: Record<Period, string> = {
today: 'A day ago',
30: '30 days ago',
60: '60 days ago',
90: '90 days ago',
career: 'Extent of data',
custom: 'Custom period',
};
export default function addPeriodSubCommands(
option: SlashCommandSubcommandGroupBuilder,
extra: (
+1 -18
View File
@@ -7,7 +7,7 @@ import { CYCLIC_API } from '../../constants/cyclic.js';
import getPeriodNow from '../blitzstars/getPeriodNow.js';
import getPeriodStart from '../blitzstars/getPeriodStart.js';
import getTimeDaysAgo from '../blitzstars/getTimeDaysAgo.js';
import { Period, RELATIVE_PERIOD_NAMES } from './addPeriodSubCommands.js';
import { Period } from './addPeriodSubCommands.js';
export const PERIOD_NAMES: Record<Period, string> = {
today: "Today's statistics",
@@ -28,7 +28,6 @@ export const EVOLUTION_PERIOD_NAMES: Record<Period, string> = {
};
export interface ResolvedPeriod {
relativePeriodName: string;
statsName: string;
evolutionName: string;
start: number;
@@ -44,21 +43,6 @@ export default function resolvePeriod(
let evolutionName: string;
let start: number;
let end: number;
let subcommand: Period;
let url: typeof interaction extends ChatInputCommandInteraction
? undefined
: URL;
if (interaction instanceof ChatInputCommandInteraction) {
subcommand = interaction.options.getSubcommand() as Period;
} else {
url = new URL(`${CYCLIC_API}/${interaction.customId}`);
const path = url.pathname.split('/').filter(Boolean);
subcommand = path[path.length - 1] as Period;
}
const period = subcommand;
const relativePeriodName = RELATIVE_PERIOD_NAMES[subcommand];
if (period === 'custom') {
const startRaw =
@@ -88,6 +72,5 @@ export default function resolvePeriod(
evolutionName,
start,
end,
relativePeriodName,
} satisfies ResolvedPeriod;
}
+4 -3
View File
@@ -19,7 +19,7 @@ import { StatType } from './stats.js';
export default async function evolution<Type extends StatType>(
type: Type,
{ start, end, evolutionName, relativePeriodName }: ResolvedPeriod,
{ start, end, evolutionName }: ResolvedPeriod,
{ server, id }: ResolvedPlayer,
tankId: Type extends 'tank' ? number : never,
) {
@@ -78,6 +78,7 @@ export default async function evolution<Type extends StatType>(
const battleYs = careerBattles.map(([, y]) => y);
const maxBattle = Math.max(...battleYs);
const minBattle = Math.min(...battleYs);
const minTime = Math.min(...careerBattles.map(([x]) => x));
const accountInfo = await getWargamingResponse<AccountInfo>(
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
@@ -97,8 +98,8 @@ export default async function evolution<Type extends StatType>(
{/* goofy ahh bug forces me to call them as functions */}
{careerWinrate.length > 0 && (
<Graph.Root
xMinLabel={relativePeriodName}
xMaxLabel="Latest recorded battle" // TODO: this is not true in custom periods
xMinLabel={new Date(minTime * 1000).toDateString()}
xMaxLabel={new Date(end * 1000).toDateString()}
leftVerticalMargin={{
min: minWinrate,
max: maxWinrate,