Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Storage Chart #2828

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 39 additions & 28 deletions ui/src/app/edge/history/abstracthistorychart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,56 +265,67 @@ export abstract class AbstractHistoryChart {
* @param edge the current Edge
* @param ws the websocket
*/
protected queryHistoricTimeseriesData(fromDate: Date, toDate: Date, res?: Resolution): Promise<QueryHistoricTimeseriesDataResponse> {

// Take custom resolution if passed
protected queryHistoricTimeseriesData(fromDate: Date, toDate: Date, res?: Resolution): Promise<QueryHistoricTimeseriesDataResponse> {
const resolution = res ?? calculateResolution(this.service, fromDate, toDate).resolution;

this.errorResponse = null;

if (this.debounceTimeout) {
clearTimeout(this.debounceTimeout);
}

this.debounceTimeout = setTimeout(() => {
const result: Promise<QueryHistoricTimeseriesDataResponse> = new Promise<QueryHistoricTimeseriesDataResponse>((resolve, reject) => {
return new Promise<QueryHistoricTimeseriesDataResponse>((resolve, reject) => {
this.debounceTimeout = setTimeout(() => {
this.service.getCurrentEdge().then(edge => {
this.service.getConfig().then(config => {
this.setLabel(config);
this.getChannelAddresses(edge, config).then(channelAddresses => {
const request = new QueryHistoricTimeseriesDataRequest(DateUtils.maxDate(fromDate, this.edge?.firstSetupProtocol), toDate, channelAddresses, resolution);
const request = new QueryHistoricTimeseriesDataRequest(
DateUtils.maxDate(fromDate, this.edge?.firstSetupProtocol),
toDate,
channelAddresses,
resolution,
);
edge.sendRequest(this.service.websocket, request).then(response => {
resolve(response as QueryHistoricTimeseriesDataResponse);
this.activeQueryData = request.id;
resolve(response as QueryHistoricTimeseriesDataResponse);
}).catch(error => {
this.errorResponse = error;
resolve(new QueryHistoricTimeseriesDataResponse(error.id, {
timestamps: [null], data: { null: null },
}));
reject(error);
});
}).catch(error => {
this.errorResponse = error;
reject(error);
});
}).catch(error => {
this.errorResponse = error;
reject(error);
});
}).catch(error => {
this.errorResponse = error;
reject(error);
});
}).then((response) => {
if (this.activeQueryData !== response.id) {
return;
}
if (Utils.isDataEmpty(response)) {
this.loading = false;
this.service.stopSpinner(this.spinnerId);
this.initializeChart();
}
return DateTimeUtils.normalizeTimestamps(resolution.unit, response);
});

return result;
}, ChartConstants.REQUEST_TIMEOUT);

return new Promise((resolve) => {
resolve(new QueryHistoricTimeseriesDataResponse("", { timestamps: [], data: {} }));
}, ChartConstants.REQUEST_TIMEOUT);
}).then((response) => {
if (this.activeQueryData !== response.id) {
throw new Error("Stale response received");
}
if (Utils.isDataEmpty(response)) {
this.loading = false;
this.service.stopSpinner(this.spinnerId);
this.initializeChart();
// Optionally, resolve with empty data or handle as needed
return response;
}
return DateTimeUtils.normalizeTimestamps(resolution.unit, response);
}).catch(error => {
console.error("Error fetching historic timeseries data:", error);
this.initializeChart();
// Optionally, return an empty response or propagate the error
return new QueryHistoricTimeseriesDataResponse("", { timestamps: [], data: {} });
});
}


/**
* Sends the Historic Timeseries Energy per Period Query and makes sure the result is not empty.
*
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/edge/history/storage/singlechart.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class StorageSingleChartComponent extends AbstractHistoryChart implements
borderColor: "rgba(0,223,0,1)",
});
}
if ("_sum/EssActivePowerL1" && "_sum/EssActivePowerL2" && "_sum/EssActivePowerL3" in result.data && this.showPhases == true) {
if (["_sum/EssActivePowerL1", "_sum/EssActivePowerL2", "_sum/EssActivePowerL3"].every(channel => channel in result.data) && this.showPhases === true) {
if (channelAddress.channelId == "EssActivePowerL1") {
datasets.push({
label: this.translate.instant("General.phase") + " " + "L1",
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/edge/history/storage/totalchart.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class StorageTotalChartComponent extends AbstractHistoryChart implements
backgroundColor: "rgba(0,223,0,0.05)",
borderColor: "rgba(0,223,0,1)",
});
} if ("_sum/EssActivePowerL1" && "_sum/EssActivePowerL2" && "_sum/EssActivePowerL3" in result.data && this.showPhases == true) {
} if (["_sum/EssActivePowerL1", "_sum/EssActivePowerL2", "_sum/EssActivePowerL3"].every(channel => channel in result.data) && this.showPhases === true) {
if (channelAddress.channelId == "EssActivePowerL1") {
datasets.push({
label: this.translate.instant("General.phase") + " " + "L1",
Expand Down