Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
PowerPanel-Frontend/src/app/statistics/statistics.component.ts
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
93 lines (78 sloc)
2.66 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Component, OnInit} from '@angular/core'; | |
import {MetricsService} from '../services/metrics.service'; | |
import {HttpClient, HttpHeaders} from '@angular/common/http'; | |
import { Router } from '@angular/router'; | |
import {LoginService} from '../services/login.service'; | |
import { GeneratorState, GeneratorMetric} from '../generator-object'; | |
import { GeneratorService } from '../services/generator.service'; | |
import { timer } from 'rxjs/observable/timer'; | |
@Component({ | |
selector: 'app-statistics', | |
templateUrl: './statistics.component.html', | |
styleUrls: ['./statistics.component.css'] | |
}) | |
export class StatisticsComponent implements OnInit { | |
constructor(public data: MetricsService, public data2: GeneratorService, private http: HttpClient, | |
private router: Router, private login: LoginService) { | |
} | |
public metric: any; | |
public generator_state: GeneratorState; | |
public generator_statistics: Map<string, GeneratorMetric>; | |
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$; | |
getMajorTicks(metric: GeneratorMetric) { | |
const total = (metric.max - metric.min); | |
let inner = 0; | |
if (total % 6 === 0) { | |
inner = total / 6; | |
} else if (total % 5 === 0) { | |
inner = total / 5; | |
} | |
const tick_array = []; | |
for (let i = metric.min; i < metric.max; i += inner) { | |
tick_array.push(i); | |
} | |
tick_array.push(metric.max); | |
return tick_array.join(','); | |
} | |
getMetric(metric_name: string) { | |
if (this.generator_statistics.has(metric_name)) { | |
return this.generator_statistics.get(metric_name); | |
} else { | |
return null; | |
} | |
} | |
goToGraphGen() { | |
this.router.navigateByUrl('/visualize-one'); | |
} | |
goToGraphSpec(dataType) { | |
this.router.navigateByUrl('/visualize-one'); | |
localStorage.setItem('data_type', dataType); | |
} | |
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; | |
}); | |
}, (error) => { | |
// todo go to logout | |
}); | |
} | |
reloadLoop() { | |
} | |
ngOnInit() { | |
localStorage.removeItem('data_type'); | |
localStorage.removeItem('fault_type'); | |
this.timer$ = timer(0, 60000); | |
this.timer$.subscribe(() => { | |
this.loadData(); | |
}); | |
// this.loadData(); | |
} | |
} |