diff --git a/.vscode/settings.json b/.vscode/settings.json index 2b09f08da..862f08758 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,6 +9,7 @@ "Smri", "strvk", "tankopedia", + "Unicum", "Unregistering", "vickers", "wargaming", diff --git a/src/commands/stats.tsx b/src/commands/stats.tsx index ecb3c6465..3a7304f8e 100644 --- a/src/commands/stats.tsx +++ b/src/commands/stats.tsx @@ -85,12 +85,12 @@ export default { return accumulator + tankTier * stats.battles; }, 0) / totalBattles, - wn8: + WN8: entries.reduce((accumulator, [tankIdString, stats]) => { const tankId = Number(tankIdString); - const tankWn8 = getWN8(tankAverages[tankId].all, stats); + const tankWN8 = getWN8(tankAverages[tankId].all, stats); - return accumulator + tankWn8 * stats.battles; + return accumulator + tankWN8 * stats.battles; }, 0) / totalBattles, }; diff --git a/src/commands/tankstats.tsx b/src/commands/tankstats.tsx index 3edcf380b..0e4854ffa 100644 --- a/src/commands/tankstats.tsx +++ b/src/commands/tankstats.tsx @@ -100,7 +100,7 @@ export default { stats={stats} supplementaryStats={{ tier: tankopedia[tankId].tier, - wn8: getWN8(tankAverages[tankId].all, stats), + WN8: getWN8(tankAverages[tankId].all, stats), }} /> )} diff --git a/src/components/GenericAllStats.tsx b/src/components/GenericAllStats.tsx index 62039cf49..24d8b1d06 100644 --- a/src/components/GenericAllStats.tsx +++ b/src/components/GenericAllStats.tsx @@ -1,3 +1,4 @@ +import getWN8Percentile from '../core/blitz/getWN8Percentile.js'; import { AllStats, SupplementaryStats } from '../types/accountInfo.js'; import GenericStats from './GenericStats/index.js'; @@ -14,7 +15,13 @@ export default function GenericAllStats({ {stat[0]} - + + {stat[2] && } {stat[1]} diff --git a/src/components/GenericStats/index.tsx b/src/components/GenericStats/index.tsx index 53e253e57..d85239537 100644 --- a/src/components/GenericStats/index.tsx +++ b/src/components/GenericStats/index.tsx @@ -1,6 +1,9 @@ +import { Percentile } from '../../constants/percentiles.js'; import GenericStatsColumn from './components/GenericStatsColumn.js'; -export type Stat = [string, string | number]; +export type Stat = + | [string, string | number] + | [string, string | number, Percentile | undefined]; export interface GenericStatsProps { stats: Stat[]; diff --git a/src/components/PercentileIndicator.tsx b/src/components/PercentileIndicator.tsx new file mode 100644 index 000000000..9a466a562 --- /dev/null +++ b/src/components/PercentileIndicator.tsx @@ -0,0 +1,45 @@ +import { + blue, + green, + lime, + orange, + pink, + purple, + red, + slate, + teal, + yellow, +} from '@radix-ui/colors'; +import { Percentile } from '../constants/percentiles.js'; + +export interface PercentileIndicatorProps { + percentile: Percentile; +} + +export const PERCENTILE_COLORS = { + [Percentile.VeryBad]: slate.slate9, + [Percentile.Bad]: red.red9, + [Percentile.BelowAverage]: orange.orange9, + [Percentile.Average]: yellow.yellow9, + [Percentile.AboveAverage]: lime.lime9, + [Percentile.Good]: green.green9, + [Percentile.VeryGood]: teal.teal9, + [Percentile.Great]: blue.blue9, + [Percentile.Unicum]: pink.pink9, + [Percentile.SuperUnicum]: purple.purple9, +}; + +export default function PercentileIndicator({ + percentile, +}: PercentileIndicatorProps) { + return ( +
+ ); +} diff --git a/src/constants/percentiles.ts b/src/constants/percentiles.ts new file mode 100644 index 000000000..f0e7dbfec --- /dev/null +++ b/src/constants/percentiles.ts @@ -0,0 +1,13 @@ +// http://www.wotinfo.net/en/wn8scale +export enum Percentile { + VeryBad, + Bad, + BelowAverage, + Average, + AboveAverage, + Good, + VeryGood, + Great, + Unicum, + SuperUnicum, +} diff --git a/src/core/blitz/getWN8Percentile.ts b/src/core/blitz/getWN8Percentile.ts new file mode 100644 index 000000000..870bf83d4 --- /dev/null +++ b/src/core/blitz/getWN8Percentile.ts @@ -0,0 +1,21 @@ +import { Percentile } from '../../constants/percentiles.js'; + +const WN8_PERCENTILES: [number, Percentile][] = [ + [0, Percentile.VeryBad], + [300, Percentile.Bad], + [450, Percentile.BelowAverage], + [650, Percentile.Average], + [900, Percentile.AboveAverage], + [1200, Percentile.Good], + [1600, Percentile.VeryGood], + [2000, Percentile.Great], + [2450, Percentile.Unicum], + [2900, Percentile.SuperUnicum], +]; + +export default function getWN8Percentile(WN8: number) { + const lastIndex = WN8_PERCENTILES.findLastIndex( + ([WN8Listing]) => WN8Listing <= WN8, + ); + return WN8_PERCENTILES[lastIndex === -1 ? 0 : lastIndex][1]; +} diff --git a/src/types/accountInfo.ts b/src/types/accountInfo.ts index 3e14adc50..908930892 100644 --- a/src/types/accountInfo.ts +++ b/src/types/accountInfo.ts @@ -19,7 +19,7 @@ export interface AllStats { } export interface SupplementaryStats { - wn8: number; + WN8: number; tier: number; }