|
@@ -4,15 +4,15 @@ import { Label, BaseChartDirective } from 'ng2-charts';
|
|
|
import { MeasuresService } from 'src/app/services/measures.service';
|
|
import { MeasuresService } from 'src/app/services/measures.service';
|
|
|
import { PlantsService } from 'src/app/services/plants.service';
|
|
import { PlantsService } from 'src/app/services/plants.service';
|
|
|
import { LogsService } from 'src/app/services/logs.service';
|
|
import { LogsService } from 'src/app/services/logs.service';
|
|
|
-
|
|
|
|
|
import { OrganizationsService } from '@app/services/organizations.service';
|
|
import { OrganizationsService } from '@app/services/organizations.service';
|
|
|
|
|
+
|
|
|
import { ActivatedRoute } from '@angular/router';
|
|
import { ActivatedRoute } from '@angular/router';
|
|
|
import { MatPaginator } from '@angular/material/paginator';
|
|
import { MatPaginator } from '@angular/material/paginator';
|
|
|
import { MatSort } from '@angular/material/sort';
|
|
import { MatSort } from '@angular/material/sort';
|
|
|
import { MatTableDataSource } from '@angular/material/table';
|
|
import { MatTableDataSource } from '@angular/material/table';
|
|
|
import Swal from 'sweetalert2';
|
|
import Swal from 'sweetalert2';
|
|
|
import { HttpClient } from '@angular/common/http';
|
|
import { HttpClient } from '@angular/common/http';
|
|
|
-import { formatDate } from '@angular/common';
|
|
|
|
|
|
|
+import { formatDate, DatePipe } from '@angular/common';
|
|
|
|
|
|
|
|
import {AngularMyDatePickerDirective,IAngularMyDpOptions, IMyDateModel} from 'angular-mydatepicker';
|
|
import {AngularMyDatePickerDirective,IAngularMyDpOptions, IMyDateModel} from 'angular-mydatepicker';
|
|
|
import printJS from 'print-js'
|
|
import printJS from 'print-js'
|
|
@@ -34,7 +34,7 @@ export class AssetsComponent implements OnInit {
|
|
|
title = "Plantas";
|
|
title = "Plantas";
|
|
|
|
|
|
|
|
// General var declarations
|
|
// General var declarations
|
|
|
- organizationId:string;
|
|
|
|
|
|
|
+ assetID:string;
|
|
|
listAssets:any;
|
|
listAssets:any;
|
|
|
eProduced:any;
|
|
eProduced:any;
|
|
|
error:boolean;
|
|
error:boolean;
|
|
@@ -51,9 +51,10 @@ export class AssetsComponent implements OnInit {
|
|
|
environmentCO2:any;
|
|
environmentCO2:any;
|
|
|
environmentHouse:any;
|
|
environmentHouse:any;
|
|
|
environmentFuel:any;
|
|
environmentFuel:any;
|
|
|
- isActive:[boolean,boolean,boolean,boolean]; //Activated param (chart)
|
|
|
|
|
|
|
+ isActive:[boolean,boolean,boolean,boolean,boolean,boolean,boolean,boolean,boolean]; //Activated param (chart)
|
|
|
chartActive:[boolean,boolean,boolean,boolean]
|
|
chartActive:[boolean,boolean,boolean,boolean]
|
|
|
initialLoad: boolean = true;
|
|
initialLoad: boolean = true;
|
|
|
|
|
+ metersInstalled:boolean = true;
|
|
|
|
|
|
|
|
// For daterange
|
|
// For daterange
|
|
|
daysLabels:any = {su: 'Dom', mo: 'Lun', tu: 'Mar', we: 'Mie', th: 'Jue', fr: 'Vie', sa: 'Sab'};
|
|
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[];
|
|
array1: any[];
|
|
|
array2: any[];
|
|
array2: any[];
|
|
|
array3: 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(MatPaginator, { static: true }) paginator: MatPaginator;
|
|
|
@ViewChild(MatSort, { static: true }) sort: MatSort;
|
|
@ViewChild(MatSort, { static: true }) sort: MatSort;
|
|
|
|
|
|
|
@@ -94,6 +96,11 @@ export class AssetsComponent implements OnInit {
|
|
|
public barChartOptions: ChartOptions;
|
|
public barChartOptions: ChartOptions;
|
|
|
public barChartData: ChartDataSets[];
|
|
public barChartData: ChartDataSets[];
|
|
|
@ViewChild("baseChart",null) chart: BaseChartDirective;
|
|
@ViewChild("baseChart",null) chart: BaseChartDirective;
|
|
|
|
|
+ city: any;
|
|
|
|
|
+ total_savings: any;
|
|
|
|
|
+ last_day_savings: number;
|
|
|
|
|
+ savings_logs: any;
|
|
|
|
|
+ savings_logs_data = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get selected asset
|
|
// Get selected asset
|
|
@@ -103,10 +110,11 @@ export class AssetsComponent implements OnInit {
|
|
|
private plantsService: PlantsService,
|
|
private plantsService: PlantsService,
|
|
|
private http: HttpClient,
|
|
private http: HttpClient,
|
|
|
private logsService: LogsService,
|
|
private logsService: LogsService,
|
|
|
- private measService: MeasuresService) {
|
|
|
|
|
|
|
+ private measService: MeasuresService,
|
|
|
|
|
+ public datepipe: DatePipe) {
|
|
|
|
|
|
|
|
this.route.queryParams.subscribe(params => {
|
|
this.route.queryParams.subscribe(params => {
|
|
|
- this.organizationId = params['id'];
|
|
|
|
|
|
|
+ this.assetID = params['id'];
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
Swal.fire({
|
|
Swal.fire({
|
|
@@ -119,7 +127,7 @@ export class AssetsComponent implements OnInit {
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
ngOnInit() {
|
|
|
// Default date is today and set it on a string var and initialize dateRange plugin
|
|
// Default date is today and set it on a string var and initialize dateRange plugin
|
|
|
- this.initialDate = new Date().toISOString().slice(0, 10);
|
|
|
|
|
|
|
+ this.initialDate = this.datepipe.transform(new Date(), 'yyyy-MM-dd')//.toISOString().slice(0, 10);
|
|
|
if (this.myDateInit) {
|
|
if (this.myDateInit) {
|
|
|
let begin: Date = new Date();
|
|
let begin: Date = new Date();
|
|
|
this.model = {
|
|
this.model = {
|
|
@@ -133,7 +141,8 @@ export class AssetsComponent implements OnInit {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Initialize default 'clicked' options for chart button options
|
|
// Initialize default 'clicked' options for chart button options
|
|
|
- this.isActive = [false, false, false, false];
|
|
|
|
|
|
|
+ this.isActive = [false, false, false, false, false, false, false, false, false];
|
|
|
|
|
+
|
|
|
this.chartActive = [true, false, false, false];
|
|
this.chartActive = [true, false, false, false];
|
|
|
|
|
|
|
|
// Get all assets (according to user's assigned organizations)
|
|
// Get all assets (according to user's assigned organizations)
|
|
@@ -142,36 +151,42 @@ export class AssetsComponent implements OnInit {
|
|
|
|
|
|
|
|
// Default values for chart
|
|
// Default values for chart
|
|
|
this.view = "month";
|
|
this.view = "month";
|
|
|
- if (this.organizationId == undefined){
|
|
|
|
|
- this.organizationId = this.listAssets[0].id;
|
|
|
|
|
- }
|
|
|
|
|
this.chart1Type = "bar";
|
|
this.chart1Type = "bar";
|
|
|
|
|
+
|
|
|
|
|
+ if (this.assetID == undefined){
|
|
|
|
|
+ this.assetID = this.listAssets[0].id;
|
|
|
|
|
+ this.city = this.listAssets[0].city;
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ this.city = this.listAssets.find(object=>object.id == this.assetID).city;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // Initialize a draw chart according to the default values
|
|
|
|
|
- this.onMeasureClickRange(this.view, this.initialDate);
|
|
|
|
|
|
|
+ let tempAsset = this.listAssets.find(object=>object.id == this.assetID);
|
|
|
|
|
|
|
|
- // 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
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ if (tempAsset["meters_installed"].length > 0){
|
|
|
|
|
+ this.metersInstalled = true;
|
|
|
|
|
|
|
|
- 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);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // Get savings produced by an asset
|
|
|
|
|
+ this.getSavings(this.assetID);
|
|
|
|
|
+
|
|
|
|
|
+ // 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) => {
|
|
}, (err) => {
|
|
|
Swal.fire({
|
|
Swal.fire({
|
|
|
type: 'error',
|
|
type: 'error',
|
|
|
title: 'Error en el servidor',
|
|
title: 'Error en el servidor',
|
|
|
- text: "No su pudo obtener la informacion"
|
|
|
|
|
|
|
+ text: err.message
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -180,10 +195,10 @@ export class AssetsComponent implements OnInit {
|
|
|
Swal.close();
|
|
Swal.close();
|
|
|
}, 2700);
|
|
}, 2700);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// Default check asset dropdown if a value is equal to an assetID
|
|
// Default check asset dropdown if a value is equal to an assetID
|
|
|
isSelected(){
|
|
isSelected(){
|
|
|
- if(this.organizationId!=undefined){
|
|
|
|
|
|
|
+ if(this.assetID!=undefined){
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
else{
|
|
else{
|
|
@@ -199,36 +214,75 @@ export class AssetsComponent implements OnInit {
|
|
|
|
|
|
|
|
// Trigger again the chart with the selected assetID
|
|
// Trigger again the chart with the selected assetID
|
|
|
onChangeObj(event:any) {
|
|
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);
|
|
|
|
|
+ this.city = tempAsset["city"];
|
|
|
|
|
+
|
|
|
|
|
+ if (tempAsset["meters_installed"].length > 0){
|
|
|
|
|
+ this.metersInstalled = true;
|
|
|
|
|
+ this.getSavings(this.assetID);
|
|
|
|
|
+ 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, ...)
|
|
// Change the date range of the chart, according to the selected view (daily, weekly, ...)
|
|
|
onDateChanged(event: IMyDateModel) {
|
|
onDateChanged(event: IMyDateModel) {
|
|
|
let endDate = `${event.singleDate.date.year}-${event.singleDate.date.month}-${event.singleDate.date.day}`;
|
|
let endDate = `${event.singleDate.date.year}-${event.singleDate.date.month}-${event.singleDate.date.day}`;
|
|
|
this.initialDate = endDate;
|
|
this.initialDate = endDate;
|
|
|
- switch (this.view)
|
|
|
|
|
- {
|
|
|
|
|
- case "day":
|
|
|
|
|
- this.onMeasureClickRange(this.view, endDate);
|
|
|
|
|
- break;
|
|
|
|
|
- case "week":
|
|
|
|
|
- this.onMeasureClickRange(this.view, endDate);
|
|
|
|
|
- break;
|
|
|
|
|
- case "month":
|
|
|
|
|
- this.onMeasureClickRange(this.view, endDate);
|
|
|
|
|
- break;
|
|
|
|
|
- case "year":
|
|
|
|
|
- this.onMeasureClickRange(this.view, endDate);
|
|
|
|
|
- break;
|
|
|
|
|
- default:
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ this.getMeasureRangeChart(this.view, endDate);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ getSavings(assetID: string) {
|
|
|
|
|
+ this.plantsService.getAssetSavings(this.assetID).subscribe( res => {
|
|
|
|
|
+ this.total_savings = res["data"]["ahorro_total"];
|
|
|
|
|
+ this.total_savings = +this.total_savings > 10000 ? (+this.total_savings / 1000).toFixed(3) + "k" : +this.total_savings.toFixed(2) || 0;
|
|
|
|
|
+ this.last_day_savings = +res["data"]["ahorro_ultimas_24_horas"].toFixed(2) || 0;
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ 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;
|
|
// 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
|
|
// 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){
|
|
if(this.initialLoad == false){
|
|
|
Swal.fire({
|
|
Swal.fire({
|
|
|
allowOutsideClick: false,
|
|
allowOutsideClick: false,
|
|
@@ -267,167 +321,215 @@ export class AssetsComponent implements OnInit {
|
|
|
let interval:string;
|
|
let interval:string;
|
|
|
switch (view)
|
|
switch (view)
|
|
|
{
|
|
{
|
|
|
|
|
+
|
|
|
case "day":
|
|
case "day":
|
|
|
interval = "1D";
|
|
interval = "1D";
|
|
|
- this.isActive = [true, false, false, false];
|
|
|
|
|
|
|
+ this.isActive = [true, false, false, false, false, false, false, false, false];
|
|
|
break;
|
|
break;
|
|
|
case "week":
|
|
case "week":
|
|
|
interval = "7D";
|
|
interval = "7D";
|
|
|
- this.isActive = [false, true, false, false];
|
|
|
|
|
|
|
+ this.isActive = [false, true, false, false, false, false, false, false, false];
|
|
|
break;
|
|
break;
|
|
|
|
|
+ case "WTD":
|
|
|
|
|
+ interval = "WTD"
|
|
|
|
|
+ this.isActive = [false, false, true, false, false, false, false, false, false];
|
|
|
|
|
+ break;
|
|
|
case "month":
|
|
case "month":
|
|
|
interval = "1M";
|
|
interval = "1M";
|
|
|
- this.isActive = [false, false, true, false];
|
|
|
|
|
|
|
+ this.isActive = [false, false, false, true, false, false, false, false, false];
|
|
|
break;
|
|
break;
|
|
|
- case "mtd": //TO DO
|
|
|
|
|
|
|
+ case "MTD":
|
|
|
interval = "MTD";
|
|
interval = "MTD";
|
|
|
|
|
+ this.isActive = [false, false, false, false, true, false, false, false, false];
|
|
|
break;
|
|
break;
|
|
|
- case "year":
|
|
|
|
|
|
|
+ case "3m":
|
|
|
|
|
+ interval = "3M";
|
|
|
|
|
+ this.isActive = [false, false, false, false, false, true, false, false, false];
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "12m":
|
|
|
|
|
+ interval = "1Y";
|
|
|
|
|
+ this.isActive = [false, false, false, false, false, false, true, false, false];
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "YTD":
|
|
|
interval = "YTD";
|
|
interval = "YTD";
|
|
|
- this.isActive = [false, false, false, true];
|
|
|
|
|
|
|
+ this.isActive = [false, false, false, false, false, false, false, true, false];
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "total":
|
|
|
|
|
+ interval = "TOTAL";
|
|
|
|
|
+ this.isActive = [false, false, false, false, false, false, false, false, true];
|
|
|
break;
|
|
break;
|
|
|
default:
|
|
default:
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Get the measures according to the meters, given the params required
|
|
|
|
|
- this.logsService.getEnergyProducedByParams(assetId,interval,dateRange).toPromise()
|
|
|
|
|
- .then((data: any) => {
|
|
|
|
|
- this.metersData = [];
|
|
|
|
|
- this.metersKeys = Object.keys(data["data"]["dataset"]);
|
|
|
|
|
-
|
|
|
|
|
- // Get all the values according to each index (meter)
|
|
|
|
|
- this.metersValues = Object.values(data["data"]["dataset"]);
|
|
|
|
|
-
|
|
|
|
|
- /// Get the keys of those values
|
|
|
|
|
- let meterKeys2 = Object.keys(this.metersValues);
|
|
|
|
|
- this.displayedColumns= [];
|
|
|
|
|
- this.tableData = [];
|
|
|
|
|
-
|
|
|
|
|
- // The chart data object requires certain ordered params, so we itirate the returned object from the API call,
|
|
|
|
|
- // and build the new object with the required/needed values
|
|
|
|
|
- for (let prop in meterKeys2) {
|
|
|
|
|
- //let label = localStorage.getItem("email") == "inverlec@grupomerelec.com" ? `INVERLEC ${prop}` : this.metersValues[prop]["label"];
|
|
|
|
|
- let label = this.metersValues[prop]["label"];
|
|
|
|
|
- let measure_values = Object.values(this.metersValues[prop]["data"].map(obj => obj.total_energy_kWh).reverse())
|
|
|
|
|
- this.metersData.push({"label": label, backgroundColor: this.barChartColors[prop], data: measure_values, borderColor: this.borderChartColors[prop] });
|
|
|
|
|
- this.tableData.push({headers: label+" [kWh]", dataValues: measure_values})
|
|
|
|
|
|
|
+ this.logsService.getEnergySavingsProducedByAsset(assetId, interval, dateRange).toPromise()
|
|
|
|
|
+ .then((res: any)=>{
|
|
|
|
|
+ this.savings_logs = undefined;
|
|
|
|
|
+ this.savings_logs_data = [];
|
|
|
|
|
+ this.savings_logs = res["data"]["dataset"];
|
|
|
|
|
+ let savingsKeys = Object.keys(this.savings_logs);
|
|
|
|
|
+ for (let key in savingsKeys) {
|
|
|
|
|
+ let savingDate = savingsKeys[key];
|
|
|
|
|
+ this.savings_logs_data.push(this.savings_logs[savingDate]["ahorro"]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Initialization of arrays for the table view of the measure values
|
|
|
|
|
- this.array1 = this.array2 = this.array3 = [];
|
|
|
|
|
-
|
|
|
|
|
- // Loop to build an object that contains the date and each meter value from a certain asset
|
|
|
|
|
- // This object is required to build the datatable
|
|
|
|
|
- for (let prop in meterKeys2) {
|
|
|
|
|
- this.array2 = [];
|
|
|
|
|
- //let label = localStorage.getItem("email") == "inverlec@grupomerelec.com" ? `INVERLEC ${prop}` : this.metersValues[prop]["label"];
|
|
|
|
|
- let quantity = Object.keys(this.metersValues[0]["data"]);
|
|
|
|
|
- let mvalues = Object.values(this.metersValues[prop]["data"].map(obj => obj).reverse())
|
|
|
|
|
|
|
+ // Get the measures according to the meters, given the params required
|
|
|
|
|
+ this.logsService.getEnergyProducedByParams(assetId,interval,dateRange).toPromise()
|
|
|
|
|
+ .then((data: any) => {
|
|
|
|
|
+ this.metersData = [];
|
|
|
|
|
+ this.metersKeys = Object.keys(data["data"]["dataset"]);
|
|
|
|
|
|
|
|
- for (let prop2 in quantity){
|
|
|
|
|
- // Date insertion
|
|
|
|
|
- this.array3 = [];
|
|
|
|
|
- let columnname = `medidor${prop}`;
|
|
|
|
|
-
|
|
|
|
|
- if (+prop == 0 && mvalues[prop2] != undefined){
|
|
|
|
|
- let dateT = this.getDateWithFormat(this.view, mvalues[prop2]["dateMax"])
|
|
|
|
|
- this.array3.push(dateT);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // Get all the values according to each index (meter)
|
|
|
|
|
+ this.metersValues = Object.values(data["data"]["dataset"]);
|
|
|
|
|
+
|
|
|
|
|
+ /// Get the keys of those values
|
|
|
|
|
+ let meterKeys2 = Object.keys(this.metersValues);
|
|
|
|
|
+ this.displayedColumns= [];
|
|
|
|
|
+ this.tableData = [];
|
|
|
|
|
+ this.metersData.push({ "label": "AHORRO [US$]", data: this.savings_logs_data.reverse(), type: "line", backgroundColor: "#e57272", borderColor: "#ce2525", borderWidth: 2, yAxisID: 'y-axis-ahorro', fill: false})
|
|
|
|
|
+ // The chart data object requires certain ordered params, so we itirate the returned object from the API call,
|
|
|
|
|
+ // and build the new object with the required/needed values
|
|
|
|
|
+ for (let prop in meterKeys2) {
|
|
|
|
|
+ //let label = localStorage.getItem("email") == "inverlec@grupomerelec.com" ? `INVERLEC ${prop}` : this.metersValues[prop]["label"];
|
|
|
|
|
+ let label = this.metersValues[prop]["label"]+" [kWh]";
|
|
|
|
|
+ let measure_values = Object.values(this.metersValues[prop]["data"].map(obj => obj.total_energy_kWh).reverse());
|
|
|
|
|
+ this.metersData.push({"label": label, backgroundColor: this.barChartColors[prop], data: measure_values, borderColor: this.borderChartColors[prop] });
|
|
|
|
|
+ this.tableData.push({headers: label+" [kWh]", dataValues: measure_values});
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // this.metersData.push({ "label": "Ahorro", data: [10,30,30,40,30,20,15,25,30,35], type: "line", backgroundColor: "#e57272", borderColor: "#ce2525", borderWidth: 2, yAxisID: 'y-axis-ahorro',})
|
|
|
|
|
+ // Initialization of arrays for the table view of the measure values
|
|
|
|
|
+ this.array1 = this.array2 = this.array3 = [];
|
|
|
|
|
+
|
|
|
|
|
+ // Loop to build an object that contains the date and each meter value from a certain asset
|
|
|
|
|
+ // This object is required to build the datatable
|
|
|
|
|
+ for (let prop in meterKeys2) {
|
|
|
|
|
+ this.array2 = [];
|
|
|
|
|
+ //let label = localStorage.getItem("email") == "inverlec@grupomerelec.com" ? `INVERLEC ${prop}` : this.metersValues[prop]["label"];
|
|
|
|
|
+ let quantity = Object.keys(this.metersValues[0]["data"]);
|
|
|
|
|
+ let mvalues = Object.values(this.metersValues[prop]["data"].map(obj => obj).reverse())
|
|
|
|
|
|
|
|
- if (mvalues[prop2] != undefined) {
|
|
|
|
|
- this.array3.push(mvalues[prop2]["total_energy_kWh"]);
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- this.array3.push(0)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (+prop == 0){
|
|
|
|
|
- this.array2.push(this.array3)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ for (let prop2 in quantity){
|
|
|
|
|
+ // Date insertion
|
|
|
|
|
+ this.array3 = [];
|
|
|
|
|
+ let columnname = `medidor${prop}`;
|
|
|
|
|
|
|
|
- if (+prop != 0) {
|
|
|
|
|
- this.array1[prop2].push(this.array3[0]);
|
|
|
|
|
|
|
+ if (+prop == 0 && mvalues[prop2] != undefined){
|
|
|
|
|
+ let dateT = this.getDateWithFormat(this.view, mvalues[prop2]["dateMax"])
|
|
|
|
|
+ this.array3.push(dateT);
|
|
|
|
|
+ this.array3.push(this.savings_logs_data[prop2]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (mvalues[prop2] != undefined) {
|
|
|
|
|
+ this.array3.push(mvalues[prop2]["total_energy_kWh"]);
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ this.array3.push(0)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (+prop == 0){
|
|
|
|
|
+ this.array2.push(this.array3)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (+prop != 0) {
|
|
|
|
|
+ this.array1[prop2].push(this.array3[0]);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ if (+prop == 0){
|
|
|
|
|
+ this.array1 = (this.array2)
|
|
|
|
|
+ //this.array1 = [].concat.apply([], this.array1)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- if (+prop == 0){
|
|
|
|
|
- this.array1 = (this.array2)
|
|
|
|
|
- //this.array1 = [].concat.apply([], this.array1)
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- // According to the selected interval in the option buttons of the chart, the date is given an specific format
|
|
|
|
|
- switch (view){
|
|
|
|
|
- case "day":
|
|
|
|
|
- this.barChartLabels = this.metersValues[0]["data"].map(obj => formatDate(obj.dateMax, 'HH:mm ','es-Es','-0600')).reverse();
|
|
|
|
|
- break;
|
|
|
|
|
- case 'week':
|
|
|
|
|
- this.barChartLabels = this.metersValues[0]["data"].map(obj => formatDate(obj.dateMax, 'EEEE dd','es-Es','-0600')).reverse();
|
|
|
|
|
- break;
|
|
|
|
|
- case "year":
|
|
|
|
|
- this.barChartLabels = this.metersValues[0]["data"].map(obj => formatDate(obj.dateMax, 'MM/yyyy','es-Es','-0600')).reverse();
|
|
|
|
|
- break;
|
|
|
|
|
- default:
|
|
|
|
|
- this.barChartLabels = this.metersValues[0]["data"].map(obj => formatDate(obj.dateMax, 'dd/MM','es-Es','-0600')).reverse();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // According to the selected interval in the option buttons of the chart, the date is given an specific format
|
|
|
|
|
+ switch (view){
|
|
|
|
|
+ case "day":
|
|
|
|
|
+ this.barChartLabels = this.metersValues[0]["data"].map(obj => formatDate(obj.dateMax, 'HH:mm ','es-Es','-0600')).reverse();
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 'week':
|
|
|
|
|
+ this.barChartLabels = this.metersValues[0]["data"].map(obj => formatDate(obj.dateMax, 'EEEE dd','es-Es','-0600')).reverse();
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "year":
|
|
|
|
|
+ this.barChartLabels = this.metersValues[0]["data"].map(obj => formatDate(obj.dateMax, 'MM/yyyy','es-Es','-0600')).reverse();
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ this.barChartLabels = this.metersValues[0]["data"].map(obj => formatDate(obj.dateMax, 'dd/MM','es-Es','-0600')).reverse();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // Push the values to the chart object
|
|
|
|
|
- this.tableData.push({headers: "Fecha/Hora", dataValues: this.barChartLabels})
|
|
|
|
|
- this.tableData.reverse()
|
|
|
|
|
- for( let v in Object.keys(this.tableData)){
|
|
|
|
|
- this.displayedColumns.push(this.tableData[v]["headers"]);
|
|
|
|
|
- }
|
|
|
|
|
- this.tableData2 = this.array1;
|
|
|
|
|
-
|
|
|
|
|
- this.dataSource.data = this.tableData2;
|
|
|
|
|
- this.dataSource.paginator = this.paginator;
|
|
|
|
|
- this.dataSource.sort = this.sort;
|
|
|
|
|
-
|
|
|
|
|
- this.showTable = true;
|
|
|
|
|
- this.chart1 = new Chart('canvas', {
|
|
|
|
|
- type: this.chart1Type,
|
|
|
|
|
- options: {
|
|
|
|
|
- title: {
|
|
|
|
|
- display: true,
|
|
|
|
|
- },
|
|
|
|
|
- tooltips: {
|
|
|
|
|
- mode: 'index',
|
|
|
|
|
- callbacks: {
|
|
|
|
|
- // Get the total of the energy produced in every point and show it in the hover tooltip
|
|
|
|
|
- label: function (tooltipItem, data) {
|
|
|
|
|
- var label = data.datasets[tooltipItem.datasetIndex].label || '';
|
|
|
|
|
- var value = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
|
|
|
|
|
- var total = 0;
|
|
|
|
|
-
|
|
|
|
|
- for (var i = 0; i < data.datasets.length; i++)
|
|
|
|
|
- total += +data.datasets[i].data[tooltipItem.index];
|
|
|
|
|
-
|
|
|
|
|
- if (tooltipItem.datasetIndex !== data.datasets.length - 1) {
|
|
|
|
|
- return label + " : " + value;
|
|
|
|
|
|
|
+ // Push the values to the chart object
|
|
|
|
|
+ this.tableData.push({headers: "Ahorro[US$]"});
|
|
|
|
|
+ this.tableData.push({headers: "Fecha/Hora", dataValues: this.barChartLabels});
|
|
|
|
|
+ this.tableData.reverse()
|
|
|
|
|
+ for( let v in Object.keys(this.tableData)){
|
|
|
|
|
+ this.displayedColumns.push(this.tableData[v]["headers"]);
|
|
|
|
|
+ }
|
|
|
|
|
+ this.tableData2 = this.array1;
|
|
|
|
|
+
|
|
|
|
|
+ this.dataSource.data = this.tableData2;
|
|
|
|
|
+ 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,
|
|
|
|
|
+ options: {
|
|
|
|
|
+ title: {
|
|
|
|
|
+ display: true,
|
|
|
|
|
+ },
|
|
|
|
|
+ tooltips: {
|
|
|
|
|
+ mode: 'index',
|
|
|
|
|
+ callbacks: {
|
|
|
|
|
+ // Get the total of the energy produced in every point and show it in the hover tooltip
|
|
|
|
|
+ label: function (tooltipItem, data) {
|
|
|
|
|
+ var label = data.datasets[tooltipItem.datasetIndex].label || '';
|
|
|
|
|
+ var value = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
|
|
|
|
|
+ var total = 0;
|
|
|
|
|
+
|
|
|
|
|
+ for (var i = 1; i < data.datasets.length; i++)
|
|
|
|
|
+ total += +data.datasets[i].data[tooltipItem.index];
|
|
|
|
|
+
|
|
|
|
|
+ if (tooltipItem.datasetIndex !== data.datasets.length - 1) {
|
|
|
|
|
+ return label + " : " + value;
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ return [label + " : " + value, "TOTAL[kWh] : " + Math.round(total)];
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- else {
|
|
|
|
|
- return [label + " : " + value, "TOTAL : " + Math.round(total)];
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ responsive: true,
|
|
|
|
|
+ maintainAspectRatio: false,
|
|
|
|
|
+ scales: {
|
|
|
|
|
+ xAxes: [{
|
|
|
|
|
+ stacked: true,
|
|
|
|
|
+ barPercentage: 0.7
|
|
|
|
|
+ }],
|
|
|
|
|
+ yAxes: [
|
|
|
|
|
+ {
|
|
|
|
|
+ stacked: true,
|
|
|
|
|
+ position: "left"
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ display: true,
|
|
|
|
|
+ stacked: true,
|
|
|
|
|
+ position: 'right',
|
|
|
|
|
+ id: 'y-axis-ahorro',
|
|
|
|
|
+ gridLines: {
|
|
|
|
|
+ drawOnChartArea: false
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ ]
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
- responsive: true,
|
|
|
|
|
- maintainAspectRatio: false,
|
|
|
|
|
- scales: {
|
|
|
|
|
- xAxes: [{
|
|
|
|
|
- stacked: true,
|
|
|
|
|
- barPercentage: 0.7
|
|
|
|
|
- }],
|
|
|
|
|
- yAxes: [{
|
|
|
|
|
- stacked: true
|
|
|
|
|
- }]
|
|
|
|
|
|
|
+
|
|
|
|
|
+ data: {
|
|
|
|
|
+ labels: this.barChartLabels,
|
|
|
|
|
+ datasets: this.metersData,
|
|
|
}
|
|
}
|
|
|
- },
|
|
|
|
|
- data: {
|
|
|
|
|
- labels: this.barChartLabels,
|
|
|
|
|
- datasets: this.metersData,
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ this.chartjs = true;
|
|
|
});
|
|
});
|
|
|
- this.chartjs = true;
|
|
|
|
|
});
|
|
});
|
|
|
setTimeout(()=>{
|
|
setTimeout(()=>{
|
|
|
Swal.close();
|
|
Swal.close();
|
|
@@ -465,6 +567,7 @@ export class AssetsComponent implements OnInit {
|
|
|
printTable(){
|
|
printTable(){
|
|
|
printJS(
|
|
printJS(
|
|
|
{ printable: 'measuresTable', type: 'html',
|
|
{ printable: 'measuresTable', type: 'html',
|
|
|
|
|
+ //properties: this.displayedColumns.join(","),
|
|
|
header: '<h3 class="report-header">Datos de la planta </h3>',
|
|
header: '<h3 class="report-header">Datos de la planta </h3>',
|
|
|
documentTitle: 'DENMARK - Informacion generada',
|
|
documentTitle: 'DENMARK - Informacion generada',
|
|
|
style: '.report-header{ color: #075D9D; font-size: 24px; }' }
|
|
style: '.report-header{ color: #075D9D; font-size: 24px; }' }
|
|
@@ -534,9 +637,21 @@ export class AssetsComponent implements OnInit {
|
|
|
stacked: true,
|
|
stacked: true,
|
|
|
barPercentage: 0.7
|
|
barPercentage: 0.7
|
|
|
}],
|
|
}],
|
|
|
- yAxes: [{
|
|
|
|
|
- stacked: true
|
|
|
|
|
- }]
|
|
|
|
|
|
|
+ yAxes: [
|
|
|
|
|
+ {
|
|
|
|
|
+ stacked: true,
|
|
|
|
|
+ position: "left"
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ display: true,
|
|
|
|
|
+ stacked: false,
|
|
|
|
|
+ position: 'right',
|
|
|
|
|
+ id: 'y-axis-ahorro',
|
|
|
|
|
+ gridLines: {
|
|
|
|
|
+ drawOnChartArea: false
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ ]
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
data: {
|
|
data: {
|