Skip to content

Commit

Permalink
small statistics module for track user votes
Browse files Browse the repository at this point in the history
  • Loading branch information
scammo committed Aug 14, 2024
1 parent d1e2e5a commit 33bb03d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
10 changes: 9 additions & 1 deletion backend/app/Http/Controllers/TrackController.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,19 @@ public function proposals(Request $request)
abort(403);
}

$proposals = Proposal::where('track_id', $track->id)->where('status', $request->proposalStatus)->with('opinions', 'opinions.user')->get();
$proposals = Proposal::where('track_id', $track->id)
->where('status', $request->proposalStatus)
->with('opinions', 'opinions.user')
->get();

$opinions = Proposal::where('track_id', $track->id)
->with('opinions')
->get();

return [
'proposals' => $proposals,
'users' => $track->users,
'opinions' => $opinions
];
}

Expand Down
44 changes: 44 additions & 0 deletions frontend/src/components/OpinionStats.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<script setup>
import DataTable from 'primevue/datatable';
import Column from 'primevue/column';
const props = defineProps({
opinions: Array,
users: Array,
});
const vote_average = +props.opinions.reduce(
(accumulator, currentValue) => (parseFloat(accumulator) + parseFloat(currentValue.vote)).toFixed(2),
0
) / props.opinions.length;
const table_vote_average = props.users.map((user) => {
const userOpinions = props.opinions.filter(opinion => +opinion.user_id === +user.id).map(opinion => { return { ...opinion, vote: +opinion.vote } });
const userOpinionsVotes = userOpinions.map(opinion => +opinion.vote);
const vote_average = +userOpinions.reduce(
(accumulator, currentValue) => accumulator + currentValue.vote,
0
) / userOpinions.length || '0';
return {
username: user.username,
vote_average: new Intl.NumberFormat('de-DE').format(vote_average),
userOpinions: userOpinions.map(opinion => +opinion.vote).sort(),
min: userOpinions.length ? Math.min(...userOpinionsVotes) : 'X',
max: userOpinions.length ? Math.max(...userOpinionsVotes) : 'X'
};
});
</script>
<template>
<div class="m-4">
<h2>Opinion Stats</h2>
<p>Durchschnittswert aller Stimmen: {{ new Intl.NumberFormat('de-DE').format(vote_average) }}</p>

<h3>Durschnittswert pro User</h3>
<DataTable :value="table_vote_average">
<Column field="username" header="Username" sortable></Column>
<Column field="vote_average" header="Durchschnitt" sortable></Column>
<Column field="min" header="Niedriegster Vote" sortable></Column>
<Column field="max" header="Höchster Vote" sortable></Column>
<Column field="userOpinions" header="Alle Votes" sortable></Column>
</DataTable>
</div>
</template>
7 changes: 7 additions & 0 deletions frontend/src/views/orga/ProposalsTrack.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Column from "primevue/column";
import Accordion from "primevue/accordion";
import AccordionTab from "primevue/accordiontab";
import Button from "primevue/button";
import OpinionStats from "../../components/OpinionStats.vue";
const router = useRouter();
const route = useRoute();
Expand All @@ -21,6 +22,7 @@ const proposals = ref([]);
const toast = useToast();
const proposalStatus = ref("created");
const trackUsers = ref([]);
const trackOpions = ref([]);
onMounted(async () => {
await loadPoposals();
Expand All @@ -33,6 +35,9 @@ const loadPoposals = async () => {
const response = await client.get(`track/proposals?slug=${route.params.slug}&proposalStatus=${proposalStatus.value}`)
let data = response.data.proposals
trackUsers.value = response.data.users
trackOpions.value = response.data.opinions.flatMap((track) => {
return track.opinions
})
data = data.map((proposal) => {
return {
Expand Down Expand Up @@ -215,5 +220,7 @@ const rowClass = (data) => {
<Button label="💾 Alle Track Daten Exportieren" @click="exportTrackData" />
<Button class="ml-2" label="Export Inhaltsfelder (NICHT VERSCHLÜSSELT)" @click="exportContentData" />
<OpinionStats :opinions="trackOpions" :users="trackUsers" />
</template>
</template>

0 comments on commit 33bb03d

Please sign in to comment.