|
|
@@ -0,0 +1,310 @@
|
|
|
+import { ActivatedRoute, Router } from "@angular/router";
|
|
|
+import { Component, OnInit, NgZone, ViewChild } from "@angular/core";
|
|
|
+import { Chart, ChartOptions, ChartType, ChartDataSets } from "chart.js";
|
|
|
+import { Label, BaseChartDirective } from "ng2-charts";
|
|
|
+import { PlantsService } from "src/app/services/plants.service";
|
|
|
+import { OrganizationsService } from "src/app/services/organizations.service";
|
|
|
+
|
|
|
+import { MatPaginator } from "@angular/material/paginator";
|
|
|
+import { MatSort } from "@angular/material/sort";
|
|
|
+import { MatTableDataSource } from "@angular/material/table";
|
|
|
+import { AuthService } from "@app/services/auth2.service";
|
|
|
+import { formatDate, DatePipe } from "@angular/common";
|
|
|
+
|
|
|
+import * as moment from "moment";
|
|
|
+import Swal from "sweetalert2";
|
|
|
+import { RatesService } from "@app/services/rates.service";
|
|
|
+
|
|
|
+@Component({
|
|
|
+ selector: "app-rates",
|
|
|
+ templateUrl: "./rates.component.html",
|
|
|
+ styleUrls: ["./rates.component.scss"],
|
|
|
+})
|
|
|
+export class RatesComponent implements OnInit {
|
|
|
+ title = "Tarifas";
|
|
|
+
|
|
|
+ listData: any;
|
|
|
+ rows = [];
|
|
|
+
|
|
|
+ listAssets: any;
|
|
|
+ dataSource = new MatTableDataSource(this.listAssets);
|
|
|
+ displayedColumns: string[] = ["name", "country", "city", "id"];
|
|
|
+
|
|
|
+ error: boolean;
|
|
|
+ listOrganizations: any;
|
|
|
+ plantId: string;
|
|
|
+ plant: any;
|
|
|
+ sub: any;
|
|
|
+ plantNotFound: boolean;
|
|
|
+ selectedPlant: any;
|
|
|
+ meterKeys: any;
|
|
|
+ meterKeys2: any;
|
|
|
+ assetKeys: any;
|
|
|
+
|
|
|
+ sumarize: number = 0;
|
|
|
+ totalInstalled: number = 0;
|
|
|
+
|
|
|
+ totalMetersInstalled: string;
|
|
|
+
|
|
|
+ lastUpdate = new Date().toLocaleString();
|
|
|
+ i: number;
|
|
|
+
|
|
|
+ userLevel: number;
|
|
|
+ totalAssetsInstalled: any;
|
|
|
+
|
|
|
+ rates: Object = {
|
|
|
+ distribuidora: "-",
|
|
|
+ codigo_tarifa: "-",
|
|
|
+ tarifa_actual: {
|
|
|
+ dateMin: null,
|
|
|
+ dateMax: null,
|
|
|
+ cargo_energia: null,
|
|
|
+ cargo_energia_b1: null,
|
|
|
+ cargo_energia_b2: null,
|
|
|
+ cargo_energia_b3: null,
|
|
|
+ cargo_energia_punta: null,
|
|
|
+ cargo_energia_resto: null,
|
|
|
+ cargo_energia_valle: null,
|
|
|
+ },
|
|
|
+ incremento_porcentaje: {
|
|
|
+ cargo_energia: null,
|
|
|
+ cargo_energia_b1: null,
|
|
|
+ cargo_energia_b2: null,
|
|
|
+ cargo_energia_b3: null,
|
|
|
+ cargo_energia_punta: null,
|
|
|
+ cargo_energia_resto: null,
|
|
|
+ cargo_energia_valle: null,
|
|
|
+ },
|
|
|
+ };
|
|
|
+
|
|
|
+ // For chartjs
|
|
|
+ chartjs: boolean;
|
|
|
+ chart1: Chart;
|
|
|
+ chart1Type;
|
|
|
+ barChartColors: any = [
|
|
|
+ "#5c90aa",
|
|
|
+ "#a7c1d3",
|
|
|
+ "#4e5151",
|
|
|
+ "#916458",
|
|
|
+ "#ee964b",
|
|
|
+ "#a9d0ea",
|
|
|
+ "#a7c957",
|
|
|
+ "#f2e8cf",
|
|
|
+ ];
|
|
|
+ borderChartColors: any = [
|
|
|
+ "#336b87",
|
|
|
+ "#90afc5",
|
|
|
+ "#2a3132",
|
|
|
+ "#763626",
|
|
|
+ "#d38d51",
|
|
|
+ "#a2cae4",
|
|
|
+ "#91b43d",
|
|
|
+ "#d3cbb7",
|
|
|
+ ];
|
|
|
+ public barChartType: ChartType;
|
|
|
+ public barChartLegend: boolean;
|
|
|
+ public barChartLabels: Label[];
|
|
|
+ public barChartOptions: ChartOptions;
|
|
|
+ public barChartData: ChartDataSets[];
|
|
|
+ @ViewChild("baseChart", null) chart: BaseChartDirective;
|
|
|
+ metersData: any[];
|
|
|
+ metersValues: unknown[];
|
|
|
+
|
|
|
+ constructor(
|
|
|
+ private plantsService: PlantsService,
|
|
|
+ private route: ActivatedRoute,
|
|
|
+ private orgService: OrganizationsService,
|
|
|
+ private router: Router,
|
|
|
+ private zone: NgZone,
|
|
|
+ private authService: AuthService,
|
|
|
+ private ratesService: RatesService
|
|
|
+ ) {
|
|
|
+ //DEMO
|
|
|
+ this.userLevel = +this.authService.getUserLevel();
|
|
|
+
|
|
|
+ Swal.fire({
|
|
|
+ allowOutsideClick: false,
|
|
|
+ type: "info",
|
|
|
+ text: "Espere por favor...",
|
|
|
+ });
|
|
|
+ Swal.showLoading();
|
|
|
+ }
|
|
|
+
|
|
|
+ ngOnInit() {
|
|
|
+ setTimeout(() => {
|
|
|
+ Swal.close();
|
|
|
+ }, 3000);
|
|
|
+
|
|
|
+ this.ratesService.getDefaultRate().subscribe((res) => {
|
|
|
+ console.log("tarifa");
|
|
|
+ console.log(res);
|
|
|
+ this.rates = res["data"];
|
|
|
+ });
|
|
|
+
|
|
|
+ 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 = [];
|
|
|
+ let cargo_energia = [];
|
|
|
+ let cargo_energia_b1 = [];
|
|
|
+ let cargo_energia_b2 = [];
|
|
|
+ let cargo_energia_b3 = [];
|
|
|
+
|
|
|
+ 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],
|
|
|
+ }
|
|
|
+ );*/
|
|
|
+ }
|
|
|
+ console.log(labels);
|
|
|
+ this.barChartType = "line";
|
|
|
+ this.barChartLabels = labels;
|
|
|
+
|
|
|
+ this.metersData.push(
|
|
|
+ {
|
|
|
+ label: "Cargo energia",
|
|
|
+ backgroundColor: this.barChartColors[0],
|
|
|
+ data: cargo_energia,
|
|
|
+ barPercentage: 0.7,
|
|
|
+ borderColor: this.borderChartColors[0],
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: "Cargo energia bloque 1",
|
|
|
+ backgroundColor: this.barChartColors[1],
|
|
|
+ data: cargo_energia_b1,
|
|
|
+ barPercentage: 0.7,
|
|
|
+ borderColor: this.borderChartColors[1],
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: "Cargo energia bloque 2",
|
|
|
+ backgroundColor: this.barChartColors[2],
|
|
|
+ data: cargo_energia_b2,
|
|
|
+ barPercentage: 0.7,
|
|
|
+ borderColor: this.borderChartColors[2],
|
|
|
+ },
|
|
|
+ {
|
|
|
+ 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();
|
|
|
+ */
|
|
|
+
|
|
|
+ this.barChartOptions = {
|
|
|
+ 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];
|
|
|
+
|
|
|
+ return label + " : " + value;
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ responsive: true,
|
|
|
+ maintainAspectRatio: false,
|
|
|
+ scales: {
|
|
|
+ xAxes: [
|
|
|
+ {
|
|
|
+ stacked: false,
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ yAxes: [
|
|
|
+ {
|
|
|
+ stacked: false,
|
|
|
+ position: "left",
|
|
|
+ scaleLabel: {
|
|
|
+ display: true,
|
|
|
+ labelString: "Tarifa en $USD por kWh",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ };
|
|
|
+
|
|
|
+ this.barChartLegend = true;
|
|
|
+ this.barChartData = this.metersData;
|
|
|
+ });
|
|
|
+
|
|
|
+ var responsiveOptions: any[] = [
|
|
|
+ [
|
|
|
+ "screen and (max-width: 640px)",
|
|
|
+ {
|
|
|
+ seriesBarDistance: 5,
|
|
|
+ axisX: {
|
|
|
+ labelInterpolationFnc: function (value) {
|
|
|
+ return value[0];
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ ngOnChanges(): void {}
|
|
|
+}
|