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

93 lines
2.1 KiB
TypeScript
Raw Normal View History

2017-07-29 12:59:51 +02:00
import {Component} from "@angular/core";
2017-07-29 18:00:21 +02:00
import {AppComponent} from "../app.component";
2017-07-29 12:59:51 +02:00
import {WarService} from "../services/war-service/war.service";
@Component({
selector: 'statistic',
templateUrl: './statistic.component.html',
styleUrls: ['./statistic.component.css']
})
export class StatisticComponent {
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
};
2017-07-29 18:00:21 +02:00
constructor(private appComponent: AppComponent,
private warService: WarService) {
2017-07-29 12:59:51 +02:00
}
ngOnInit() {
2017-07-29 18:00:21 +02:00
let wars = this.appComponent.wars;
if (wars.length === 0) {
this.warService.getAllWars().subscribe(items => {
this.initChart(items);
2017-07-29 12:59:51 +02:00
})
2017-07-29 18:00:21 +02:00
}
this.initChart(wars);
}
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
onSelect(event) {
console.log(event);
}
}