Add war playerCount + stats

pull/2/head
Florian Hartwich 2017-07-30 08:55:14 +02:00
parent 9070964adb
commit dad3cbe067
4 changed files with 77 additions and 31 deletions

View File

@ -24,6 +24,18 @@ const WarSchema = new Schema({
set: v => Math.round(v), set: v => Math.round(v),
required: true required: true
}, },
playersBlufor: {
type: Number,
get: v => Math.round(v),
set: v => Math.round(v),
required: true
},
playersOpfor: {
type: Number,
get: v => Math.round(v),
set: v => Math.round(v),
required: true
},
bestPlayerId: { bestPlayerId: {
type: mongoose.Schema.Types.ObjectId, type: mongoose.Schema.Types.ObjectId,
ref: 'Player', ref: 'Player',

View File

@ -1,5 +1,9 @@
h3 { h3 {
width: 920px; width: 920px;
margin-bottom: 50px; margin-left: 25%;
margin-left: 25% }
.chart-container {
width: 1200px;
margin-left: 25%;
} }

View File

@ -1,11 +1,11 @@
<h3>Statistik</h3> <h3>Punkte</h3>
<div style="width: 1200px; margin-left: 25%"> <div class="chart-container">
<ngx-charts-line-chart <ngx-charts-line-chart
[view]="[1050, 400]" [view]="[1050, 400]"
[scheme]="colorScheme" [scheme]="colorScheme"
[results]="chartData" [results]="playerData"
[gradient]="false" [gradient]="false"
[xAxis]="true" [xAxis]="true"
[yAxis]="true" [yAxis]="true"
@ -20,3 +20,26 @@
</ngx-charts-line-chart> </ngx-charts-line-chart>
</div> </div>
<h3 style="margin-top: 370px;">Spielerzahlen</h3>
<div class="chart-container">
<ngx-charts-line-chart
[view]="[1050, 350]"
[scheme]="colorScheme"
[results]="pointData"
[gradient]="false"
[xAxis]="true"
[yAxis]="true"
[legend]="true"
[legendTitle]="''"
[showXAxisLabel]="true"
[showYAxisLabel]="true"
[xAxisLabel]="'Schlachtdatum'"
[yAxisLabel]="'Anzahl Spieler'"
[autoScale]="true"
(select)="onSelect($event)">
</ngx-charts-line-chart>
</div>

View File

@ -10,10 +10,11 @@ import {WarService} from "../services/war-service/war.service";
}) })
export class StatisticComponent { export class StatisticComponent {
chartData: any[] = []; pointData: any[] = [];
playerData: any[] = [];
colorScheme = { colorScheme = {
domain: ['#0000FF', '#B22222', '#595DC7', '#B25D62'] domain: ['#0000FF', '#B22222']
}; };
constructor(private appComponent: AppComponent, constructor(private appComponent: AppComponent,
@ -31,7 +32,7 @@ export class StatisticComponent {
} }
initChart(wars: any[]) { initChart(wars: any[]) {
let updateObj = [ let pointsObj = [
{ {
"name": "NATO", "name": "NATO",
"series": [] "series": []
@ -39,43 +40,49 @@ export class StatisticComponent {
{ {
"name": "CSAT", "name": "CSAT",
"series": [] "series": []
},
{
"name": "Anz. Spieler NATO",
"series": []
},
{
"name": "Anz. Spieler CSAT",
"series": []
}]; }];
let playersObj = [
{
"name": "NATO",
"series": []
},
{
"name": "CSAT",
"series": []
}
];
for (let i = wars.length - 1; i >= 0; i--) { for (let i = wars.length - 1; i >= 0; i--) {
let isoDate = wars[i].date.slice(0, 10); const isoDate = wars[i].date.slice(0, 10);
let dayDate = parseInt(isoDate.slice(8, 10)) + 1; const dayDate = parseInt(isoDate.slice(8, 10)) + 1;
let warDateString = (dayDate < 10 ? "0" + dayDate : dayDate) + '.' const warDateString = (dayDate < 10 ? "0" + dayDate : dayDate) + '.'
+ isoDate.slice(5, 7) + '.' + isoDate.slice(0, 4); + isoDate.slice(5, 7) + '.' + isoDate.slice(0, 4);
let bluforData = {
const bluforData = {
name: warDateString, name: warDateString,
value: wars[i].ptBlufor value: wars[i].ptBlufor
}; };
updateObj[0].series.push(bluforData); const opforData = {
let opforData = {
name: warDateString, name: warDateString,
value: wars[i].ptOpfor value: wars[i].ptOpfor
}; };
updateObj[1].series.push(opforData); const bluforPlayers = {
let bluforPlayers = {
name: warDateString, name: warDateString,
value: 13 value: wars[i].playersBlufor
}; };
updateObj[2].series.push(bluforPlayers); const opforPlayers = {
let opforPlayers = {
name: warDateString, name: warDateString,
value: 13 value: wars[i].playersOpfor
}; };
updateObj[3].series.push(opforPlayers);
playersObj[0].series.push(bluforData);
playersObj[1].series.push(opforData);
pointsObj[0].series.push(bluforPlayers);
pointsObj[1].series.push(opforPlayers);
} }
this.chartData = updateObj;
Object.assign(this, this.chartData) this.pointData = pointsObj;
this.playerData = playersObj;
Object.assign(this, [this.playerData, this.pointData])
} }
onSelect(event) { onSelect(event) {