|
|
@@ -14,6 +14,7 @@ import { formatDate, DatePipe } from "@angular/common";
|
|
|
import * as moment from "moment";
|
|
|
import Swal from "sweetalert2";
|
|
|
import { RatesService } from "@app/services/rates.service";
|
|
|
+import { CatalogsService } from "@app/services/catalogs.service";
|
|
|
|
|
|
@Component({
|
|
|
selector: "app-rates",
|
|
|
@@ -109,6 +110,8 @@ export class RatesComponent implements OnInit {
|
|
|
@ViewChild("baseChart", null) chart: BaseChartDirective;
|
|
|
metersData: any[];
|
|
|
metersValues: unknown[];
|
|
|
+ distribuidoras: any;
|
|
|
+ tarifas: any;
|
|
|
|
|
|
constructor(
|
|
|
private plantsService: PlantsService,
|
|
|
@@ -117,7 +120,8 @@ export class RatesComponent implements OnInit {
|
|
|
private router: Router,
|
|
|
private zone: NgZone,
|
|
|
private authService: AuthService,
|
|
|
- private ratesService: RatesService
|
|
|
+ private ratesService: RatesService,
|
|
|
+ private catalogService: CatalogsService
|
|
|
) {
|
|
|
//DEMO
|
|
|
this.userLevel = +this.authService.getUserLevel();
|
|
|
@@ -136,18 +140,21 @@ export class RatesComponent implements OnInit {
|
|
|
}, 3000);
|
|
|
|
|
|
this.ratesService.getDefaultRate().subscribe((res) => {
|
|
|
- console.log("tarifa");
|
|
|
- console.log(res);
|
|
|
this.rates = res["data"];
|
|
|
});
|
|
|
|
|
|
+ this.catalogService.getCatalogByName("distribuidoras").subscribe((res) => {
|
|
|
+ this.distribuidoras = res["data"]["catalogo"]["records"];
|
|
|
+ });
|
|
|
+
|
|
|
+ this.catalogService.getCatalogByName("tarifas").subscribe((res) => {
|
|
|
+ this.tarifas = res["data"]["catalogo"]["records"];
|
|
|
+ });
|
|
|
+
|
|
|
this.ratesService.getHistoricalRate().subscribe((res) => {
|
|
|
- console.log("historico");
|
|
|
- console.log(res);
|
|
|
this.metersData = [];
|
|
|
this.metersValues = Object.values(res["data"]["tarifas"]);
|
|
|
|
|
|
- console.log(this.metersValues);
|
|
|
let meterKeys2 = Object.keys(this.metersValues);
|
|
|
|
|
|
let labels = [];
|
|
|
@@ -155,99 +162,108 @@ export class RatesComponent implements OnInit {
|
|
|
let cargo_energia_b1 = [];
|
|
|
let cargo_energia_b2 = [];
|
|
|
let cargo_energia_b3 = [];
|
|
|
+ let cargo_energia_punta = [];
|
|
|
+ let cargo_energia_resto = [];
|
|
|
+ let cargo_energia_valle = [];
|
|
|
|
|
|
for (let prop in meterKeys2) {
|
|
|
- console.log();
|
|
|
- //let label = localStorage.getItem("email") == "inverlec@grupomerelec.com" ? `INVERLEC ${prop}` : this.metersValues[prop]["label"];
|
|
|
-
|
|
|
- //label = this.metersValues["dateMin"] + "-" + this.metersValues["dateMax"] ;
|
|
|
- /*
|
|
|
- let measure_values = Object.values(
|
|
|
- this.metersValues[prop]["data"]
|
|
|
- .map((obj) => obj.total_energy_kWh)
|
|
|
- .reverse()
|
|
|
- );*/
|
|
|
-
|
|
|
labels.push(
|
|
|
`${this.metersValues[prop]["dateMin"]} - ${this.metersValues[prop]["dateMax"]}`
|
|
|
);
|
|
|
-
|
|
|
if (this.metersValues[prop]["cargo_energia"] != "") {
|
|
|
cargo_energia.push(this.metersValues[prop]["cargo_energia"]);
|
|
|
}
|
|
|
-
|
|
|
if (this.metersValues[prop]["cargo_energia_b1"] != "") {
|
|
|
cargo_energia_b1.push(this.metersValues[prop]["cargo_energia_b1"]);
|
|
|
}
|
|
|
-
|
|
|
if (this.metersValues[prop]["cargo_energia_b2"] != "") {
|
|
|
cargo_energia_b2.push(this.metersValues[prop]["cargo_energia_b2"]);
|
|
|
}
|
|
|
-
|
|
|
if (this.metersValues[prop]["cargo_energia_b3"] != "") {
|
|
|
cargo_energia_b3.push(this.metersValues[prop]["cargo_energia_b3"]);
|
|
|
}
|
|
|
-
|
|
|
- /*
|
|
|
-
|
|
|
-
|
|
|
- this.metersData.push(
|
|
|
- {
|
|
|
- label: label,
|
|
|
- backgroundColor: this.barChartColors[prop],
|
|
|
- data: measure_values,
|
|
|
- barPercentage: 0.7,
|
|
|
- borderColor: this.borderChartColors[prop],
|
|
|
- }
|
|
|
- );*/
|
|
|
+ if (this.metersValues[prop]["cargo_energia_punta"] != "") {
|
|
|
+ cargo_energia_punta.push(
|
|
|
+ this.metersValues[prop]["cargo_energia_punta"]
|
|
|
+ );
|
|
|
+ }
|
|
|
+ if (this.metersValues[prop]["cargo_energia_resto"] != "") {
|
|
|
+ cargo_energia_resto.push(
|
|
|
+ this.metersValues[prop]["cargo_energia_resto"]
|
|
|
+ );
|
|
|
+ }
|
|
|
+ if (this.metersValues[prop]["cargo_energia_valle"] != "") {
|
|
|
+ cargo_energia_valle.push(
|
|
|
+ this.metersValues[prop]["cargo_energia_valle"]
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
- console.log(labels);
|
|
|
this.barChartType = "line";
|
|
|
this.barChartLabels = labels;
|
|
|
|
|
|
- this.metersData.push(
|
|
|
- {
|
|
|
+ if (cargo_energia.length > 0) {
|
|
|
+ this.metersData.push({
|
|
|
label: "Cargo energia",
|
|
|
backgroundColor: this.barChartColors[0],
|
|
|
data: cargo_energia,
|
|
|
barPercentage: 0.7,
|
|
|
borderColor: this.borderChartColors[0],
|
|
|
- },
|
|
|
- {
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (cargo_energia_b1.length > 0) {
|
|
|
+ this.metersData.push({
|
|
|
label: "Cargo energia bloque 1",
|
|
|
backgroundColor: this.barChartColors[1],
|
|
|
data: cargo_energia_b1,
|
|
|
barPercentage: 0.7,
|
|
|
borderColor: this.borderChartColors[1],
|
|
|
- },
|
|
|
- {
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (cargo_energia_b2.length > 0) {
|
|
|
+ this.metersData.push({
|
|
|
label: "Cargo energia bloque 2",
|
|
|
backgroundColor: this.barChartColors[2],
|
|
|
data: cargo_energia_b2,
|
|
|
barPercentage: 0.7,
|
|
|
borderColor: this.borderChartColors[2],
|
|
|
- },
|
|
|
- {
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (cargo_energia_b3.length > 0) {
|
|
|
+ this.metersData.push({
|
|
|
label: "Cargo energia bloque 3",
|
|
|
backgroundColor: this.barChartColors[3],
|
|
|
data: cargo_energia_b3,
|
|
|
barPercentage: 0.7,
|
|
|
borderColor: this.borderChartColors[3],
|
|
|
- }
|
|
|
- );
|
|
|
- /*
|
|
|
-
|
|
|
- this.metersValues[0]["data"]
|
|
|
- .map((obj) =>
|
|
|
- formatDate(
|
|
|
- obj.dateMin.replace(/-/g, "/").replace("T", " "),
|
|
|
- "HH:mm ",
|
|
|
- "es-Es",
|
|
|
- "-0600"
|
|
|
- )
|
|
|
- )
|
|
|
- .reverse();
|
|
|
- */
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (cargo_energia_punta.length > 0) {
|
|
|
+ this.metersData.push({
|
|
|
+ label: "Cargo energia punta",
|
|
|
+ backgroundColor: this.barChartColors[4],
|
|
|
+ data: cargo_energia_punta,
|
|
|
+ barPercentage: 0.7,
|
|
|
+ borderColor: this.borderChartColors[4],
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (cargo_energia_resto.length > 0) {
|
|
|
+ this.metersData.push({
|
|
|
+ label: "Cargo energia resto",
|
|
|
+ backgroundColor: this.barChartColors[5],
|
|
|
+ data: cargo_energia_resto,
|
|
|
+ barPercentage: 0.7,
|
|
|
+ borderColor: this.borderChartColors[5],
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (cargo_energia_valle.length > 0) {
|
|
|
+ this.metersData.push({
|
|
|
+ label: "Cargo energia valle",
|
|
|
+ backgroundColor: this.barChartColors[6],
|
|
|
+ data: cargo_energia_valle,
|
|
|
+ barPercentage: 0.7,
|
|
|
+ borderColor: this.borderChartColors[6],
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
this.barChartOptions = {
|
|
|
title: {
|
|
|
@@ -307,4 +323,6 @@ export class RatesComponent implements OnInit {
|
|
|
}
|
|
|
|
|
|
ngOnChanges(): void {}
|
|
|
+
|
|
|
+ onChangeObj() {}
|
|
|
}
|