Skip to content

Commit

Permalink
UI: add TOTAL to history periods
Browse files Browse the repository at this point in the history
* add total to pickdate options, only visible if ibn-date exists
* adjust year-view to show full year -> filled up timestamps and data of energyPerPeriodResponse

Co-authored-by: Michael Grill <[email protected]>
Co-authored-by: Lukas Rieger <[email protected]>
Reviewed-by: Stefan Feilmeier <[email protected]>
  • Loading branch information
3 people committed Feb 1, 2024
1 parent 68cca7c commit c3372cc
Show file tree
Hide file tree
Showing 38 changed files with 339 additions and 157 deletions.
44 changes: 21 additions & 23 deletions tools/build-debian-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

set -e

DEBIAN_UI_LOCATION=tools/debian/usr/share/openems/www
DEBIAN_EDGE_LOCATION=tools/debian/usr/lib/openems/

main() {
initialize_environment
print_header
check_dependencies
common_update_version_in_code
common_build_edge_and_ui_in_parallel
prepare_deb_template
build_deb
create_version_file
Expand All @@ -25,23 +27,8 @@ initialize_environment() {
# Include commons
source $SCRIPT_DIR/common.sh
common_initialize_environment

# Build detailed SNAPSHOT name
if [[ "$VERSION" == *"-SNAPSHOT" ]]; then
# Replace unwanted characters with '.', compliant with Debian version
# Ref: https://unix.stackexchange.com/a/23673
VERSION_DEV_BRANCH="$(git branch --show-current)"
VERSION_DEV_COMMIT=""
if [[ $(git diff --stat) != '' ]]; then
VERSION_DEV_COMMIT="dirty"
else
VERSION_DEV_COMMIT="$(git rev-parse --short HEAD)"
fi
VERSION_DEV_BUILD_TIME=$(date "+%Y%m%d.%H%M")
# Compliant with https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-version
VERSION_STRING="$(echo $VERSION_DEV_BRANCH | tr -cs 'a-zA-Z0-9\n' '.').${VERSION_DEV_BUILD_TIME}.${VERSION_DEV_COMMIT}"
VERSION="${VERSION/-SNAPSHOT/"-${VERSION_STRING}"}"
fi
common_build_snapshot_version

DEB_FILE="${PACKAGE_NAME}.deb"
VERSION_FILE="${PACKAGE_NAME}.version"
}
Expand All @@ -66,13 +53,24 @@ prepare_deb_template() {
sed --in-place "s/^\(Version: \).*$/\1$VERSION/" tools/debian/DEBIAN/control

echo "## Add OpenEMS Edge"
mkdir -p tools/debian/usr/lib/openems/
cp io.openems.edge.application/generated/distributions/executable/EdgeApp.jar tools/debian/usr/lib/openems/openems.jar
if [ -f "$DEBIAN_EDGE_LOCATION/openems.jar" ]; then
echo "openems.jar exists. Skipping common_build_edge."
else
mkdir -p "$DEBIAN_EDGE_LOCATION"
echo "openems.jar does not exist. Building common_build_edge."
common_build_edge
cp build/openems-edge.jar $DEBIAN_EDGE_LOCATION/openems.jar
fi

echo "## Add OpenEMS UI"
rm -Rf tools/debian/usr/share/openems/www/*
mkdir -p tools/debian/usr/share/openems/www
cp -R ui/target/* tools/debian/usr/share/openems/www
if [ -d "$DEBIAN_UI_LOCATION" ] && [ "$(ls -A $DEBIAN_UI_LOCATION)" ] ; then
echo "openems.ui exists. Skipping common_build_ui."
else
mkdir -p "$DEBIAN_UI_LOCATION"
echo "openems.ui does not exist. Building common_build_ui."
common_build_ui
cp -R ui/target/* "$DEBIAN_UI_LOCATION"
fi
}

build_deb() {
Expand Down
24 changes: 23 additions & 1 deletion tools/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,28 @@ common_initialize_environment() {
VERSION_STRING=$(echo $VERSION | cut -s -d'-' -f2)
}

common_build_snapshot_version() {
if [[ "$VERSION" == *"-SNAPSHOT" ]]; then
echo "1"
# Replace unwanted characters with '.', compliant with Debian version
# Ref: https://unix.stackexchange.com/a/23673
VERSION_DEV_BRANCH="$(git branch --show-current)"
echo "2"
VERSION_DEV_COMMIT=""
if [[ $(git diff --stat) != '' ]]; then
VERSION_DEV_COMMIT="dirty"
else
VERSION_DEV_COMMIT="$(git rev-parse --short HEAD)"
fi
echo "3"
VERSION_DEV_BUILD_TIME=$(date "+%Y%m%d.%H%M")
# Compliant with https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-version
echo "4"
VERSION_STRING="$(echo $VERSION_DEV_BRANCH | tr -cs 'a-zA-Z0-9\n' '.').${VERSION_DEV_BUILD_TIME}.${VERSION_DEV_COMMIT}"
VERSION="${VERSION/-SNAPSHOT/"-${VERSION_STRING}"}"
fi
}

# Inserts the version number into the Code
common_update_version_in_code() {
echo "# Update version in Code"
Expand Down Expand Up @@ -51,7 +73,7 @@ common_build_edge_and_ui_in_parallel() {
# Build OpenEMS Edge
common_build_edge() {
echo "# Build OpenEMS Edge"
./gradlew --build-cache build buildEdge resolve.EdgeApp resolve.BackendApp
./gradlew $@ --build-cache build buildEdge resolve.EdgeApp resolve.BackendApp
git diff --exit-code io.openems.edge.application/EdgeApp.bndrun io.openems.backend.application/BackendApp.bndrun
}

Expand Down
9 changes: 5 additions & 4 deletions ui/src/app/edge/history/abstracthistorychart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import { QueryHistoricTimeseriesDataRequest } from "src/app/shared/jsonrpc/reque
import { QueryHistoricTimeseriesEnergyPerPeriodRequest } from 'src/app/shared/jsonrpc/request/queryHistoricTimeseriesEnergyPerPeriodRequest';
import { QueryHistoricTimeseriesDataResponse } from "src/app/shared/jsonrpc/response/queryHistoricTimeseriesDataResponse";
import { QueryHistoricTimeseriesEnergyPerPeriodResponse } from 'src/app/shared/jsonrpc/response/queryHistoricTimeseriesEnergyPerPeriodResponse';
import { HistoryUtils } from 'src/app/shared/service/utils';
import { ChannelAddress, Edge, EdgeConfig, Service, Utils } from "src/app/shared/shared";
import { DateUtils } from 'src/app/shared/utils/date/dateutils';
import { DateTimeUtils } from 'src/app/shared/utils/datetime/datetime-utils';

import { calculateResolution, ChartOptions, DEFAULT_TIME_CHART_OPTIONS, EMPTY_DATASET, Resolution, TooltipItem } from './shared';
import { HistoryUtils } from 'src/app/shared/service/utils';
import { DateUtils } from 'src/app/shared/utils/dateutils/dateutils';

// NOTE: Auto-refresh of widgets is currently disabled to reduce server load
export abstract class AbstractHistoryChart {
Expand Down Expand Up @@ -104,7 +105,7 @@ export abstract class AbstractHistoryChart {
this.service.stopSpinner(this.spinnerId);
this.initializeChart();
}
return response;
return DateTimeUtils.normalizeTimestamps(resolution.unit, response);
});

return result;
Expand Down Expand Up @@ -145,7 +146,7 @@ export abstract class AbstractHistoryChart {
this.service.stopSpinner(this.spinnerId);
this.initializeChart();
}
return response;
return DateTimeUtils.normalizeTimestamps(resolution.unit, response);
});
return response;
}
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/edge/history/abstracthistorywidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { QueryHistoricTimeseriesDataRequest } from 'src/app/shared/jsonrpc/reque
import { QueryHistoricTimeseriesDataResponse } from 'src/app/shared/jsonrpc/response/queryHistoricTimeseriesDataResponse';
import { ChannelAddress, Edge, EdgeConfig, Service } from 'src/app/shared/shared';
import { calculateResolution } from './shared';
import { DateUtils } from 'src/app/shared/utils/dateutils/dateutils';
import { DateUtils } from 'src/app/shared/utils/date/dateutils';

// NOTE: Auto-refresh of widgets is currently disabled to reduce server load
export abstract class AbstractHistoryWidget {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export namespace History {
"_sum/ConsumptionActiveEnergyL2": 30996,
"_sum/ConsumptionActiveEnergyL3": 30996,
"evcs0/ActiveConsumptionEnergy": 13720,
"meter0/ActiveConsumptionEnergy": 15930,
"meter0/ActiveProductionEnergy": 15930,
},
}),
dataChannelWithValues: new QueryHistoricTimeseriesDataResponse("0", {
Expand All @@ -42,7 +42,7 @@ export namespace History {
data: {
"_sum/ConsumptionActiveEnergy": 354079,
"evcs0/ActiveConsumptionEnergy": 157027,
"meter0/ActiveConsumptionEnergy": 100000,
"meter0/ActiveProductionEnergy": 100000,
},
}),
dataChannelWithValues: new QueryHistoricTimeseriesDataResponse("0", {
Expand All @@ -62,15 +62,15 @@ export namespace History {
data: {
'_sum/ConsumptionActiveEnergy': 1033427,
"evcs0/ActiveConsumptionEnergy": 328451,
"meter0/ActiveConsumptionEnergy": 21649,
"meter0/ActiveProductionEnergy": 21649,
},
}),
energyPerPeriodChannelWithValues:
new QueryHistoricTimeseriesEnergyPerPeriodResponse("0", {
data: {
'_sum/ConsumptionActiveEnergy': [1784.3478512581187, 955.1978135997077, 1604.9176251387696, 1821.5474663613152, 1204.011627189301, 1037.408900359932, 1287.891020875591, 1183.057735422114, 1027.8784377276404, 1412.783196754379, 737.2379614126091, 730.6143394985477, 1727.4568452231197, 2045.4827463867603, 1289.9867373938441, 1866.5731598778827, 896.448259060122, 1271.0485678635469, 1489.7323302960576, 1367.9696489029907, 2375.6092366846033, 2368.729102836224, 2686.60326649514, 1597.0390753045413, 972.6650191463931, 1774.233690168573, 2953.838257099637, 917.3087792235759, 1172.9800154902882, null, null],
"evcs0/ActiveConsumptionEnergy": [598.058461158158, 0, 607.3861225965935, 891.3491768679577, 269.6236843407865, 0, 306.41009901340226, 220.51407209843148, 50.15525733301707, 356.42246970726825, 0, 0, 880.0942036863182, 977.4033026217928, 210.23831546417276, 787.0712558876392, 0, 165.50743075023163, 513.2605942604259, 149.06825174512016, 883.6100586172083, 1203.117101530366, 1467.2314708234808, 553.6230686820822, 0, 714.8486366912176, 1836.7765179313803, 0, 300.374916784946, null, null],
"meter0/ActiveConsumptionEnergy": [15.53700680772126, 13.97856617670663, 16.22420643945345, 15.425155003970989, 16.41557086346929, 15.280936198647838, 15.028196655704793, 15.146427851947054, 15.567356482244767, 17.404197969735606, 17.635152684968116, 14.140394156739468, 16.107488806188936, 16.75001277671301, 15.512752420609466, 14.951999780788457, 13.733457057782298, 16.868671206682027, 14.770978996449593, 16.47697124898351, 16.772182319685665, 16.288562161254703, 15.417362341926745, 15.892028990939403, 13.811584043067414, 14.81782772305683, 14.165639305307824, 16.223347257543285, 14.495672387672808, null, null],
"meter0/ActiveProductionEnergy": [15.53700680772126, 13.97856617670663, 16.22420643945345, 15.425155003970989, 16.41557086346929, 15.280936198647838, 15.028196655704793, 15.146427851947054, 15.567356482244767, 17.404197969735606, 17.635152684968116, 14.140394156739468, 16.107488806188936, 16.75001277671301, 15.512752420609466, 14.951999780788457, 13.733457057782298, 16.868671206682027, 14.770978996449593, 16.47697124898351, 16.772182319685665, 16.288562161254703, 15.417362341926745, 15.892028990939403, 13.811584043067414, 14.81782772305683, 14.165639305307824, 16.223347257543285, 14.495672387672808, null, null],
},
timestamps: ["2023-05-31T22:00:00Z", "2023-06-01T22:00:00Z", "2023-06-02T22:00:00Z", "2023-06-03T22:00:00Z", "2023-06-04T22:00:00Z", "2023-06-05T22:00:00Z", "2023-06-06T22:00:00Z", "2023-06-07T22:00:00Z", "2023-06-08T22:00:00Z", "2023-06-09T22:00:00Z", "2023-06-10T22:00:00Z", "2023-06-11T22:00:00Z", "2023-06-12T22:00:00Z", "2023-06-13T22:00:00Z", "2023-06-14T22:00:00Z", "2023-06-15T22:00:00Z", "2023-06-16T22:00:00Z", "2023-06-17T22:00:00Z", "2023-06-18T22:00:00Z", "2023-06-19T22:00:00Z", "2023-06-20T22:00:00Z", "2023-06-21T22:00:00Z", "2023-06-22T22:00:00Z", "2023-06-23T22:00:00Z", "2023-06-24T22:00:00Z", "2023-06-25T22:00:00Z", "2023-06-26T22:00:00Z", "2023-06-27T22:00:00Z", "2023-06-28T22:00:00Z", "2023-06-29T22:00:00Z"],
}),
Expand All @@ -86,7 +86,7 @@ export namespace History {
"_sum/ConsumptionActiveEnergyL2": 4954551,
"_sum/ConsumptionActiveEnergyL3": 4954551,
'evcs0/ActiveConsumptionEnergy': 2071139,
'meter0/ActiveConsumptionEnergy': 1908650,
'meter0/ActiveProductionEnergy': 1908650,
},
}),
energyPerPeriodChannelWithValues:
Expand All @@ -97,7 +97,7 @@ export namespace History {
'_sum/ConsumptionActiveEnergyL2': [560980.3333333334, 611576.3333333334, 601740.6666666666, 644714.6666666666, 585859, 503784, 768996, 676644.3333333334, 0, 0, 0, 0],
'_sum/ConsumptionActiveEnergyL3': [560980.3333333334, 611576.3333333334, 601740.6666666666, 644714.6666666666, 585859, 503784, 768996, 676644.3333333334, 0, 0, 0, 0],
'evcs0/ActiveConsumptionEnergy': [69104, 131703, 25773, 51085, 169943, 332522, 748189, 540740, 0, 0, 0, 0],
'meter0/ActiveConsumptionEnergy': [338070, 312380, 298930, 317700, 200210, 151160, 145880, 144280, 0, 0, 0, 0],
'meter0/ActiveProductionEnergy': [338070, 312380, 298930, 317700, 200210, 151160, 145880, 144280, 0, 0, 0, 0],
},
timestamps: ["2022-12-31T23:00:00Z", "2023-01-31T23:00:00Z", "2023-02-28T23:00:00Z", "2023-03-31T22:00:00Z", "2023-04-30T22:00:00Z", "2023-05-31T22:00:00Z", "2023-06-30T22:00:00Z", "2023-07-31T22:00:00Z", "2023-08-31T22:00:00Z", "2023-09-30T22:00:00Z", "2023-10-31T23:00:00Z", "2023-11-30T23:00:00Z"],
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ChartConfig, DummyConfig } from "src/app/shared/edge/edgeconfig.spec";

import { sharedSetup, TestContext } from "../../../../../shared/test/utils.spec";
import { DATA, LABELS } from "../../energy/chart/chart.constants.spec";
import { History } from "./channels.spec";
import { expectView } from "./chart.constants.spec";
import { DATA, LABELS } from "../../energy/chart/chart.constants.spec";

describe('History Consumption', () => {
const defaultEMS = DummyConfig.from(
Expand All @@ -12,8 +12,8 @@ describe('History Consumption', () => {
);

let TEST_CONTEXT: TestContext;
beforeEach(() =>
TEST_CONTEXT = sharedSetup(),
beforeEach(async () =>
TEST_CONTEXT = await sharedSetup(),
);

it('#getChartData()', () => {
Expand Down
4 changes: 2 additions & 2 deletions ui/src/app/edge/history/common/energy/chart/chart.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ describe('History EnergyMonitor', () => {
);

let TEST_CONTEXT: TestContext;
beforeEach(() =>
TEST_CONTEXT = sharedSetup(),
beforeEach(async () =>
TEST_CONTEXT = await sharedSetup(),
);

it('getChartData()', () => {
Expand Down
4 changes: 2 additions & 2 deletions ui/src/app/edge/history/common/grid/chart/chart.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ describe('History Grid', () => {
);

let TEST_CONTEXT: TestContext;
beforeEach(() =>
TEST_CONTEXT = sharedSetup(),
beforeEach(async () =>
TEST_CONTEXT = await sharedSetup(),
);

it('#getChartData()', () => {
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/edge/history/historydataservice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Inject, Injectable } from "@angular/core";
import { DataService } from "../../shared/genericComponents/shared/dataservice";
import { QueryHistoricTimeseriesEnergyResponse } from "../../shared/jsonrpc/response/queryHistoricTimeseriesEnergyResponse";
import { ChannelAddress, Edge } from "../../shared/shared";
import { DateUtils } from "src/app/shared/utils/dateutils/dateutils";
import { DateUtils } from "src/app/shared/utils/date/dateutils";
import { QueryHistoricTimeseriesEnergyRequest } from "src/app/shared/jsonrpc/request/queryHistoricTimeseriesEnergyRequest";
import { Websocket } from "src/app/shared/service/websocket";
import { Service } from "src/app/shared/service/service";
Expand Down
67 changes: 43 additions & 24 deletions ui/src/app/edge/history/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,57 +287,59 @@ export function calculateActiveTimeOverPeriod(channel: ChannelAddress, queryResu
* @param toDate the To-Date
* @returns resolution and timeformat
*/
export function calculateResolution(service: Service, fromDate: Date, toDate: Date): { resolution: Resolution, timeFormat: 'day' | 'month' | 'hour' } {
export function calculateResolution(service: Service, fromDate: Date, toDate: Date): { resolution: Resolution, timeFormat: 'day' | 'month' | 'hour' | 'year' } {
let days = Math.abs(differenceInDays(toDate, fromDate));
let resolution: { resolution: Resolution, timeFormat: 'day' | 'month' | 'hour' };
let resolution: { resolution: Resolution, timeFormat: 'day' | 'month' | 'hour' | 'year' };

if (days <= 1) {
resolution = { resolution: { value: 5, unit: Unit.MINUTES }, timeFormat: 'hour' }; // 5 Minutes
resolution = { resolution: { value: 5, unit: ChronoUnit.Type.MINUTES }, timeFormat: 'hour' }; // 5 Minutes
} else if (days == 2) {
if (service.isSmartphoneResolution) {
resolution = { resolution: { value: 1, unit: Unit.DAYS }, timeFormat: 'hour' }; // 1 Day
resolution = { resolution: { value: 1, unit: ChronoUnit.Type.DAYS }, timeFormat: 'hour' }; // 1 Day
} else {
resolution = { resolution: { value: 10, unit: Unit.MINUTES }, timeFormat: 'hour' }; // 1 Hour
resolution = { resolution: { value: 10, unit: ChronoUnit.Type.MINUTES }, timeFormat: 'hour' }; // 1 Hour
}

} else if (days <= 4) {
if (service.isSmartphoneResolution) {
resolution = { resolution: { value: 1, unit: Unit.DAYS }, timeFormat: 'day' }; // 1 Day
resolution = { resolution: { value: 1, unit: ChronoUnit.Type.DAYS }, timeFormat: 'day' }; // 1 Day
} else {
resolution = { resolution: { value: 1, unit: Unit.HOURS }, timeFormat: 'hour' }; // 1 Hour
resolution = { resolution: { value: 1, unit: ChronoUnit.Type.HOURS }, timeFormat: 'hour' }; // 1 Hour
}

} else if (days <= 6) {
// >> show Hours
resolution = { resolution: { value: 1, unit: Unit.HOURS }, timeFormat: 'day' }; // 1 Day
resolution = { resolution: { value: 1, unit: ChronoUnit.Type.HOURS }, timeFormat: 'day' }; // 1 Day

} else if (days <= 31 && service.isSmartphoneResolution) {
// Smartphone-View: show 31 days in daily view
resolution = { resolution: { value: 1, unit: Unit.DAYS }, timeFormat: 'day' }; // 1 Day
resolution = { resolution: { value: 1, unit: ChronoUnit.Type.DAYS }, timeFormat: 'day' }; // 1 Day

} else if (days <= 90) {
resolution = { resolution: { value: 1, unit: Unit.DAYS }, timeFormat: 'day' }; // 1 Day
resolution = { resolution: { value: 1, unit: ChronoUnit.Type.DAYS }, timeFormat: 'day' }; // 1 Day

} else if (days <= 144) {
// >> show Days
if (service.isSmartphoneResolution == true) {
resolution = { resolution: { value: 1, unit: Unit.MONTHS }, timeFormat: 'month' }; // 1 Month
resolution = { resolution: { value: 1, unit: ChronoUnit.Type.MONTHS }, timeFormat: 'month' }; // 1 Month
} else {
resolution = { resolution: { value: 1, unit: Unit.DAYS }, timeFormat: 'day' }; // 1 Day
resolution = { resolution: { value: 1, unit: ChronoUnit.Type.DAYS }, timeFormat: 'day' }; // 1 Day
}
} else if (days <= 365) {
resolution = { resolution: { value: 1, unit: ChronoUnit.Type.MONTHS }, timeFormat: 'month' }; // 1 Day

} else {
// >> show Months
resolution = { resolution: { value: 1, unit: Unit.MONTHS }, timeFormat: 'month' }; // 1 Month
// >> show Years
resolution = { resolution: { value: 1, unit: ChronoUnit.Type.YEARS }, timeFormat: 'year' }; // 1 Month
}
return resolution;
}

/**
* Returns true if Chart Label should be visible. Defaults to true.
*
* Compares only the first part of the label string - without a value or unit.
*
*
* Compares only the first part of the label string - without a value or ChronoUnit.Type.
*
* @param label the Chart label
* @param orElse the default, in case no value was stored yet in Session-Storage
* @returns true for visible labels; hidden otherwise
Expand Down Expand Up @@ -368,15 +370,32 @@ export function setLabelVisible(label: string, visible: boolean | null): void {

export type Resolution = {
value: number,
unit: Unit
unit: ChronoUnit.Type
}

export enum Unit {
SECONDS = "Seconds",
MINUTES = "Minutes",
HOURS = "Hours",
DAYS = "Days",
MONTHS = "Months",
export namespace ChronoUnit {

export enum Type {
SECONDS = "Seconds",
MINUTES = "Minutes",
HOURS = "Hours",
DAYS = "Days",
MONTHS = "Months",
YEARS = "Years"
}

/**
* Evaluates whether "ChronoUnit 1" is equal or a bigger period than "ChronoUnit 2".
*
* @param unit1 the ChronoUnit 1
* @param unit2 the ChronoUnit 2
* @return true if "ChronoUnit 1" is equal or a bigger period than "ChronoUnit 2"
*/
export function isAtLeast(unit1: Type, unit2: Type) {
const currentUnit = Object.values(Type).indexOf(unit1);
const unitToCompareTo = Object.values(Type).indexOf(unit2);
return currentUnit >= unitToCompareTo;
}
}

export type ChartData = {
Expand Down
Loading

0 comments on commit c3372cc

Please sign in to comment.