Skip to content

Commit 5b59dca

Browse files
committed
Add units queued chart
1 parent 89d3e8d commit 5b59dca

8 files changed

Lines changed: 133 additions & 3 deletions

File tree

public/tcc3/drafts.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

public/tcc3/units.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

src/components/BarChart.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ const availableSeries = {
8989
mapPlayed(counts: [string, number][]): BarSeriesOption {
9090
return { data: counts.map(([_, count]) => count) };
9191
},
92+
unitCounts(counts): BarSeriesOption {
93+
return { data: counts.map(([_, count]) => count) };
94+
},
9295
};
9396
9497
type Series = typeof availableSeries;

src/components/Tournament.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
import { computed } from "vue";
33
import TournamentOverview from "./TournamentOverview.vue";
44
import PlayerStats from "./PlayerStats.vue";
5+
import UnitStats from "./UnitStats.vue";
56
const {
67
page = "overview",
78
code,
89
presetMapNames,
910
} = defineProps<{
10-
page: "overview" | "players" | "results";
11+
page: "overview" | "players" | "results" | "units";
1112
code: string;
1213
presetMapNames: Record<string, string>;
1314
}>();
@@ -17,6 +18,7 @@ const statsPages = {
1718
overview: TournamentOverview,
1819
results: TournamentOverview,
1920
players: PlayerStats,
21+
units: UnitStats,
2022
};
2123
</script>
2224

@@ -42,6 +44,12 @@ const statsPages = {
4244
:class="{ secondary: page != 'players' }"
4345
>Players</a
4446
>
47+
<!-- <a -->
48+
<!-- :href="`${baseLink}/units`" -->
49+
<!-- role="button" -->
50+
<!-- :class="{ secondary: page != 'units' }" -->
51+
<!-- >Units</a -->
52+
<!-- > -->
4553
</div>
4654
</div>
4755
<hr />

src/components/TournamentOverview.vue

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useData } from "vitepress";
44
import MapPicksChart from "./MapPicksChart.vue";
55
import MapBansChart from "./MapBansChart.vue";
66
import CivPickChart from "./CivPickChart.vue";
7-
import { allCivs, Draft, Drafts, Game, Player } from "../types";
7+
import { allCivs, Draft, Drafts, Game, Player, Unit } from "../types";
88
import CivBansChart from "./CivBansChart.vue";
99
import CivPlayedChart, { type GameStats } from "./CivPlayedChart.vue";
1010
import CivWinrateChart from "./CivWinrateChart.vue";
@@ -13,6 +13,7 @@ import { fetchData, normalizeCivs } from "../utils";
1313
import EApmChart from "./EApmChart.vue";
1414
import VilCountChart from "./VilCountChart.vue";
1515
import MostCreatedChart from "./MostCreatedChart.vue";
16+
import UnitAmountChart from "./UnitAmountChart.vue";
1617
1718
const props = defineProps({
1819
code: { type: String, required: true },
@@ -23,6 +24,7 @@ const { params } = useData();
2324
const drafts: Ref<Drafts> = ref({ civDrafts: [], mapDrafts: [] });
2425
const games: Ref<Game[]> = ref([]);
2526
const players: Ref<Player[]> = ref([]);
27+
const units: Ref<Unit[]> = ref([]);
2628
const selectedBrackets = ref([...(params.value?.brackets ?? [])]);
2729
const selectedMaps: Ref<string[]> = ref([]);
2830
@@ -31,10 +33,12 @@ watchEffect(async () => {
3133
fetchData(props.code, "drafts"),
3234
fetchData(props.code, "games"),
3335
fetchData(props.code, "players"),
36+
fetchData(props.code, "units"),
3437
];
3538
drafts.value = await promises[0];
3639
games.value = await promises[1];
3740
players.value = await promises[2];
41+
units.value = await promises[3];
3842
});
3943
4044
function mapName(map_id: string) {
@@ -169,6 +173,20 @@ const filteredPlayers = computed(
169173
// .filter((player) => selectedMaps.value.includes(mapName(player.map))),
170174
);
171175
176+
const unitCounts = computed(() => {
177+
return units.value.reduce(
178+
(totals, playerData) => {
179+
if (playerData.unit_name == "Villager") return totals;
180+
return {
181+
...totals,
182+
[playerData.unit_name]:
183+
(totals[playerData.unit_name] ?? 0) + playerData.amount,
184+
};
185+
},
186+
{} as Record<string, number>,
187+
);
188+
});
189+
172190
const allMaps = computed(() => {
173191
return [...new Set(games.value.map((game) => game.map))].toSorted();
174192
});
@@ -294,6 +312,7 @@ watch(allMaps, () => {
294312
<EApmChart :players="filteredPlayers" />
295313
<VilCountChart :players="filteredPlayers" />
296314
<MostCreatedChart :players="filteredPlayers" />
315+
<UnitAmountChart v-if="units.length" :units="unitCounts" />
297316
</template>
298317

299318
<style lang="css" module>

src/components/UnitAmountChart.vue

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<script setup lang="ts">
2+
import { computed } from "vue";
3+
import BarChart, { type SeriesParam } from "./BarChart.vue";
4+
5+
const props = defineProps(["units"]);
6+
const counts = computed(() =>
7+
Object.entries(props.units).toSorted(([_unitA, a], [_unitB, b]) => b - a),
8+
);
9+
10+
const series: SeriesParam[] = [{ type: "unitCounts", title: "Units queued" }];
11+
</script>
12+
<template>
13+
<div>
14+
<BarChart
15+
title="Units Queued (overall, no filters)"
16+
yAxis="Queue"
17+
:counts="counts"
18+
:series="series"
19+
/>
20+
</div>
21+
</template>

src/components/UnitStats.vue

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<script setup lang="ts">
2+
import { useData } from "vitepress";
3+
import { computed, Ref, ref, watchEffect } from "vue";
4+
import { Unit } from "../types";
5+
import { fetchData } from "../utils";
6+
import MapPicksChart from "./MapPicksChart.vue";
7+
import UnitAmountChart from "./UnitAmountChart.vue";
8+
9+
const props = defineProps({
10+
code: { type: String, required: true },
11+
presetMapNames: { type: Object, required: true },
12+
});
13+
const { params } = useData();
14+
15+
const units: Ref<Unit[]> = ref([]);
16+
const unitCounts = computed(() => {
17+
return units.value.reduce(
18+
(totals, playerData) => {
19+
if (playerData.unit_name == "Villager") return totals;
20+
return {
21+
...totals,
22+
[playerData.unit_name]:
23+
(totals[playerData.unit_name] ?? 0) + playerData.amount,
24+
};
25+
},
26+
{} as Record<string, number>,
27+
);
28+
});
29+
30+
watchEffect(async () => {
31+
units.value = await fetchData(props.code, "units");
32+
});
33+
</script>
34+
35+
<template>
36+
<div class="pico">
37+
<h5>Unit Stats</h5>
38+
<pre>
39+
{{ unitCounts }}
40+
<UnitAmountChart :units="unitCounts" />
41+
</pre>
42+
</div>
43+
</template>
44+
45+
<style lang="css" module>
46+
.options {
47+
:global(.grid) {
48+
grid-template-columns: repeat(3, 1fr);
49+
}
50+
}
51+
52+
.bracket {
53+
:global(.grid) {
54+
grid-template-columns: repeat(3, 1fr);
55+
}
56+
}
57+
58+
:global(.pico) {
59+
input[type="search"] {
60+
margin-top: 2rem;
61+
}
62+
}
63+
64+
.win td {
65+
background-color: var(--vp-c-green-3);
66+
}
67+
68+
.loss td {
69+
background-color: var(--vp-c-red-3);
70+
}
71+
</style>

src/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ export type Player = {
6767
most_created_count: number;
6868
};
6969

70+
export type Unit = {
71+
player: string;
72+
unit_id: number;
73+
unit_name: string;
74+
amount: number;
75+
};
76+
7077
export const allCivs = [
7178
"Britons",
7279
"Byzantines",

0 commit comments

Comments
 (0)