Skip to content
Permalink
06ac7bc75c
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
106 lines (90 sloc) 2.99 KB
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 datatimer$;
public statetimer$;
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.getGeneratorStatistics(gen_id, jsonToken).then((statistics) => {
this.generator_statistics = statistics;
});
}, (error) => {
// todo go to logout
});
}
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() {
}
ngOnInit() {
localStorage.removeItem('data_type');
localStorage.removeItem('fault_type');
this.datatimer$ = timer(0, 60000);
this.datatimer$.subscribe(() => {
this.loadData();
});
this.statetimer$ = timer(0, 5000);
this.statetimer$.subscribe(() => {
this.loadState();
});
// this.loadData();
}
}