|
@@ -19,6 +19,7 @@ import { environment } from '@environments/environment';
|
|
|
import { HttpClient } from '@angular/common/http';
|
|
import { HttpClient } from '@angular/common/http';
|
|
|
import { formatDate } from '@angular/common';
|
|
import { formatDate } from '@angular/common';
|
|
|
|
|
|
|
|
|
|
+import {AngularMyDatePickerDirective,IAngularMyDpOptions, IMyDateModel} from 'angular-mydatepicker';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -44,6 +45,25 @@ export class AssetsComponent implements OnInit {
|
|
|
chart1: Chart;
|
|
chart1: Chart;
|
|
|
metersKeys:any;
|
|
metersKeys:any;
|
|
|
metersValues:any;
|
|
metersValues:any;
|
|
|
|
|
+ view:string;
|
|
|
|
|
+
|
|
|
|
|
+ //For daterange
|
|
|
|
|
+ daysLabels:any = {su: 'Dom', mo: 'Lun', tu: 'Mar', we: 'Mie', th: 'Jue', fr: 'Vie', sa: 'Sab'};
|
|
|
|
|
+ monthsLabels:any = { 1: 'Ene', 2: 'Feb', 3: 'Mar', 4: 'Abr', 5: 'May', 6: 'Jun', 7: 'Jul', 8: 'Ago', 9: 'Sep', 10: 'Oct', 11: 'Nov', 12: 'Dic' };
|
|
|
|
|
+ todayBtnTxt:string = 'Hoy';
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ myDpOptions: IAngularMyDpOptions = {
|
|
|
|
|
+ dateRange: true,
|
|
|
|
|
+ dateFormat: 'dd/mm/yyyy',
|
|
|
|
|
+ dayLabels: this.daysLabels,
|
|
|
|
|
+ monthLabels: this.monthsLabels,
|
|
|
|
|
+ // other options are here...
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ myDateInit: boolean = true;
|
|
|
|
|
+ model: IMyDateModel = null;
|
|
|
|
|
+
|
|
|
// For chartjs
|
|
// For chartjs
|
|
|
tsLabels: any[];
|
|
tsLabels: any[];
|
|
|
polarLabels: any[];
|
|
polarLabels: any[];
|
|
@@ -97,6 +117,10 @@ export class AssetsComponent implements OnInit {
|
|
|
else {
|
|
else {
|
|
|
|
|
|
|
|
this.listAssets = results[0]["assets"];
|
|
this.listAssets = results[0]["assets"];
|
|
|
|
|
+ this.route.queryParams.subscribe(params => {
|
|
|
|
|
+ this.organizationId = params['id'];
|
|
|
|
|
+ console.log(this.organizationId); // Print the parameter to the console.
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
this.listEnergyProduced = results[1];
|
|
this.listEnergyProduced = results[1];
|
|
@@ -108,79 +132,117 @@ export class AssetsComponent implements OnInit {
|
|
|
text: "No su pudo obtener la informacion"
|
|
text: "No su pudo obtener la informacion"
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
+ this.view = "month";
|
|
|
|
|
+
|
|
|
|
|
+ this.isActive = [false, false, true, false];
|
|
|
|
|
+ this.logsService.getEnergyProducedByMonth().toPromise()
|
|
|
|
|
+ .then((data: any) => {
|
|
|
|
|
+ // Get all the keys(each meter name) of the returned promise
|
|
|
|
|
+ this.metersKeys = Object.keys(data["1M"]);
|
|
|
|
|
+
|
|
|
|
|
+ // Get all the values according to each index (meter)
|
|
|
|
|
+ this.metersValues = Object.values(data["1M"]).map(sub => sub);
|
|
|
|
|
+ let meterKeys2 = Object.keys(this.metersValues);
|
|
|
|
|
+
|
|
|
|
|
+ // Re-Initialize Json object
|
|
|
|
|
+ this.metersData = [];
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- this.isActive = [false, false, true, false];
|
|
|
|
|
- this.logsService.getEnergyProducedByMonth().toPromise()
|
|
|
|
|
- .then((data: any) => {
|
|
|
|
|
- // Get all the keys(each meter name) of the returned promise
|
|
|
|
|
- this.metersKeys = Object.keys(data["1M"]);
|
|
|
|
|
-
|
|
|
|
|
- // Get all the values according to each index (meter)
|
|
|
|
|
- this.metersValues = Object.values(data["1M"]).map(sub => sub);
|
|
|
|
|
- let meterKeys2 = Object.keys(this.metersValues);
|
|
|
|
|
-
|
|
|
|
|
- // Re-Initialize Json object
|
|
|
|
|
- this.metersData = [];
|
|
|
|
|
-
|
|
|
|
|
- // Json object construction for passing its values to the chartjs datasets according to its requirements
|
|
|
|
|
- for (let prop in meterKeys2) {
|
|
|
|
|
- let label = localStorage.getItem("email") == "inverlec@grupomerelec.com" ? `INVERLEC ${prop}` : this.metersKeys[prop];
|
|
|
|
|
- this.metersData.push({"label": label, backgroundColor: this.barChartColors[prop], data: this.metersValues[prop].map(obj => obj.total_energy_kWh).reverse()});
|
|
|
|
|
- this.barChartLabels = this.metersValues[prop].map(obj => formatDate(obj.dateMax, 'dd/MM','es-Es','-0600')).reverse();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // Json object construction for passing its values to the chartjs datasets according to its requirements
|
|
|
|
|
+ for (let prop in meterKeys2) {
|
|
|
|
|
+ let label = localStorage.getItem("email") == "inverlec@grupomerelec.com" ? `INVERLEC ${prop}` : this.metersKeys[prop];
|
|
|
|
|
+ this.metersData.push({"label": label, backgroundColor: this.barChartColors[prop], data: this.metersValues[prop].map(obj => obj.total_energy_kWh).reverse()});
|
|
|
|
|
+ this.barChartLabels = this.metersValues[prop].map(obj => formatDate(obj.dateMax, 'dd/MM','es-Es','-0600')).reverse();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Chart draw
|
|
|
|
|
+ this.chart1 = new Chart('canvas', {
|
|
|
|
|
+ type: 'bar',
|
|
|
|
|
+ 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];
|
|
|
|
|
|
|
|
- // Chart draw
|
|
|
|
|
- this.chart1 = new Chart('canvas', {
|
|
|
|
|
- type: 'bar',
|
|
|
|
|
- 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;
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- return [label + " : " + value, "TOTAL : " + Math.round(total)];
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (tooltipItem.datasetIndex !== data.datasets.length - 1) {
|
|
|
|
|
+ return label + " : " + value;
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ return [label + " : " + value, "TOTAL : " + Math.round(total)];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- },
|
|
|
|
|
- responsive: true,
|
|
|
|
|
- maintainAspectRatio: false,
|
|
|
|
|
- scales: {
|
|
|
|
|
- xAxes: [{
|
|
|
|
|
- stacked: true,
|
|
|
|
|
- }],
|
|
|
|
|
- yAxes: [{
|
|
|
|
|
- stacked: true
|
|
|
|
|
- }]
|
|
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
- data: {
|
|
|
|
|
- labels: this.barChartLabels,
|
|
|
|
|
- datasets:
|
|
|
|
|
- this.metersData,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- this.chartjs = true;
|
|
|
|
|
|
|
+ responsive: true,
|
|
|
|
|
+ maintainAspectRatio: false,
|
|
|
|
|
+ scales: {
|
|
|
|
|
+ xAxes: [{
|
|
|
|
|
+ stacked: true,
|
|
|
|
|
+ }],
|
|
|
|
|
+ yAxes: [{
|
|
|
|
|
+ stacked: true
|
|
|
|
|
+ }]
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ data: {
|
|
|
|
|
+ labels: this.barChartLabels,
|
|
|
|
|
+ datasets:
|
|
|
|
|
+ this.metersData,
|
|
|
|
|
+ },
|
|
|
});
|
|
});
|
|
|
this.chartjs = true;
|
|
this.chartjs = true;
|
|
|
- setTimeout(()=>{
|
|
|
|
|
- Swal.close();
|
|
|
|
|
- }, 2700);
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ this.chartjs = true;
|
|
|
|
|
+ setTimeout(()=>{
|
|
|
|
|
+ Swal.close();
|
|
|
|
|
+ }, 2700);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if (this.myDateInit) {
|
|
|
|
|
+ // Initialize to specific date range with IMyDate object.
|
|
|
|
|
+ // Begin date = today. End date = today + 3.
|
|
|
|
|
+ let begin: Date = new Date();
|
|
|
|
|
+ let end: Date = new Date();
|
|
|
|
|
+ begin.setDate(end.getDate() - 31);
|
|
|
|
|
+ console.log("if");
|
|
|
|
|
+ this.model = {
|
|
|
|
|
+ isRange: true,
|
|
|
|
|
+ singleDate: null,
|
|
|
|
|
+ dateRange: {
|
|
|
|
|
+ beginDate: {
|
|
|
|
|
+ year: begin.getFullYear(), month: begin.getMonth() + 1, day: begin.getDate()
|
|
|
|
|
+ },
|
|
|
|
|
+ endDate: {
|
|
|
|
|
+ year: end.getFullYear(), month: end.getMonth() + 1, day: end.getDate()
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ // Initialize to specific date range with a javascript date object.
|
|
|
|
|
+ // Begin date = today. End date = today + 3.
|
|
|
|
|
+ let begin: Date = new Date();
|
|
|
|
|
+ let end: Date = new Date();
|
|
|
|
|
+ end.setDate(end.getDate() + 3);
|
|
|
|
|
+ console.log("else");
|
|
|
|
|
+ this.model = {
|
|
|
|
|
+ isRange: true,
|
|
|
|
|
+ singleDate: null,
|
|
|
|
|
+ dateRange: {
|
|
|
|
|
+ beginJsDate: begin,
|
|
|
|
|
+ endJsDate: end
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -192,12 +254,36 @@ export class AssetsComponent implements OnInit {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- onChangeObj(event) {
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ onDateChanged(event: IMyDateModel) {
|
|
|
|
|
+ console.log('onDateChanged(): ', event);
|
|
|
|
|
+ let beginDate = `${event.dateRange.beginDate.year}-${event.dateRange.beginDate.month}-${event.dateRange.beginDate.day}`;
|
|
|
|
|
+ let endDate = `${event.dateRange.endDate.year}-${event.dateRange.endDate.month}-${event.dateRange.endDate.day}`;
|
|
|
|
|
+
|
|
|
|
|
+ switch (this.view)
|
|
|
|
|
+ {
|
|
|
|
|
+ case "day":
|
|
|
|
|
+ console.log("day");
|
|
|
|
|
+ this.onMeasureClickDay(beginDate);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "week":
|
|
|
|
|
+ console.log("week");
|
|
|
|
|
+ this.onMeasureClickWeek(beginDate, endDate);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "month":
|
|
|
|
|
+ console.log("month");
|
|
|
|
|
+ this.onMeasureClickMonth(beginDate, endDate);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "year":
|
|
|
|
|
+ console.log("year");
|
|
|
|
|
+ this.onMeasureYear(beginDate, endDate);
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ console.log("nada");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- onMeasureClickDay(): void {
|
|
|
|
|
|
|
+ onMeasureClickDay(measureDate?:string): void {
|
|
|
Swal.fire({
|
|
Swal.fire({
|
|
|
allowOutsideClick: false,
|
|
allowOutsideClick: false,
|
|
|
type: 'info',
|
|
type: 'info',
|
|
@@ -205,6 +291,8 @@ export class AssetsComponent implements OnInit {
|
|
|
});
|
|
});
|
|
|
Swal.showLoading();
|
|
Swal.showLoading();
|
|
|
this.isActive = [true, false, false, false];
|
|
this.isActive = [true, false, false, false];
|
|
|
|
|
+ this.view = "day";
|
|
|
|
|
+
|
|
|
this.chart1.destroy();
|
|
this.chart1.destroy();
|
|
|
|
|
|
|
|
|
|
|
|
@@ -280,7 +368,7 @@ export class AssetsComponent implements OnInit {
|
|
|
}, 2700)
|
|
}, 2700)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- onMeasureClickWeek(): void {;
|
|
|
|
|
|
|
+ onMeasureClickWeek(measureDateBegin?:string, measureDateEnd?:string): void {;
|
|
|
|
|
|
|
|
Swal.fire({
|
|
Swal.fire({
|
|
|
allowOutsideClick: false,
|
|
allowOutsideClick: false,
|
|
@@ -288,6 +376,7 @@ export class AssetsComponent implements OnInit {
|
|
|
text: 'Espere por favor...'
|
|
text: 'Espere por favor...'
|
|
|
});
|
|
});
|
|
|
Swal.showLoading();
|
|
Swal.showLoading();
|
|
|
|
|
+ this.view = "week";
|
|
|
this.isActive = [false, true, false, false];
|
|
this.isActive = [false, true, false, false];
|
|
|
this.chart1.destroy();
|
|
this.chart1.destroy();
|
|
|
|
|
|
|
@@ -364,13 +453,14 @@ export class AssetsComponent implements OnInit {
|
|
|
}, 2700)
|
|
}, 2700)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- onMeasureClickMonth(): void {
|
|
|
|
|
|
|
+ onMeasureClickMonth(measureDateBegin?:string, measureDateEnd?:string): void {
|
|
|
Swal.fire({
|
|
Swal.fire({
|
|
|
allowOutsideClick: false,
|
|
allowOutsideClick: false,
|
|
|
type: 'info',
|
|
type: 'info',
|
|
|
text: 'Espere por favor...'
|
|
text: 'Espere por favor...'
|
|
|
});
|
|
});
|
|
|
Swal.showLoading();
|
|
Swal.showLoading();
|
|
|
|
|
+ this.view = "month";
|
|
|
this.isActive = [false, false, true, false];
|
|
this.isActive = [false, false, true, false];
|
|
|
this.chart1.destroy();
|
|
this.chart1.destroy();
|
|
|
|
|
|
|
@@ -448,7 +538,7 @@ export class AssetsComponent implements OnInit {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- onMeasureYear(): void {
|
|
|
|
|
|
|
+ onMeasureYear(measureDateBegin?:string, measureDateEnd?:string): void {
|
|
|
|
|
|
|
|
Swal.fire({
|
|
Swal.fire({
|
|
|
allowOutsideClick: false,
|
|
allowOutsideClick: false,
|
|
@@ -456,7 +546,7 @@ export class AssetsComponent implements OnInit {
|
|
|
text: 'Espere por favor...'
|
|
text: 'Espere por favor...'
|
|
|
});
|
|
});
|
|
|
Swal.showLoading();
|
|
Swal.showLoading();
|
|
|
-
|
|
|
|
|
|
|
+ this.view = "year";
|
|
|
this.isActive = [false, false, false, true];
|
|
this.isActive = [false, false, false, true];
|
|
|
this.chart1.destroy();
|
|
this.chart1.destroy();
|
|
|
|
|
|