-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
378 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
<script setup lang="ts"> | ||
import { useTitle } from '@vueuse/core'; | ||
import { BarElement, CategoryScale, Chart as ChartJS, ChartData, Legend, LinearScale, Title, Tooltip } from 'chart.js'; | ||
import dayjs from "dayjs"; | ||
import { Ref, ref, watch } from "vue"; | ||
import { Bar } from 'vue-chartjs'; | ||
import { useI18n } from 'vue-i18n'; | ||
import dataService from "../services/DataService"; | ||
const { t } = useI18n({ | ||
inheritLocale: true, | ||
useScope: 'global' | ||
}) | ||
useTitle('Jelu | Stats') | ||
console.log(dayjs('2020-1-1').format('MMMM')) | ||
console.log(dayjs('2020-3-1').format('MMMM')) | ||
ChartJS.register(Title, Tooltip, Legend, BarElement, CategoryScale, LinearScale) | ||
const getYears = () => { | ||
dataService.yearsWithStats() | ||
.then(res => { | ||
years.value = res | ||
}) | ||
.catch(e => { | ||
console.log(e) | ||
}) | ||
} | ||
const getAllStats = () => { | ||
dataService.yearStats() | ||
.then(res => { | ||
let labels = res.map(r => r.year) | ||
const updatedChartData = { | ||
labels: labels, | ||
datasets: [ | ||
{ | ||
label: 'finished', | ||
backgroundColor: '#bbbbbb', | ||
data: res.map(r => r.finished) | ||
}, | ||
{ | ||
label: 'dropped', | ||
backgroundColor: '#f87979', | ||
data: res.map(r => r.dropped) | ||
} | ||
] | ||
} | ||
chartData.value = { ...updatedChartData } | ||
}) | ||
.catch(e => { | ||
console.log(e) | ||
}) | ||
} | ||
const getYearStats = () => { | ||
if (currentYear.value != null) { | ||
dataService.monthStatsForYear(currentYear.value) | ||
.then(res => { | ||
let labels = res.map(r => r.month).map(m => dayjs(`2020-${m}-1`).format('MMMM')) | ||
const updatedChartData = { | ||
labels: labels, | ||
datasets: [ | ||
{ | ||
label: 'finished', | ||
backgroundColor: '#bbbbbb', | ||
data: res.map(r => r.finished) | ||
}, | ||
{ | ||
label: 'dropped', | ||
backgroundColor: '#f87979', | ||
data: res.map(r => r.dropped) | ||
} | ||
] | ||
} | ||
yearChartData.value = { ...updatedChartData } | ||
}) | ||
.catch(e => { | ||
console.log(e) | ||
}) | ||
} | ||
} | ||
const loaded = ref(false) | ||
const chartData = ref<ChartData<'bar'>>({ | ||
datasets: [] | ||
}) | ||
const yearChartData = ref<ChartData<'bar'>>({ | ||
datasets: [] | ||
}) | ||
const years: Ref<Array<number>> = ref([]) | ||
const currentYear: Ref<number|null> = ref(null) | ||
watch(currentYear, (newVal, oldVal) => { | ||
console.log("year " + newVal + " " + oldVal) | ||
getYearStats() | ||
}) | ||
getAllStats() | ||
getYears() | ||
</script> | ||
|
||
<template> | ||
<div class="grid grid-cols-1 justify-center justify-items-center justify-self-center"> | ||
<h1 class="text-2xl typewriter w-11/12 sm:w-8/12 pb-4 capitalize"> | ||
{{ t('stats.all_time') }} | ||
</h1> | ||
<div class=""> | ||
<Bar | ||
:chart-data="chartData" | ||
/> | ||
</div> | ||
<h1 class="text-2xl typewriter w-11/12 sm:w-8/12 py-4 capitalize"> | ||
{{ t('stats.yearly_stats') }} | ||
</h1> | ||
<div v-if="years != null && years !== undefined && years.length > 0" class=""> | ||
<select | ||
v-model="currentYear" | ||
class="select select-bordered select-accent pt-2 mb-4" | ||
> | ||
<option | ||
disabled | ||
selected | ||
> | ||
{{ t('stats.choose_year') }} | ||
</option> | ||
<option | ||
v-for="year in years" | ||
:key="year" | ||
:value="year" | ||
> | ||
{{ year }} | ||
</option> | ||
</select> | ||
<Bar | ||
:chart-data="yearChartData" | ||
/> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export interface YearStats { | ||
dropped: number, | ||
finished: number, | ||
year: number | ||
} | ||
|
||
export interface MonthStats { | ||
dropped: number, | ||
finished: number, | ||
year: number, | ||
month: number | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.