Skip to content

Commit

Permalink
feat: Add initial head2head
Browse files Browse the repository at this point in the history
  • Loading branch information
adberger committed Jul 1, 2024
1 parent 74e1756 commit 3beecfd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
9 changes: 7 additions & 2 deletions app/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ const layout =
useHead({
title: "Tellbow",
meta: [{ name: "description", content: "Alles rund ums Schwingen!" },
{ name: "google-site-verification", content: "3yA7b1xo5M3eQ_QOpOHA5sZeUe6hHItJK2M27aAdq_k" },],
meta: [
{ name: "description", content: "Alles rund ums Schwingen!" },
{
name: "google-site-verification",
content: "3yA7b1xo5M3eQ_QOpOHA5sZeUe6hHItJK2M27aAdq_k",
},
],
htmlAttrs: { lang: "de" },
link: [
{
Expand Down
5 changes: 5 additions & 0 deletions app/components/header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ const items = ref([
icon: "statistics-icon",
route: "/statistics",
},
{
label: "Direktvergleich",
icon: "bouts-icon",
route: "/head2head",
},
]);
function home() {
Expand Down
25 changes: 19 additions & 6 deletions app/pages/head2head/[wid]-[oid].vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const loadStatisticsData = async () => {
expand: "wrestler,place",
sort: "-place.year,-created",
fields:
"id,rank,rank2,points,final,result,wreath,status,expand.wrestler.name,expand.wrestler.vorname,expand.place.name,expand.place.year",
"id,rank,rank2,points,final,result,wreath,status,expand.wrestler.id,expand.wrestler.name,expand.wrestler.vorname,expand.place.name,expand.place.year",
})
.then((data) => {
// Grouping data by wrestler name and vorname
Expand All @@ -75,8 +75,8 @@ const loadStatisticsData = async () => {
if (!curr.expand) {
return acc; // Skip this entry if wrestler or place is undefined
}
const { name, vorname } = curr.expand.wrestler;
const key = `${name} ${vorname}`;
const { id, name, vorname } = curr.expand.wrestler;
const key = `${id} ${name} ${vorname}`;
if (!acc[key]) {
acc[key] = [];
}
Expand All @@ -87,7 +87,7 @@ const loadStatisticsData = async () => {
);
// Calculating statistics for each wrestler
const statistics = Object.entries(groupedData).map(([key, value]) => {
const [name, vorname] = key.split(" ");
const [id, name, vorname] = key.split(" ");
const averageRank = (
value.reduce((sum, entry) => sum + parseInt(entry.rank), 0) /
value.length
Expand All @@ -99,6 +99,7 @@ const loadStatisticsData = async () => {
const countWreaths = value.filter((entry) => entry.wreath).length;
const countFinals = value.filter((entry) => entry.final).length;
return {
id,
name,
vorname,
averageRank,
Expand Down Expand Up @@ -130,7 +131,7 @@ const loadBoutsData = async () => {
expand: "wrestler,opponent,place",
sort: "-place.year,-created",
fields:
"id,result,points,expand.wrestler.name,expand.wrestler.vorname,expand.opponent.name,expand.opponent.vorname,expand.place.name,expand.place.year",
"id,result,points,expand.wrestler.name,expand.wrestler.vorname,expand.opponent.name,expand.opponent.vorname,expand.place.id,expand.place.name,expand.place.year",
})
.then((data) => {
const groupedData: any = {};
Expand All @@ -143,12 +144,14 @@ const loadBoutsData = async () => {
) {
return;
}
const placeId = entry.expand.place.id;
const placeName = entry.expand.place.name;
const year = entry.expand.place.year.split("-")[0];
const key = `${placeName}-${year}`;
const key = `${placeId}-${placeName}-${year}`;
if (!groupedData[key]) {
groupedData[key] = {
place: {
id: entry.expand.place.id,
name: entry.expand.place.name,
year: entry.expand.place.year.split("-")[0],
},
Expand Down Expand Up @@ -181,6 +184,14 @@ function isHigher(stat: any, type: string, _reverse = false) {
}
return stat === highest[type];
}
async function rowRClick(rid: any) {
await navigateTo("/rankings/" + rid);
}
async function rowWClick(wid: any) {
await navigateTo("/wrestler/" + wid);
}
</script>
<template>
<div>
Expand Down Expand Up @@ -215,6 +226,7 @@ function isHigher(stat: any, type: string, _reverse = false) {
v-for="(item, index) in slotProps.items"
:key="index"
class="col-12 hover:bg-gray-200"
@click="rowWClick(item.id)"
>
<div class="grid">
<div class="col md:col-5">
Expand Down Expand Up @@ -295,6 +307,7 @@ function isHigher(stat: any, type: string, _reverse = false) {
v-for="(item, index) in slotProps.items"
:key="index"
class="col-12 hover:bg-gray-200"
@click="rowRClick(item.place.id)"
>
<div class="grid">
<div class="col md:col-7">
Expand Down
4 changes: 2 additions & 2 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export default defineNuxtConfig({
head: {
meta: [
{
"name": "google-site-verification",
"content": "3yA7b1xo5M3eQ_QOpOHA5sZeUe6hHItJK2M27aAdq_k",
name: "google-site-verification",
content: "3yA7b1xo5M3eQ_QOpOHA5sZeUe6hHItJK2M27aAdq_k",
},
],
script: [
Expand Down

0 comments on commit 3beecfd

Please sign in to comment.