|
|
@@ -34,7 +34,7 @@ export class AssetsComponent implements OnInit {
|
|
|
title = "Plantas";
|
|
|
|
|
|
// General var declarations
|
|
|
- organizationId:string;
|
|
|
+ assetID:string;
|
|
|
listAssets:any;
|
|
|
eProduced:any;
|
|
|
error:boolean;
|
|
|
@@ -51,9 +51,10 @@ export class AssetsComponent implements OnInit {
|
|
|
environmentCO2:any;
|
|
|
environmentHouse:any;
|
|
|
environmentFuel:any;
|
|
|
- isActive:[boolean,boolean,boolean,boolean]; //Activated param (chart)
|
|
|
+ isActive:[boolean,boolean,boolean,boolean,boolean,boolean,boolean,boolean]; //Activated param (chart)
|
|
|
chartActive:[boolean,boolean,boolean,boolean]
|
|
|
initialLoad: boolean = true;
|
|
|
+ metersInstalled:boolean = true;
|
|
|
|
|
|
// For daterange
|
|
|
daysLabels:any = {su: 'Dom', mo: 'Lun', tu: 'Mar', we: 'Mie', th: 'Jue', fr: 'Vie', sa: 'Sab'};
|
|
|
@@ -78,7 +79,8 @@ export class AssetsComponent implements OnInit {
|
|
|
array1: any[];
|
|
|
array2: any[];
|
|
|
array3: any[];
|
|
|
- dataSource = new MatTableDataSource(this.tableData2);
|
|
|
+ dataSource = new MatTableDataSource(this.tableData2);
|
|
|
+ dataSourcePrint = new MatTableDataSource(this.tableData2);
|
|
|
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
|
|
|
@ViewChild(MatSort, { static: true }) sort: MatSort;
|
|
|
|
|
|
@@ -107,7 +109,7 @@ export class AssetsComponent implements OnInit {
|
|
|
public datepipe: DatePipe) {
|
|
|
|
|
|
this.route.queryParams.subscribe(params => {
|
|
|
- this.organizationId = params['id'];
|
|
|
+ this.assetID = params['id'];
|
|
|
});
|
|
|
|
|
|
Swal.fire({
|
|
|
@@ -134,7 +136,8 @@ export class AssetsComponent implements OnInit {
|
|
|
}
|
|
|
|
|
|
// Initialize default 'clicked' options for chart button options
|
|
|
- this.isActive = [false, false, false, false];
|
|
|
+ this.isActive = [false, false, false, false, false, false, false, false];
|
|
|
+
|
|
|
this.chartActive = [true, false, false, false];
|
|
|
|
|
|
// Get all assets (according to user's assigned organizations)
|
|
|
@@ -143,29 +146,26 @@ export class AssetsComponent implements OnInit {
|
|
|
|
|
|
// Default values for chart
|
|
|
this.view = "month";
|
|
|
- if (this.organizationId == undefined){
|
|
|
- this.organizationId = this.listAssets[0].id;
|
|
|
- }
|
|
|
this.chart1Type = "bar";
|
|
|
+
|
|
|
+ if (this.assetID == undefined){
|
|
|
+ this.assetID = this.listAssets[0].id;
|
|
|
+ }
|
|
|
|
|
|
- // Initialize a draw chart according to the default values
|
|
|
- this.onMeasureClickRange(this.view, this.initialDate);
|
|
|
-
|
|
|
- // Api call to get the energy summary stats of all assets in the organization
|
|
|
- let energy_produced = this.logsService.getEnergySummaryByAsset(this.organizationId).subscribe(resp => {
|
|
|
- this.eProduced = resp["data"]["energy"];//results[1];
|
|
|
- this.energyDay = this.eProduced.today.total_energy_kWh || 0;
|
|
|
- this.energyWeek = this.eProduced.thisWeek.total_energy_kWh > 0 ? (this.eProduced.thisWeek.total_energy_kWh/1000).toFixed(2) : this.eProduced.thisWeek.total_energy_kWh || 0
|
|
|
- this.energyMonth = this.eProduced.thisMonth.total_energy_kWh > 0 ? (this.eProduced.thisMonth.total_energy_kWh/1000).toFixed(2) : this.eProduced.thisMonth.total_energy_kWh || 0
|
|
|
- this.energyYear = this.eProduced.lifeTime.total_energy_kWh > 0 ? (this.eProduced.lifeTime.total_energy_kWh/1000).toFixed(2) : this.eProduced.lifeTime.total_energy_kWh || 0
|
|
|
- });
|
|
|
+ let tempAsset = this.listAssets.find(object=>object.id == this.assetID);
|
|
|
|
|
|
- this.logsService.getAssetEnviromentalStats(this.organizationId).subscribe(resp => {
|
|
|
- this.environment = resp["data"]["environmentals"];
|
|
|
- this.environmentCO2 = this.environment.avoided_kg_of_co2.toFixed(2);
|
|
|
- this.environmentHouse = this.environment.number_of_homes.toFixed(0);
|
|
|
- this.environmentFuel = this.environment.number_of_crude_barrels.toFixed(2);
|
|
|
- });
|
|
|
+ if (tempAsset["meters_installed"].length > 0){
|
|
|
+ this.metersInstalled = true;
|
|
|
+ // Get energy produced given an asset
|
|
|
+ this.getEnergyProduced(this.assetID);
|
|
|
+ // Initialize a draw chart according to the default values
|
|
|
+ this.getMeasureRangeChart(this.view, this.initialDate, this.assetID);
|
|
|
+ // Get environmental data given an asset
|
|
|
+ this.getEnvironmentalData(this.assetID);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.metersInstalled = false;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}, (err) => {
|
|
|
@@ -184,7 +184,7 @@ export class AssetsComponent implements OnInit {
|
|
|
|
|
|
// Default check asset dropdown if a value is equal to an assetID
|
|
|
isSelected(){
|
|
|
- if(this.organizationId!=undefined){
|
|
|
+ if(this.assetID!=undefined){
|
|
|
return true;
|
|
|
}
|
|
|
else{
|
|
|
@@ -200,8 +200,23 @@ export class AssetsComponent implements OnInit {
|
|
|
|
|
|
// Trigger again the chart with the selected assetID
|
|
|
onChangeObj(event:any) {
|
|
|
- this.organizationId = event.target.value;
|
|
|
- this.onMeasureClickRange(this.view, this.initialDate, this.organizationId);
|
|
|
+ this.assetID = event.target.value;
|
|
|
+ let tempAsset = this.listAssets.find(object=>object.id == this.assetID);
|
|
|
+
|
|
|
+ if (tempAsset["meters_installed"].length > 0){
|
|
|
+ this.metersInstalled = true;
|
|
|
+ this.getEnergyProduced(this.assetID);
|
|
|
+ this.getMeasureRangeChart(this.view, this.initialDate, this.assetID);
|
|
|
+ this.getEnvironmentalData(this.assetID);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.metersInstalled = false;
|
|
|
+ if (this.chart1 != undefined){
|
|
|
+ this.chart1.destroy();
|
|
|
+ }
|
|
|
+ this.chart1 = undefined;
|
|
|
+ this.chart1 = new Chart('canvas', {});
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Change the date range of the chart, according to the selected view (daily, weekly, ...)
|
|
|
@@ -211,25 +226,51 @@ export class AssetsComponent implements OnInit {
|
|
|
switch (this.view)
|
|
|
{
|
|
|
case "day":
|
|
|
- this.onMeasureClickRange(this.view, endDate);
|
|
|
+ this.getMeasureRangeChart(this.view, endDate);
|
|
|
break;
|
|
|
case "week":
|
|
|
- this.onMeasureClickRange(this.view, endDate);
|
|
|
+ this.getMeasureRangeChart(this.view, endDate);
|
|
|
break;
|
|
|
case "month":
|
|
|
- this.onMeasureClickRange(this.view, endDate);
|
|
|
+ this.getMeasureRangeChart(this.view, endDate);
|
|
|
break;
|
|
|
case "year":
|
|
|
- this.onMeasureClickRange(this.view, endDate);
|
|
|
+ this.getMeasureRangeChart(this.view, endDate);
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ getEnvironmentalData(assetID: string) {
|
|
|
+ this.logsService.getAssetEnviromentalStats(assetID).subscribe(resp => {
|
|
|
+ this.environment = resp["data"]["environmentals"];
|
|
|
+ this.environmentCO2 = this.environment.avoided_kg_of_co2.toFixed(2);
|
|
|
+ this.environmentHouse = this.environment.number_of_homes.toFixed(0);
|
|
|
+ this.environmentFuel = this.environment.number_of_crude_barrels.toFixed(2);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ getEnergyProduced(assetID:string){
|
|
|
+ // Api call to get the energy summary stats of all assets in the organization
|
|
|
+ let energy_produced = this.logsService.getEnergySummaryByAsset(assetID).subscribe(resp => {
|
|
|
+ this.eProduced = resp["data"]["energy"];//results[1];
|
|
|
+ this.energyDay = this.eProduced.today.total_energy_kWh || 0;
|
|
|
+ this.energyWeek = this.eProduced.thisWeek.total_energy_kWh > 0 ? (this.eProduced.thisWeek.total_energy_kWh/1000).toFixed(2) : this.eProduced.thisWeek.total_energy_kWh || 0
|
|
|
+ this.energyMonth = this.eProduced.thisMonth.total_energy_kWh > 0 ? (this.eProduced.thisMonth.total_energy_kWh/1000).toFixed(2) : this.eProduced.thisMonth.total_energy_kWh || 0
|
|
|
+ this.energyYear = this.eProduced.lifeTime.total_energy_kWh > 0 ? (this.eProduced.lifeTime.total_energy_kWh/1000).toFixed(2) : this.eProduced.lifeTime.total_energy_kWh || 0
|
|
|
+ }, (err) => {
|
|
|
+ Swal.fire({
|
|
|
+ type: 'error',
|
|
|
+ title: 'Error en el servidor',
|
|
|
+ text: "No su pudo obtener la informacion"
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
// Draw a measure chart using chartjs, given some params, view, for daily, weekly, monthly or yearly measures;
|
|
|
// measureDate, for a date range given a view and a paramID, for an specific assetID selected in the dropdown
|
|
|
- onMeasureClickRange(view:string, measureDate?:string, paramId?:string): void {
|
|
|
+ getMeasureRangeChart(view:string, measureDate?:string, paramId?:string): void {
|
|
|
if(this.initialLoad == false){
|
|
|
Swal.fire({
|
|
|
allowOutsideClick: false,
|
|
|
@@ -268,25 +309,35 @@ export class AssetsComponent implements OnInit {
|
|
|
let interval:string;
|
|
|
switch (view)
|
|
|
{
|
|
|
+
|
|
|
case "day":
|
|
|
interval = "1D";
|
|
|
- this.isActive = [true, false, false, false];
|
|
|
+ this.isActive = [true, false, false, false, false, false, false, false];
|
|
|
break;
|
|
|
case "week":
|
|
|
interval = "7D";
|
|
|
- this.isActive = [false, true, false, false];
|
|
|
+ this.isActive = [false, true, false, false, false, false, false, false];
|
|
|
break;
|
|
|
+ case "wtd":
|
|
|
+ interval = "WTD"
|
|
|
+ this.isActive = [false, false, true, false, false, false, false, false]
|
|
|
case "month":
|
|
|
interval = "1M";
|
|
|
- this.isActive = [false, false, true, false];
|
|
|
+ this.isActive = [false, false, false, true, false, false, false, false];
|
|
|
break;
|
|
|
- case "mtd": //TO DO
|
|
|
+ case "mtd":
|
|
|
interval = "MTD";
|
|
|
+ this.isActive = [false, false, false, false, true, false, false, false];
|
|
|
+ case "3m":
|
|
|
+ interval = "3M";
|
|
|
+ this.isActive = [false, false, false, false, false, true, false, false];
|
|
|
break;
|
|
|
case "year":
|
|
|
interval = "YTD";
|
|
|
- this.isActive = [false, false, false, true];
|
|
|
- break;
|
|
|
+ this.isActive = [false, false, false, false, false, false, true, false];
|
|
|
+ case "total":
|
|
|
+ interval = "TOTAL";
|
|
|
+ this.isActive = [false, false, false, false, false, false, false, true];
|
|
|
default:
|
|
|
}
|
|
|
|
|
|
@@ -383,6 +434,9 @@ export class AssetsComponent implements OnInit {
|
|
|
this.dataSource.paginator = this.paginator;
|
|
|
this.dataSource.sort = this.sort;
|
|
|
|
|
|
+ this.dataSourcePrint.data = this.tableData2;
|
|
|
+
|
|
|
+
|
|
|
this.showTable = true;
|
|
|
this.chart1 = new Chart('canvas', {
|
|
|
type: this.chart1Type,
|
|
|
@@ -466,6 +520,7 @@ export class AssetsComponent implements OnInit {
|
|
|
printTable(){
|
|
|
printJS(
|
|
|
{ printable: 'measuresTable', type: 'html',
|
|
|
+ //properties: this.displayedColumns.join(","),
|
|
|
header: '<h3 class="report-header">Datos de la planta </h3>',
|
|
|
documentTitle: 'DENMARK - Informacion generada',
|
|
|
style: '.report-header{ color: #075D9D; font-size: 24px; }' }
|