Skip to content

Commit

Permalink
Merge pull request #31 from AkinariHex/nextjs
Browse files Browse the repository at this point in the history
Tournament submission fix and toast for submission confirmation
  • Loading branch information
AkinariHex authored Jan 7, 2024
2 parents 68a5878 + 5845048 commit 9d8cd69
Show file tree
Hide file tree
Showing 12 changed files with 623 additions and 210 deletions.
3 changes: 2 additions & 1 deletion app/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ export async function saveTournamentMatches(
ids: matchIDs,
});

let isSubmissionVerified = formData.get('verifierCheckBox') ?? false;
let isSubmissionVerified =
formData.get('verifierCheckBox') == 'on' ?? false;

await fetch(
`${process.env.REACT_APP_API_URL}/matches/batch?verified=${isSubmissionVerified}`,
Expand Down
44 changes: 24 additions & 20 deletions app/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import AreaChart from '@/components/Charts/AreaChart/AreaChart';
import BarChart from '@/components/Charts/BarChart/BarChart';
import DoughnutChart from '@/components/Charts/DoughnutChart/DoughnutChart';
import PlayersBarChart from '@/components/Charts/PlayersBarChart/PlayersBarChart';
import RadarChart from '@/components/Charts/RadarChart/RadarChart';
import FilterButtons from '@/components/Dashboard/FilterButtons/FilterButtons';
import GridCard from '@/components/Dashboard/GridCard/GridCard';
import UserTotalMatches from '@/components/Dashboard/Matches/UserTotalMatches/UserTotalMatches';
Expand Down Expand Up @@ -30,7 +31,7 @@ export default async function page({

return (
<main className={styles.main}>
<div className={styles.notices}>
{/* <div className={styles.notices}>
<Notice title={'About your TR'}>
Your TR (tournament rating) is calculated based on your match cost
relative to other players in your matches, see{' '}
Expand Down Expand Up @@ -59,7 +60,7 @@ export default async function page({
"If you've never played osu! tournaments before, welcome! You can start earning TR simply by playing in osu! tournament matches."
}
/>
</div>
</div> */}
<UserMainCard data={data?.generalStats} />
<div className={styles.mainGraphContainer}>
<FilterButtons params={searchParams} />
Expand Down Expand Up @@ -158,8 +159,8 @@ export default async function page({
</span>
</div>
</GridCard>
<GridCard title={'Winrate by mod - TO DO'}>
<BarChart mainAxe={'x'} />
<GridCard title={'Winrate by mod'}>
<RadarChart winrateModData={data?.modStats} />
</GridCard>
<GridCard title={'Teammates'}>
<div className={styles.cardStat}>
Expand All @@ -174,10 +175,6 @@ export default async function page({
{data?.matchStats.bestTeammateName}
</span>
</div>
<div className={styles.cardStat}>
<span>Worst teammate (to remove)</span>
<span className={styles.value}>??</span>
</div>
</GridCard>
<GridCard title={'Opponents'}>
<div className={styles.cardStat}>
Expand All @@ -190,13 +187,9 @@ export default async function page({
<span>Best opponent</span>
<span className={styles.value}>TO DO</span>
</div>
<div className={styles.cardStat}>
<span>Worst opponent (to remove)</span>
<span className={styles.value}>??</span>
</div>
</GridCard>
<GridCard title={'Average score per mod - TO DO'}>
<BarChart mainAxe={'x'} />
<GridCard title={'Average score per mod'}>
<RadarChart averageModScore={data?.modStats} />
</GridCard>
<GridCard title={'Most played with teammates - TO DO'}>
<PlayersBarChart />
Expand All @@ -211,20 +204,31 @@ export default async function page({
<AreaChart />
</div>
</GridCard>
<GridCard title={'Most common team size - TO DO'}>
<BarChart mainAxe={'x'} />
<GridCard title={'Most common team size'}>
<BarChart
mainAxe={'x'}
teamSizes={data?.tournamentStats.teamSizeCounts}
/>
</GridCard>
<GridCard title={'Most common format - TO DO'}>
<BarChart mainAxe={'x'} />
</GridCard>
<GridCard title={'Summary of placements - TO DO'}>
<BarChart mainAxe={'x'} />
</GridCard>
<GridCard title={'Best tournament performances - TO DO'}>
<BarChart mainAxe={'y'} />
<GridCard title={'Best tournament performances'}>
<BarChart
mainAxe={'y'}
bestTournamentPerformances={data?.tournamentStats.bestPerformances}
/>
</GridCard>
<GridCard title={'Worst tournament performances - TO DO'}>
<BarChart mainAxe={'y'} />
<GridCard title={'Worst tournament performances'}>
<BarChart
mainAxe={'y'}
worstTournamentPerformances={
data?.tournamentStats.worstPerformances
}
/>
</GridCard>
</StatsGrid>
</main>
Expand Down
4 changes: 2 additions & 2 deletions components/Charts/AreaChart/AreaChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ export default function AreaChart({
fill: true,
label: '',
data: dataForGraph,
borderWidth: 2,
borderWidth: 3,
borderColor: `hsla(${colors[0]}, 0.6)`,
backgroundColor: `hsla(${colors[1]}, 0.6)`,
backgroundColor: 'transparent' /* `hsla(${colors[1]}, 0.6)` */,
font: font,
},
],
Expand Down
70 changes: 60 additions & 10 deletions components/Charts/BarChart/BarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,19 @@ ChartJS.register(
Legend
);

export default function BarChart({ mainAxe = 'x' }: { mainAxe: any }) {
export default function BarChart({
mainAxe = 'x',
bestTournamentPerformances,
worstTournamentPerformances,
teamSizes,
}: {
mainAxe: any;
bestTournamentPerformances?: any;
worstTournamentPerformances?: any;
teamSizes?: any;
}) {
const [font, setFont] = useState('');
const [color, setColor] = useState('');

/* get variables of colors from CSS */
useEffect(() => {
Expand All @@ -32,6 +43,9 @@ export default function BarChart({ mainAxe = 'x' }: { mainAxe: any }) {
'--font-families'
)
);
setColor(
getComputedStyle(document.documentElement).getPropertyValue('--green-400')
);
}, []);

const options = {
Expand All @@ -52,7 +66,7 @@ export default function BarChart({ mainAxe = 'x' }: { mainAxe: any }) {
display: false,
},
tooltip: {
enabled: false,
enabled: true,
},
},
scales: {
Expand All @@ -63,6 +77,7 @@ export default function BarChart({ mainAxe = 'x' }: { mainAxe: any }) {
family: font,
},
},
grace: '2%',
/* border: {
color: 'transparent',
}, */
Expand All @@ -74,27 +89,62 @@ export default function BarChart({ mainAxe = 'x' }: { mainAxe: any }) {
family: font,
},
},
grace: '10%',
stepsSize: 1,
},
},
};

const labels = ['HR', 'NM', 'HD', 'FM'];
var labels = ['HR', 'NM', 'HD', 'FM'];
var dataScores = ['']; /* labels.map(() => Math.ceil(Math.random() * 20)) */

if (bestTournamentPerformances) {
labels.length = 0;
bestTournamentPerformances.map((tournament: any, index: any) => {
labels[index] = tournament.tournamentName;
dataScores[index] = tournament.matchCost.toFixed(2);
return;
});
}

if (worstTournamentPerformances) {
labels.length = 0;
worstTournamentPerformances.map((tournament: any, index: any) => {
labels[index] = tournament.tournamentName;
dataScores[index] = tournament.matchCost.toFixed(2);
return;
});
}

if (teamSizes) {
Object.keys(teamSizes).map((data: any, index: any) => {
labels[index] = data.replace('count', '');
return;
});

Object.values(teamSizes).map((data: any, index: any) => {
dataScores[index] = data;
return;
});
}

const data = {
labels,
datasets: [
{
label: 'Dataset 1',
data: labels.map(() => Math.ceil(Math.random() * 100)),
backgroundColor: [
'rgba(255, 99, 132)',
'rgba(54, 162, 235)',
'rgba(255, 206, 86)',
'rgba(25, 156, 86)',
],
data: dataScores,
backgroundColor: teamSizes
? [
'rgba(120, 227, 117, 1)',
'rgba(76, 148, 255, 1)',
'rgba(227, 117, 117, 1)',
]
: `hsla(${color})`,
/* barThickness: 30, */
/* maxBarThickness: 30, */
beginAtZero: true,
padding: 10,
},
],
};
Expand Down
3 changes: 3 additions & 0 deletions components/Charts/RadarChart/RadarChart.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.radarChart {
height: 20rem;
}
152 changes: 152 additions & 0 deletions components/Charts/RadarChart/RadarChart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
'use client';

import {
Chart as ChartJS,
Filler,
Legend,
LineElement,
PointElement,
RadialLinearScale,
Tooltip,
} from 'chart.js';
import { useEffect, useState } from 'react';
import { Radar } from 'react-chartjs-2';
import styles from './RadarChart.module.css';

ChartJS.register(
RadialLinearScale,
PointElement,
LineElement,
Filler,
Tooltip,
Legend
);

export default function RadarChart({
winrateModData,
averageModScore,
}: {
winrateModData?: any;
averageModScore?: any;
}) {
const [colors, setColors] = useState<string[]>([]);
const [font, setFont] = useState('');

/* get variables of colors from CSS */
useEffect(() => {
setColors([
getComputedStyle(document.documentElement).getPropertyValue('--blue-600'),
getComputedStyle(document.documentElement).getPropertyValue('--blue-400'),
]);
setFont(
getComputedStyle(document.documentElement).getPropertyValue(
'--font-families'
)
);
}, []);

let labels = ['NM', 'HD', 'HR', 'DT', 'EZ'];
let values = [95, 90, 22, 10, 50];

if (winrateModData) {
labels = ['NM', 'HD', 'HR', 'DT', 'EZ'];
values = [
(winrateModData.playedNM?.winrate * 100) | 0,
(winrateModData.playedHD?.winrate * 100) | 0,
(winrateModData.playedHR?.winrate * 100) | 0,
(winrateModData.playedDT?.winrate * 100) | 0,
(winrateModData.playedEZ?.winrate * 100) | 0,
];
}

if (averageModScore) {
labels = ['NM', 'HD', 'HR', 'DT', 'EZ'];
values = [
averageModScore.playedNM?.normalizedAverageScore.toFixed(0) | 0,
averageModScore.playedHD?.normalizedAverageScore.toFixed(0) | 0,
averageModScore.playedHR?.normalizedAverageScore.toFixed(0) | 0,
averageModScore.playedDT?.normalizedAverageScore.toFixed(0) | 0,
averageModScore.playedEZ?.normalizedAverageScore.toFixed(0) | 0,
];
}

const data = {
labels: labels,
datasets: [
{
label: winrateModData
? 'Winrate %'
: averageModScore
? 'AVG Score'
: 'Winrate %',
data: values,
backgroundColor: `hsla(${colors[0]}, 0.15)`,
borderWidth: 0,
},
],
};

const options = {
elements: {
line: {
borderWidth: 0,
},
point: {
pointBackgroundColor: `hsla(${colors[1]})`,
pointBorderWidth: 0,
},
},
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
display: false,
position: 'right' as const,
},
title: {
display: false,
},
tooltip: {
enabled: true,
},
},

layout: {
padding: {
left: 0,
},
},
scales: {
r: {
backgroundColor: 'rgb(250,250,250)',
beginAtZero: true,
angleLines: {
borderDash: (context: any) => {
const space = context.scale.yCenter - context.scale.top - 30;
const ticksLength = context.scale.ticks.length - 1;
const spaceInPx = space / ticksLength;
return [0, 0, 0, spaceInPx, 2500];
},
},
min: 0,
max: winrateModData ? 100 : averageModScore ? 1200000 : 100,
ticks: {
stepSize: winrateModData ? 25 : averageModScore ? 300000 : 25,
callback: (value: any, tick: any, values: any) => {
return '';
},
showLabelBackdrop: (context: any) => {
return false;
},
/* maxTicksLimit: 4, */
},
},
},
};

return (
<div className={styles.radarChart}>
<Radar data={data} options={options} />
</div>
);
}
Loading

0 comments on commit 9d8cd69

Please sign in to comment.