Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
integrated ngifs with statuses, cleaned up code
  • Loading branch information
ema14006 committed Apr 15, 2019
1 parent 2fd9d3c commit 10aa0bb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 114 deletions.
43 changes: 16 additions & 27 deletions src/app/statistics/statistics.component.html
Expand Up @@ -107,67 +107,61 @@
<h3 class = "p-3">Faults</h3>
</div>
<div class = "col-md-6">
<h5 *ngIf = "isOvercrank; else emptyOvercrank"><span class="badge badge-danger">Overcrank</span></h5>
<h5 *ngIf = "this.generator.fault_codes.includes('fault.overcrank'); else emptyOvercrank"><span class="badge badge-danger">Overcrank</span></h5>
<ng-template #emptyOvercrank>
<h5><span class="badge badge-secondary">Overcrank</span></h5>
</ng-template>
</div>
<div class = "col-md-6">
<h5 *ngIf = "isHighEngineTemperature; else emptyEngine"><span class="badge badge-danger">High Engine<br>Temperature</span></h5>
<h5 *ngIf = "this.generator.fault_codes.includes('fault.engine.temp.high'); else emptyEngine"><span class="badge badge-danger">High Engine<br>Temperature</span></h5>
<ng-template #emptyEngine>
<h5><span class="badge badge-secondary">High Engine<br>Temperature</span></h5>
</ng-template>
</div>
<div class = "col-md-6">
<h5 *ngIf = "isLowOilPressure; else emptyOil"><span class="badge badge-danger">Low Oil<br>Pressure</span></h5>
<h5 *ngIf = "this.generator.fault_codes.includes('fault.oil.pressure.low'); else emptyOil"><span class="badge badge-danger">Low Oil<br>Pressure</span></h5>
<ng-template #emptyOil>
<h5><span class="badge badge-secondary">Low Oil<br>Pressure</span></h5>
</ng-template>
</div>
<div class = "col-md-6">
<h5 *ngIf = "isOverspeed; else emptyOverspeed"><span class="badge badge-danger">Overspeed</span></h5>
<h5 *ngIf = "this.generator.fault_codes.includes('fault.overspeed'); else emptyOverspeed"><span class="badge badge-danger">Overspeed</span></h5>
<ng-template #emptyOverspeed>
<h5><span class="badge badge-secondary">Overspeed</span></h5>
</ng-template>
</div>
<div class = "col-md-6">
<h5 *ngIf = "isEmergencyStop; else emptyEmergency"><span class="badge badge-danger">Emergency Stop</span></h5>
<h5 *ngIf = "this.generator.fault_codes.includes('fault.emstop'); else emptyEmergency"><span class="badge badge-danger">Emergency Stop</span></h5>
<ng-template #emptyEmergency>
<h5><span class="badge badge-secondary">Emergency Stop</span></h5>
</ng-template>
</div>
<div class = "col-md-6">
<h5 *ngIf = "isLowFuel; else emptyLowFuel"><span class="badge badge-danger">Low Fuel</span></h5>
<h5 *ngIf = "this.generator.fault_codes.includes('fault.fuel.low'); else emptyLowFuel"><span class="badge badge-danger">Low Fuel</span></h5>
<ng-template #emptyLowFuel>
<h5><span class="badge badge-secondary">Low Fuel</span></h5>
</ng-template>
</div>
<div class = "col-md-6">
<h5 *ngIf = "isLowCoolant; else emptyLowCoolant"><span class="badge badge-danger">Low Coolant<br>Level/Aux</span></h5>
<h5 *ngIf = "this.generator.fault_codes.includes('fault.coolant.level.low'); else emptyLowCoolant"><span class="badge badge-danger">Low Coolant<br>Level/Aux</span></h5>
<ng-template #emptyLowCoolant>
<h5><span class="badge badge-secondary">Low Coolant<br>Level/Aux</span></h5>
</ng-template>
</div>
<div class = "col-md-6">
<h5 *ngIf = "isLowCrankingVoltage; else emptyLowCranking"><span class="badge badge-danger">Low Cranking<br>Voltage</span></h5>
<h5 *ngIf = "this.generator.fault_codes.includes('fault.crank.volt.low'); else emptyLowCranking"><span class="badge badge-danger">Low Cranking<br>Voltage</span></h5>
<ng-template #emptyLowCranking>
<h5><span class="badge badge-secondary">Low Cranking<br>Voltage</span></h5>
</ng-template>
</div>
<div class = "col-md-6">
<h5 *ngIf = "isBatteryVoltage; else emptyBatteryVolt"><span class="badge badge-danger">Battery Voltage<br>(Hi/Lo)</span></h5>
<h5 *ngIf = "this.generator.fault_codes.includes('fault.batt.volt.low') || this.generator.fault_codes.includes('fault.batt.volt.high'); else emptyBatteryVolt"><span class="badge badge-danger">Battery Voltage<br>(Hi/Lo)</span></h5>
<ng-template #emptyBatteryVolt>
<h5><span class="badge badge-secondary">Battery Voltage<br>(Hi/Lo)</span></h5>
</ng-template>
</div>
<div class = "col-md-6">
<h5 *ngIf = "isBatteryChargerFail; else emptyBatteryCharger"><span class="badge badge-danger">Battery Charger<br>Fail</span></h5>
<ng-template #emptyBatteryCharger>
<h5><span class="badge badge-secondary">Battery Charger<br>Fail</span></h5>
</ng-template>
</div>
</div>
<div class = "col-md-6">
<h5 *ngIf = "isCommonFault; else emptyCommon"><span class="badge badge-danger">Common Fault</span></h5>
<h5 *ngIf = "this.generator.fault_codes.includes('fault.common'); else emptyCommon"><span class="badge badge-danger">Common Fault</span></h5>
<ng-template #emptyCommon>
<h5><span class="badge badge-secondary">Common Fault</span></h5>
</ng-template>
Expand All @@ -178,35 +172,30 @@
<h3 class = "p-3">System Status</h3>
</div>
<div class = "col-md-6">
<h5 *ngIf = "isEPSSupplying; else emptyEPS"><span class="badge badge-success">EPS Supplying<br>Load</span></h5>
<h5 *ngIf = "this.generator.status_codes.includes('status.eps'); else emptyEPS"><span class="badge badge-success">EPS Supplying<br>Load</span></h5>
<ng-template #emptyEPS>
<h5><span class="badge badge-secondary">EPS Supplying<br>Load</span></h5>
</ng-template>
</div>
<div class = "col-md-6">
<h5 *ngIf = "isNotInAuto; else emptyAuto"><span class="badge badge-success">Not-In-Auto</span></h5>
<h5 *ngIf = "this.generator.status_codes.includes('status.notinauto'); else emptyAuto"><span class="badge badge-success">Not-In-Auto</span></h5>
<ng-template #emptyAuto>
<h5><span class="badge badge-secondary">Not-In-Auto</span></h5>
</ng-template>
</div>
<div class = "col-md-6">
<h5 *ngIf = "isSystemRunning; else emptySystem"><span class="badge badge-success">System Running</span></h5>
<h5 *ngIf = "this.generator.status_codes.includes('status.system.ready'); else emptySystem"><span class="badge badge-success">System Ready</span></h5>
<ng-template #emptySystem>
<h5><span class="badge badge-secondary">System Running</span></h5>
</ng-template>
</div>
<div class = "col-md-6">
<h5 *ngIf = "isGeneratorRunning; else emptyGenerator"><span class="badge badge-success">Generator<br>Running</span></h5>
<h5 *ngIf = "this.generator.status_codes.includes('status.gen.running'); else emptyGenerator"><span class="badge badge-success">Generator<br>Running</span></h5>
<ng-template #emptyGenerator>
<h5><span class="badge badge-secondary">Generator<br>Running</span></h5>
</ng-template>
</div>
<div class = "col-md-6">
<h5 *ngIf = "isCommunicationStatus; else emptyCommunication"><span class="badge badge-success">Communication<br>Status</span></h5>
<ng-template #emptyCommunication>
<h5><span class="badge badge-secondary">Communication<br>Status</span></h5>
</ng-template>
</div>

</div>
</div>
</div>
Expand Down
93 changes: 6 additions & 87 deletions src/app/statistics/statistics.component.ts
Expand Up @@ -53,35 +53,9 @@ export class StatisticsComponent implements OnInit {
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()
Expand All @@ -95,45 +69,8 @@ export class StatisticsComponent implements OnInit {
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() {

Expand All @@ -146,17 +83,8 @@ export class StatisticsComponent implements OnInit {

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.metric = data;
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];
Expand All @@ -176,25 +104,16 @@ export class StatisticsComponent implements OnInit {

});


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) => {
Expand Down

0 comments on commit 10aa0bb

Please sign in to comment.