Browse Source

funny graphs

master
gsd 10 months ago
parent
commit
d50cf10203
  1. 27
      package-lock.json
  2. 2
      package.json
  3. 21
      src/App.vue
  4. 3
      src/api/GlobalApi.js
  5. 70
      src/components/ActionDialogs/Tables/PlayersGraph.vue
  6. 8
      src/components/TabsMenuElements/MainView/Components/SubComponents/CurrentPlayers.vue

27
package-lock.json

@ -9,9 +9,11 @@
"version": "0.1.0", "version": "0.1.0",
"dependencies": { "dependencies": {
"axios": "^1.5.1", "axios": "^1.5.1",
"chart.js": "^4.4.3",
"core-js": "^3.8.3", "core-js": "^3.8.3",
"leaflet": "^1.9.4", "leaflet": "^1.9.4",
"vue": "^2.6.14", "vue": "^2.6.14",
"vue-chartjs": "^5.3.1",
"vue-material": "^1.0.0-beta-16", "vue-material": "^1.0.0-beta-16",
"vue2-leaflet": "^2.7.1" "vue2-leaflet": "^2.7.1"
}, },
@ -1961,6 +1963,11 @@
"@jridgewell/sourcemap-codec": "^1.4.14" "@jridgewell/sourcemap-codec": "^1.4.14"
} }
}, },
"node_modules/@kurkle/color": {
"version": "0.3.2",
"resolved": "https://registry.npmjs.org/@kurkle/color/-/color-0.3.2.tgz",
"integrity": "sha512-fuscdXJ9G1qb7W8VdHi+IwRqij3lBkosAm4ydQtEmbY58OzHXqQhvlxqEkoz0yssNVn38bcpRWgA9PP+OGoisw=="
},
"node_modules/@leichtgewicht/ip-codec": { "node_modules/@leichtgewicht/ip-codec": {
"version": "2.0.4", "version": "2.0.4",
"resolved": "https://registry.npmjs.org/@leichtgewicht/ip-codec/-/ip-codec-2.0.4.tgz", "resolved": "https://registry.npmjs.org/@leichtgewicht/ip-codec/-/ip-codec-2.0.4.tgz",
@ -3915,6 +3922,17 @@
"node": ">=4" "node": ">=4"
} }
}, },
"node_modules/chart.js": {
"version": "4.4.3",
"resolved": "https://registry.npmjs.org/chart.js/-/chart.js-4.4.3.tgz",
"integrity": "sha512-qK1gkGSRYcJzqrrzdR6a+I0vQ4/R+SoODXyAjscQ/4mzuNzySaMCd+hyVxitSY1+L2fjPD1Gbn+ibNqRmwQeLw==",
"dependencies": {
"@kurkle/color": "^0.3.0"
},
"engines": {
"pnpm": ">=8"
}
},
"node_modules/chokidar": { "node_modules/chokidar": {
"version": "3.5.3", "version": "3.5.3",
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz",
@ -10756,6 +10774,15 @@
"csstype": "^3.1.0" "csstype": "^3.1.0"
} }
}, },
"node_modules/vue-chartjs": {
"version": "5.3.1",
"resolved": "https://registry.npmjs.org/vue-chartjs/-/vue-chartjs-5.3.1.tgz",
"integrity": "sha512-rZjqcHBxKiHrBl0CIvcOlVEBwRhpWAVf6rDU3vUfa7HuSRmGtCslc0Oc8m16oAVuk0erzc1FCtH1VCriHsrz+A==",
"peerDependencies": {
"chart.js": "^4.1.1",
"vue": "^3.0.0-0 || ^2.7.0"
}
},
"node_modules/vue-eslint-parser": { "node_modules/vue-eslint-parser": {
"version": "8.3.0", "version": "8.3.0",
"resolved": "https://registry.npmjs.org/vue-eslint-parser/-/vue-eslint-parser-8.3.0.tgz", "resolved": "https://registry.npmjs.org/vue-eslint-parser/-/vue-eslint-parser-8.3.0.tgz",

2
package.json

@ -9,9 +9,11 @@
}, },
"dependencies": { "dependencies": {
"axios": "^1.5.1", "axios": "^1.5.1",
"chart.js": "^4.4.3",
"core-js": "^3.8.3", "core-js": "^3.8.3",
"leaflet": "^1.9.4", "leaflet": "^1.9.4",
"vue": "^2.6.14", "vue": "^2.6.14",
"vue-chartjs": "^5.3.1",
"vue-material": "^1.0.0-beta-16", "vue-material": "^1.0.0-beta-16",
"vue2-leaflet": "^2.7.1" "vue2-leaflet": "^2.7.1"
}, },

21
src/App.vue

@ -52,6 +52,27 @@ Vue.use(MdSwitch);
Vue.use(MdTooltip); Vue.use(MdTooltip);
Vue.use(MdCheckbox); Vue.use(MdCheckbox);
import {
Chart as ChartJS,
Title,
Tooltip,
Legend,
LineElement,
LinearScale,
CategoryScale,
PointElement
} from 'chart.js'
ChartJS.register(
Title,
Tooltip,
Legend,
LineElement,
LinearScale,
CategoryScale,
PointElement
)
import "@/css/buttons.css"; import "@/css/buttons.css";
import "@/css/rounded.css"; import "@/css/rounded.css";
import "@/css/text.css"; import "@/css/text.css";

3
src/api/GlobalApi.js

@ -79,6 +79,7 @@ export default class GlobalApi {
} }
getServers4Selector() { getServers4Selector() {
this.create_server_websocket()
let r = []; let r = [];
for (const srv in this.stats.servers_map) { for (const srv in this.stats.servers_map) {
r.push({"srv": this.stats.servers_map[srv]['key'], "name": this.stats.servers_map[srv]['name']}) r.push({"srv": this.stats.servers_map[srv]['key'], "name": this.stats.servers_map[srv]['name']})
@ -126,6 +127,8 @@ export default class GlobalApi {
this.stats["servers_map"] = response; this.stats["servers_map"] = response;
} else { } else {
for (let srv in response) { for (let srv in response) {
//blya nu ya i dolbaeb missnul
response[srv]['key'] = srv;
this.stats["servers_map"][srv] = response[srv]; this.stats["servers_map"][srv] = response[srv];
} }
} }

70
src/components/ActionDialogs/Tables/PlayersGraph.vue

@ -0,0 +1,70 @@
<template>
<md-dialog :md-active.sync="show" @close="show=false">
<div class="md-layout md-alignment-bottom-center">
<div class="md-layout-item md-size-100 md-small-size-100 md-alignment-bottom-center rounded-only">
<h1 v-if="loading" style="text-align: center">Загрузка</h1>
<div v-else>
<LineChartGenerator :data="chartData" :dataset-id-key="'label'" :chart-id="'line-chart'" :height="400" :width="600"></LineChartGenerator>
<div style="padding-right: 2.5%; padding-left: 2.5%;">
<md-field style="margin: 0% 0%;">
<label style="font-family: tf2secondary">Выбрать сервер</label>
<md-select @md-selected="onLoad" v-model="srv" :mdClass="'ssm'" >
<md-option :value="''">Выбрать все</md-option>
<md-option v-for="srv in $API.getServers4Selector()" :key="srv['srv']" :value="srv['srv']">{{srv['name']}}</md-option>
</md-select>
</md-field>
<md-field style="margin: 0% 0%;">
<label style="font-family: tf2secondary">Выбрать количество дней</label>
<md-select @md-selected="onLoad" v-model="limit" :mdClass="'ssm'" >
<md-option v-for="days in [7, 14, 21, 28]" :key="days" :value="days">{{days}} дней</md-option>
</md-select>
</md-field>
<md-button style="float: right" class="btn-default" v-on:click="showMe(false)">Закрыть</md-button>
</div>
</div>
</div>
</div>
</md-dialog>
</template>
<script>
import { Line as LineChartGenerator } from 'vue-chartjs'
import axios from "axios";
import Random from "@/api/Random";
export default {
name: "PlayersGraph",
data: () => ({
show: false,
loading: false,
chartData: {"labels":[], "datasets":[]},
srv: "",
limit: 7
}),
components: { LineChartGenerator },
methods: {
showMe(action) {
this.show = action === undefined ? !this.show : action;
if (action === true) {
this.onLoad();
}
},
onLoad() {
this.loading = true;
axios.get(`api/stats/graph/peak/of/days?limit=${this.limit}&server_id=${this.srv}` + Random.getRndWebAppend()).then(
response => {
//console.log(response.data);
const data = response.data.reverse();
this.chartData = {"labels":[], "datasets":[]};
for (const i in data) {
this.chartData.labels.push(data[i].date);
}
this.chartData.datasets.push({"label":"Пик игроков", backgroundColor: '#ff0000', data: data.map(d => d['max'])})
this.chartData.datasets.push({"label":"Среднее количество игроков", backgroundColor: '#fff900', data: data.map(d => d['avg'])})
//console.log(this.chartData);
}
).catch().finally(() => this.loading = false)
}
}
}
</script>

8
src/components/TabsMenuElements/MainView/Components/SubComponents/CurrentPlayers.vue

@ -18,21 +18,25 @@
<h4 class="txt-innert" style="text-align: center; margin: 10% 10%;">{{this.$API.stats.statistic.player_now}}</h4> <h4 class="txt-innert" style="text-align: center; margin: 10% 10%;">{{this.$API.stats.statistic.player_now}}</h4>
</div> </div>
<div class="md-layout-item" v-bind:class="`md-size-${space_size} ${getSH()}`"/> <div class="md-layout-item" v-bind:class="`md-size-${space_size} ${getSH()}`"/>
<div class="md-layout-item rounded-and-colored" v-bind:class="`md-size-${puff_size} ${getSS()}`"> <div class="md-layout-item rounded-and-colored" style="cursor: pointer" v-on:click="$refs.cp_pg.showMe(true)" v-bind:class="`md-size-${puff_size} ${getSS()}`">
<h4 class="txt-innert" style="text-align: center; margin: 10% 10%;">{{this.$API.stats.statistic.player_max}}</h4> <h4 class="txt-innert" style="text-align: center; margin: 10% 10%;" >{{this.$API.stats.statistic.player_max}}</h4>
</div> </div>
<div class="md-layout-item" v-bind:class="`md-size-${space_size} ${getSH()}`"/> <div class="md-layout-item" v-bind:class="`md-size-${space_size} ${getSH()}`"/>
<div class="md-layout-item rounded-and-colored" v-bind:class="`md-size-${puff_size} ${getSS()}`"> <div class="md-layout-item rounded-and-colored" v-bind:class="`md-size-${puff_size} ${getSS()}`">
<h4 class="txt-innert" style="text-align: center; margin: 10% 10%;">{{this.$API.stats.statistic.working_servers}}/{{this.$API.stats.statistic.total_servers}}</h4> <h4 class="txt-innert" style="text-align: center; margin: 10% 10%;">{{this.$API.stats.statistic.working_servers}}/{{this.$API.stats.statistic.total_servers}}</h4>
</div> </div>
</div> </div>
<PlayersGraph ref="cp_pg"/>
</div> </div>
</template> </template>
<script> <script>
import PlayersGraph from "@/components/ActionDialogs/Tables/PlayersGraph.vue";
export default { export default {
name: 'CurrentPlayers', name: 'CurrentPlayers',
components: {PlayersGraph},
data: () => ({ data: () => ({
puff_size: 15, puff_size: 15,
space_size: 5, space_size: 5,

Loading…
Cancel
Save