Skip to content
Permalink
b52798ca46
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
214 lines (164 sloc) 5.28 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 } from '../generator-object';
import { GeneratorService } from '../services/generator.service';
@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 fuelTemp: any;
public oilTemp: any;
public pACurrent: any;
public pBCurrent: any;
public pCCurrent: any;
public engineSpeed: any;
public fuelPressure: any;
public pAVoltage: any;
public pBVoltage: any;
public pCVoltage: any;
public totalKw: any;
public coolantTemp: any;
public oilPressure: any;
public fuelTempCheck: any;
public oilTempCheck: any;
public pACurrentCheck: any;
public pBCurrentCheck: any;
public pCCurrentCheck: any;
public engineSpeedCheck: any;
public fuelLevelCheck: any;
public pAVoltageCheck: any;
public pBVoltageCheck: any;
public pCVoltageCheck: any;
public totalKwCheck: any;
public coolantTempCheck: any;
public oilPressureCheck: any;
public metric: any;
public metricYearAvg: any;
public fuelTempYearAvg: any;
public isRecent: boolean = true;
public isHour: boolean = false;
public isDay: boolean = false;
public isWeek: boolean = false;
public isMonth: boolean = false;
public isYear: boolean = false;
public isOvercrank: boolean = false;
public isHighEngineTemperature: boolean = false;
public isLowOilPressure: boolean = false;
public isOverspeed: boolean = false;
public isEmergencyStop: boolean = false;
public isLowFuel: boolean = false;
public isLowCoolant: boolean = false;
public isLowCrankingVoltage: boolean = false;
public isBatteryVoltage: boolean = false;
public isBatteryChargerFail: boolean = false;
public isCommonFault: boolean = false;
public isEPSSupplying: boolean = false;
public isNotInAuto: boolean = false;
public isSystemRunning: boolean = false;
public isGeneratorRunning: boolean = false;
public isCommunicationStatus: boolean = false;
public testArray: String[] = ["overcrank", "high_engine_temp"];
public generator : GeneratorState;
goToGraphGen()
{
this.router.navigateByUrl('/visualize-one');
}
goToGraphSpec(dataType)
{
this.router.navigateByUrl('/visualize-one');
localStorage.setItem('data_type', dataType);
}
lengthCheck(metricArray)
{
if (metricArray.length == 0)
{
return null;
}
else
{
return metricArray[0][1];
}
}
setCheck(metricArray)
{
if(metricArray.length == 0)
{
console.log(false)
return false;
}
else
{
console.log(true);
return true;
}
}
statusChange(genStatus)
{
if(genStatus == "overcrank")
{
return this.isOvercrank = true;
}
else if(genStatus == "high_engine_temp")
{
return this.isHighEngineTemperature = true;
}
}
async ngOnInit() {
localStorage.removeItem('data_type');
localStorage.removeItem('fault_type');
const jsonToken = await this.login.getToken();
const gen_id = parseInt(localStorage.getItem('gen_id'),10);
try {
this.data.getDevMetrics(jsonToken).subscribe((data) => {
//console.log(data.outputs[1].dps[0][1]);
this.metric = data;
//console.log(this.metric.outputs[0].dps.length == 0);
this.fuelTemp = this.lengthCheck(this.metric.outputs[0].dps);
//this.fuelTempCheck = this.setCheck(this.metric.outputs[0].dps);
//console.log(this.fuelTempCheck);
//this.fuelTemp = this.metric.outputs[0].dps[0][1];
this.oilTemp = this.metric.outputs[1].dps[0][1];
this.pACurrent = this.metric.outputs[2].dps[0][1];
this.pBCurrent = this.metric.outputs[3].dps[0][1];
this.pCCurrent = this.metric.outputs[4].dps[0][1];
this.engineSpeed = this.metric.outputs[5].dps[0][1];
this.fuelPressure = this.metric.outputs[6].dps[0][1];
this.pAVoltage = this.metric.outputs[7].dps[0][1];
this.pBVoltage = this.metric.outputs[8].dps[0][1];
this.pCVoltage = this.metric.outputs[9].dps[0][1];
this.totalKw = this.metric.outputs[10].dps[0][1];
this.coolantTemp = this.metric.outputs[11].dps[0][1];
this.oilPressure = this.metric.outputs[12].dps[0][1];
});
this.generator = await this.data2.getGeneratorState(gen_id,jsonToken);
if (this.generator.fault_count == 0)
{
console.log("hi");
}
else
{
for(var i = 0; i< this.testArray.length; i++)
{
this.statusChange(this.testArray[i]);
}
}
} catch (err) {
return err;
}
try {
this.data.getYearMetrics(jsonToken).subscribe((data) => {
this.metricYearAvg = data;
this.fuelTempYearAvg = this.metricYearAvg.outputs[0].dps[0][1];
});
} catch (err) {
return err;
}
}
}