working on economy graph

This commit is contained in:
cnachtigall1991
2021-10-19 07:24:16 +02:00
parent 5f96a72e76
commit 482008c77b
8 changed files with 152 additions and 10 deletions

View File

@@ -0,0 +1,108 @@
<template>
<table v-if="data.rounds">
<thead>
<tr>
<th>p1</th>
<th>p2</th>
</tr>
</thead>
<tbody v-if="data.eq_teams">
<tr v-for="(round, i) in data.eq_teams[0][0]" :key="data.eq_teams[0][i]">
<td>{{i + ' - ' + round}}</td>
</tr>
</tbody>
</table>
</template>
<script>
import {getPlayerValue} from "../utils";
import {useStore} from "vuex";
import {onMounted, reactive} from "vue";
export default {
name: "EqValueGraph",
setup() {
const store = useStore()
const data = reactive({
rounds: {},
team: [],
eq_team_1: [],
eq_team_2: [],
eq_team_player_1: [],
eq_team_player_2: [],
eq_teams: []
})
const getTeamPlayer = (stats, team) => {
let arr = []
for (let i = (team - 1) * 5; i < team * 5; i++) {
arr.push(stats[i].player.steamid64)
}
return arr
}
const parseObject = async () => {
data.rounds = await getPlayerValue(store.state.matchDetails.match_id)
let eq_1 = []
let eq_2 = []
for (const round in data.rounds) {
for (const player in data.rounds[round]) {
for (let p in data.team[0]) {
if (data.team[0][p] === player) {
eq_1.push({
round: round,
player: player,
eq: (data.rounds[round][player][0] + data.rounds[round][player][2])
})
}
}
for (let p in data.team[1]) {
if (data.team[1][p] === player) {
eq_2.push({
round: round,
player: player,
eq: (data.rounds[round][player][0] + data.rounds[round][player][2])
})
}
}
}
}
data.eq_team_player_1.push(eq_1)
data.eq_team_player_2.push(eq_2)
data.eq_team_1.push(sumArr(eq_1))
data.eq_team_2.push(sumArr(eq_2))
}
const sumArr = (arr) => {
return arr.reduce((acc, current) => ({
...acc,
[current.round]: (acc[current.round] || 0) + current.eq
}), {})
}
onMounted(() => {
data.team.push(getTeamPlayer(store.state.matchDetails.stats, 1))
data.team.push(getTeamPlayer(store.state.matchDetails.stats, 2))
parseObject()
data.eq_teams.push(data.eq_team_1, data.eq_team_2)
// console.log(data.eq_team)
})
return {data}
}
}
</script>
<style scoped>
</style>