diff --git a/src/app/statistics/statistics.component.ts b/src/app/statistics/statistics.component.ts index 0e76c2a..7d9655b 100644 --- a/src/app/statistics/statistics.component.ts +++ b/src/app/statistics/statistics.component.ts @@ -27,7 +27,8 @@ export class StatisticsComponent implements OnInit { public radial_metrics = ['l1.current', 'l2.current', 'l3.current', 'engine.rpm', 'fuel.pressure', 'l1.l0.voltage', 'l2.l0.voltage', 'l3.l0.voltage', 'total.kw']; public slide_metrics = ['coolant.temp', 'fuel.temp', 'oil.temp', 'oil.pressure']; - public timer$; + public datatimer$; + public statetimer$; getMajorTicks(metric: GeneratorMetric) { const total = (metric.max - metric.min); @@ -65,9 +66,6 @@ export class StatisticsComponent implements OnInit { loadData() { const gen_id = parseInt(localStorage.getItem('gen_id'), 10); this.login.getToken().then((jsonToken) => { - this.data2.getGeneratorState(gen_id, jsonToken).then((state) => { - this.generator_state = state; - }); this.data2.getGeneratorStatistics(gen_id, jsonToken).then((statistics) => { this.generator_statistics = statistics; }); @@ -76,6 +74,17 @@ export class StatisticsComponent implements OnInit { }); } + loadState() { + const gen_id = parseInt(localStorage.getItem('gen_id'), 10); + this.login.getToken().then((jsonToken) => { + this.data2.getGeneratorState(gen_id, jsonToken).then((state) => { + this.generator_state = state; + }); + }, (error) => { + // todo go to logout + }); + } + reloadLoop() { } @@ -83,10 +92,14 @@ export class StatisticsComponent implements OnInit { ngOnInit() { localStorage.removeItem('data_type'); localStorage.removeItem('fault_type'); - this.timer$ = timer(0, 60000); - this.timer$.subscribe(() => { + this.datatimer$ = timer(0, 60000); + this.datatimer$.subscribe(() => { this.loadData(); }); + this.statetimer$ = timer(0, 5000); + this.statetimer$.subscribe(() => { + this.loadState(); + }); // this.loadData(); }