2017-08-10 23:14:45 +02:00
|
|
|
<template>
|
|
|
|
<section>
|
2017-08-13 01:23:24 +02:00
|
|
|
<header class="results-header">
|
2017-08-13 15:44:03 +02:00
|
|
|
<h1>{{ $t('euromat.results.headline') }}</h1>
|
2017-08-13 01:23:24 +02:00
|
|
|
</header>
|
2017-08-10 23:47:40 +02:00
|
|
|
|
|
|
|
<ul class="party-results">
|
2017-08-13 21:42:02 +02:00
|
|
|
<li v-for="item of results">
|
|
|
|
<h2>{{ item.token }} ({{ getScorePercentage(item.score) }} %)</h2>
|
|
|
|
<!-- <svgicon :name="getPartyLogoName(item.token)" width="50" height="50" /> -->
|
|
|
|
<party-percentage
|
|
|
|
:value="getScorePercentage(item.score)"
|
|
|
|
:max="totalScoredPoints" />
|
2017-08-10 23:47:40 +02:00
|
|
|
</li>
|
|
|
|
</ul>
|
2017-08-10 23:14:45 +02:00
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2017-08-13 21:42:02 +02:00
|
|
|
import * as SCORING from '@/app/euromat/scoring'
|
|
|
|
import { getParties, getThesesCount } from '@/data'
|
2017-08-13 01:23:24 +02:00
|
|
|
import Progress from '@/components/progress'
|
2017-08-13 15:44:03 +02:00
|
|
|
import '@/assets/icons'
|
2017-08-10 23:47:40 +02:00
|
|
|
|
2017-08-13 21:42:02 +02:00
|
|
|
// FIXME: There is a bug that not all theses are send to localStorage.
|
|
|
|
// We have 43 theses now, but only 42 are stored. Hence I check if
|
|
|
|
// answers is even an object.
|
|
|
|
|
2017-08-10 23:14:45 +02:00
|
|
|
export default {
|
|
|
|
name: 'Results',
|
|
|
|
|
2017-08-13 01:23:24 +02:00
|
|
|
components: {
|
|
|
|
'party-percentage': Progress
|
|
|
|
},
|
|
|
|
|
2017-08-10 23:14:45 +02:00
|
|
|
data () {
|
|
|
|
return {
|
2017-08-13 21:42:02 +02:00
|
|
|
answers: [],
|
|
|
|
emphasized: [],
|
2017-08-13 15:44:03 +02:00
|
|
|
results: [],
|
2017-08-10 23:47:40 +02:00
|
|
|
thesesCount: getThesesCount(),
|
2017-08-13 21:42:02 +02:00
|
|
|
parties: getParties(),
|
|
|
|
totalScoredPoints: 0
|
2017-08-10 23:47:40 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2017-08-13 15:44:03 +02:00
|
|
|
getPartyLogoName (token) {
|
|
|
|
return `${token.toLowerCase()}-logo`
|
2017-08-13 21:42:02 +02:00
|
|
|
},
|
|
|
|
getScorePercentage (score) {
|
|
|
|
console.log(score, this.totalScoredPoints)
|
|
|
|
return (score / this.totalScoredPoints * 100).toFixed(2)
|
|
|
|
},
|
|
|
|
sortResults () {
|
|
|
|
return this.parties
|
|
|
|
.map(party => ({
|
|
|
|
token: party.token,
|
|
|
|
score: party.positions
|
|
|
|
.map(this.countScoring)
|
|
|
|
.reduce((a, b) => a + b, 0)
|
|
|
|
}))
|
|
|
|
.sort((a, b) => a.score - b.score)
|
|
|
|
.reverse()
|
|
|
|
},
|
|
|
|
countScoring (partyConfig) {
|
|
|
|
const answer = this.answers.find(answer => answer.thesis === partyConfig.thesis)
|
|
|
|
if (!answer || answer.position === 'skipped') {
|
|
|
|
return SCORING.MIN_POINTS
|
|
|
|
}
|
|
|
|
|
|
|
|
let score = 0
|
|
|
|
const hasEmphasis = !!this.emphasized.find(e => e.id === answer.thesis)
|
|
|
|
const user = answer.position
|
|
|
|
const party = partyConfig.position
|
|
|
|
|
|
|
|
if (user === party) {
|
|
|
|
score = SCORING.MAX_POINTS
|
|
|
|
} else if (
|
|
|
|
(user === 'positive' && party === 'neutral') ||
|
|
|
|
(user === 'neutral' && party === 'positive') ||
|
|
|
|
(user === 'negative' && party === 'neutral')
|
|
|
|
) {
|
|
|
|
score = SCORING.BASE_POINTS
|
|
|
|
} else if (
|
|
|
|
(user === 'positive' && party === 'negative') ||
|
|
|
|
(user === 'neutral' && party === 'negative') ||
|
|
|
|
(user === 'negative' && party === 'positive')
|
|
|
|
) {
|
|
|
|
score = SCORING.MIN_POINTS
|
|
|
|
}
|
|
|
|
|
|
|
|
score = hasEmphasis ? score * SCORING.EMPHASIS_POINTS : score
|
|
|
|
this.totalScoredPoints += score
|
|
|
|
|
|
|
|
return score
|
2017-08-10 23:14:45 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-08-13 21:42:02 +02:00
|
|
|
created () {
|
|
|
|
const emphasized = JSON.parse(localStorage.getItem('euromat-emphasized'))
|
|
|
|
const answers = JSON.parse(localStorage.getItem('euromat-answers'))
|
|
|
|
|
|
|
|
if (emphasized) this.emphasized = emphasized
|
|
|
|
if (answers) this.answers = answers
|
|
|
|
|
|
|
|
this.results = this.sortResults()
|
2017-08-10 23:14:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2017-08-10 23:47:40 +02:00
|
|
|
<style lang="scss" scoped>
|
2017-08-13 01:23:24 +02:00
|
|
|
@import "~styles/layout";
|
|
|
|
|
|
|
|
.results-header {
|
|
|
|
margin-bottom: $base-gap;
|
|
|
|
}
|
|
|
|
|
2017-08-10 23:47:40 +02:00
|
|
|
.party-results {
|
|
|
|
list-style: none;
|
|
|
|
width: 100%;
|
|
|
|
|
|
|
|
li {
|
|
|
|
display: flex;
|
2017-08-13 01:23:24 +02:00
|
|
|
flex-direction: column;
|
|
|
|
margin-bottom: $base-gap;
|
2017-08-10 23:47:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|