opt-cc/static/src/app/statistic/overview/stats-overview.component.ts

83 lines
1.9 KiB
TypeScript
Raw Normal View History

2017-07-29 12:59:51 +02:00
import {Component} from "@angular/core";
import {WarService} from "../../services/war-service/war.service";
2017-07-29 12:59:51 +02:00
@Component({
selector: 'stats-overview',
templateUrl: './stats-overview.component.html',
styleUrls: ['./stats-overview.component.css']
2017-07-29 12:59:51 +02:00
})
export class StatisticOverviewComponent {
2017-07-29 12:59:51 +02:00
2017-07-30 08:55:14 +02:00
pointData: any[] = [];
playerData: any[] = [];
2017-07-29 12:59:51 +02:00
colorScheme = {
2017-07-30 08:55:14 +02:00
domain: ['#0000FF', '#B22222']
2017-07-29 12:59:51 +02:00
};
constructor(private warService: WarService) {
2017-07-29 12:59:51 +02:00
}
ngOnInit() {
this.warService.getAllWars().subscribe(items => {
this.initChart(items);
})
2017-07-29 18:00:21 +02:00
}
initChart(wars: any[]) {
2017-07-30 08:55:14 +02:00
let pointsObj = [
2017-07-29 18:00:21 +02:00
{
"name": "NATO",
"series": []
},
{
"name": "CSAT",
"series": []
2017-07-30 08:55:14 +02:00
}];
let playersObj = [
2017-07-29 18:00:21 +02:00
{
2017-07-30 08:55:14 +02:00
"name": "NATO",
2017-07-29 18:00:21 +02:00
"series": []
},
{
2017-07-30 08:55:14 +02:00
"name": "CSAT",
2017-07-29 18:00:21 +02:00
"series": []
2017-07-30 08:55:14 +02:00
}
];
2017-07-29 18:00:21 +02:00
for (let i = wars.length - 1; i >= 0; i--) {
2017-07-30 08:55:14 +02:00
const isoDate = wars[i].date.slice(0, 10);
const dayDate = parseInt(isoDate.slice(8, 10)) + 1;
const warDateString = (dayDate < 10 ? "0" + dayDate : dayDate) + '.'
2017-07-29 18:00:21 +02:00
+ isoDate.slice(5, 7) + '.' + isoDate.slice(0, 4);
2017-07-30 08:55:14 +02:00
const bluforData = {
2017-07-29 18:00:21 +02:00
name: warDateString,
value: wars[i].ptBlufor
};
2017-07-30 08:55:14 +02:00
const opforData = {
2017-07-29 18:00:21 +02:00
name: warDateString,
value: wars[i].ptOpfor
};
2017-07-30 08:55:14 +02:00
const bluforPlayers = {
2017-07-29 18:00:21 +02:00
name: warDateString,
2017-07-30 08:55:14 +02:00
value: wars[i].playersBlufor
2017-07-29 18:00:21 +02:00
};
2017-07-30 08:55:14 +02:00
const opforPlayers = {
2017-07-29 18:00:21 +02:00
name: warDateString,
2017-07-30 08:55:14 +02:00
value: wars[i].playersOpfor
2017-07-29 18:00:21 +02:00
};
2017-07-30 08:55:14 +02:00
playersObj[0].series.push(bluforData);
playersObj[1].series.push(opforData);
pointsObj[0].series.push(bluforPlayers);
pointsObj[1].series.push(opforPlayers);
2017-07-29 18:00:21 +02:00
}
2017-07-30 08:55:14 +02:00
this.pointData = pointsObj;
this.playerData = playersObj;
Object.assign(this, [this.playerData, this.pointData])
2017-07-29 18:00:21 +02:00
}
2017-07-29 12:59:51 +02:00
}