Skip to content

Commit 2e4a0fc

Browse files
authored
Fixed price shift for non-CET price area (#1090)
* Fixed non-CET price presentation * Added compiled version * Updated fix for non cet * Fixed! I think...
1 parent fc6e9e8 commit 2e4a0fc

File tree

7 files changed

+32
-29
lines changed

7 files changed

+32
-29
lines changed

lib/PriceService/include/PriceService.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class PriceService {
136136
bool retrieve(const char* url, Stream* doc);
137137
float getCurrencyMultiplier(const char* from, const char* to, time_t t);
138138
bool timeIsInPeriod(tmElements_t tm, PriceConfig pc);
139-
float getFixedPrice(uint8_t direction, int8_t hour);
139+
float getFixedPrice(uint8_t direction, int8_t point);
140140
float getEnergyPricePoint(uint8_t direction, uint8_t point);
141141
};
142142
#endif

lib/PriceService/src/PriceService.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,16 @@ bool PriceService::isExportPricesDifferentFromImport() {
127127
}
128128

129129
float PriceService::getPricePoint(uint8_t direction, uint8_t point) {
130-
float value = getFixedPrice(direction, point * getResolutionInMinutes() / 60);
130+
float value = getFixedPrice(direction, point);
131131
if(value == PRICE_NO_VALUE) value = getEnergyPricePoint(direction, point);
132132
if(value == PRICE_NO_VALUE) return PRICE_NO_VALUE;
133133

134134
tmElements_t tm;
135135
time_t ts = time(nullptr);
136-
breakTime(tz->toLocal(ts), tm);
136+
breakTime(entsoeTz->toLocal(ts), tm);
137137
tm.Hour = tm.Minute = tm.Second = 0;
138-
breakTime(makeTime(tm) + (point * SECS_PER_MIN * getResolutionInMinutes()), tm);
138+
ts = entsoeTz->toUTC(makeTime(tm)) + (point * SECS_PER_MIN * getResolutionInMinutes());
139+
breakTime(tz->toLocal(ts), tm);
139140

140141
for (uint8_t i = 0; i < priceConfig.size(); i++) {
141142
PriceConfig pc = priceConfig.at(i);
@@ -162,15 +163,14 @@ float PriceService::getPricePoint(uint8_t direction, uint8_t point) {
162163

163164
float PriceService::getCurrentPrice(uint8_t direction) {
164165
time_t ts = time(nullptr);
165-
tmElements_t tm;
166-
breakTime(tz->toLocal(ts), tm);
167166
uint8_t pos = getCurrentPricePointIndex();
168167

169168
return getPricePoint(direction, pos);
170169
}
171170

172171
float PriceService::getEnergyPricePoint(uint8_t direction, uint8_t point) {
173172
uint8_t pos = point;
173+
174174
float multiplier = 1.0;
175175
uint8_t numberOfPointsToday = 24;
176176
if(today != NULL) {
@@ -206,10 +206,10 @@ float PriceService::getPriceForRelativeHour(uint8_t direction, int8_t hour) {
206206
time_t ts = time(nullptr);
207207
tmElements_t tm;
208208

209-
breakTime(tz->toLocal(ts), tm);
210-
int8_t targetHour = tm.Hour + hour;
209+
breakTime(entsoeTz->toLocal(ts), tm);
210+
uint8_t targetHour = tm.Hour + hour;
211211
tm.Hour = tm.Minute = tm.Second = 0;
212-
time_t startOfDay = tz->toUTC(makeTime(tm));
212+
time_t startOfDay = entsoeTz->toUTC(makeTime(tm));
213213

214214
if((ts + (hour * SECS_PER_HOUR)) < startOfDay) {
215215
return PRICE_NO_VALUE;
@@ -235,15 +235,15 @@ float PriceService::getPriceForRelativeHour(uint8_t direction, int8_t hour) {
235235
return valueSum / valueCount;
236236
}
237237

238-
float PriceService::getFixedPrice(uint8_t direction, int8_t hour) {
238+
float PriceService::getFixedPrice(uint8_t direction, int8_t point) {
239239
time_t ts = time(nullptr);
240240

241241
tmElements_t tm;
242+
breakTime(entsoeTz->toLocal(ts), tm);
243+
tm.Hour = tm.Minute = tm.Second = 0;
244+
ts = entsoeTz->toUTC(makeTime(tm)) + (point * SECS_PER_MIN * getResolutionInMinutes());
242245
breakTime(tz->toLocal(ts), tm);
243-
tm.Hour = hour;
244-
tm.Minute = 0;
245-
tm.Second = 0;
246-
breakTime(makeTime(tm), tm);
246+
tm.Minute = tm.Second = 0;
247247

248248
float value = PRICE_NO_VALUE;
249249
for (uint8_t i = 0; i < priceConfig.size(); i++) {
@@ -760,6 +760,6 @@ bool PriceService::timeIsInPeriod(tmElements_t tm, PriceConfig pc) {
760760
uint8_t PriceService::getCurrentPricePointIndex() {
761761
time_t ts = time(nullptr);
762762
tmElements_t tm;
763-
breakTime(tz->toLocal(ts), tm);
763+
breakTime(entsoeTz->toLocal(ts), tm);
764764
return ((tm.Hour * 60) + tm.Minute) / getResolutionInMinutes();
765765
}

lib/SvelteUi/app/dist/index.js

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/SvelteUi/app/src/lib/BarChart.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
{#each config.x.ticks as point, i}
7474
{#if !isNaN(xScale(i))}
7575
<g class="tick" transform="translate({xScale(i)},{heightAvailable})">
76-
{#if barWidth > 20 || i%2 == 0}
76+
{#if barWidth > 20 || i%2 == 0 || !config.x.ticks[i-1].label}
7777
<text x="{barWidth/2}" y="-4">{point.label}</text>
7878
{/if}
7979
</g>

lib/SvelteUi/app/src/lib/Dashboard.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,17 @@
140140
{#if uiVisibility(sysinfo.ui.p, data.p && !Number.isNaN(data.p))}
141141
{#if importPrices?.importExportPriceDifferent && (data.om || data.e > 0)}
142142
<div class="cnt gwf">
143-
<PricePlot title="{translations.dashboard?.price_import ?? "Price import"}" json={importPrices}/>
143+
<PricePlot title="{translations.dashboard?.price_import ?? "Price import"}" json={importPrices} sysinfo={sysinfo}/>
144144
</div>
145145
{:else}
146146
<div class="cnt gwf">
147-
<PricePlot title={translations.dashboard?.price ?? "Price"} json={importPrices}/>
147+
<PricePlot title={translations.dashboard?.price ?? "Price"} json={importPrices} sysinfo={sysinfo}/>
148148
</div>
149149
{/if}
150150
{/if}
151151
{#if importPrices?.importExportPriceDifferent && (data.om || data.e > 0) && uiVisibility(sysinfo.ui.p, data.pe && !Number.isNaN(data.pe))}
152152
<div class="cnt gwf">
153-
<PricePlot title={translations.dashboard?.price_export ?? "Price export"} json={exportPrices}/>
153+
<PricePlot title={translations.dashboard?.price_export ?? "Price export"} json={exportPrices} sysinfo={sysinfo}/>
154154
</div>
155155
{/if}
156156
{#if uiVisibility(sysinfo.ui.d, dayPlot)}

lib/SvelteUi/app/src/lib/PricePlot.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
66
export let title;
77
export let json;
8+
export let sysinfo;
89
910
let config = {};
1011
let max;
@@ -39,7 +40,8 @@
3940
let xTicks = [];
4041
let values = [];
4142
min = max = 0;
42-
let i = Math.floor(((cur.getHours()*60) + cur.getMinutes()) / json?.resolution);
43+
addHours(cur, sysinfo.clock_offset - ((24 + cur.getHours() - cur.getUTCHours())%24));
44+
let i = json?.cursor ? json.cursor : 0;
4345
cur.setMinutes(Math.floor(cur.getMinutes()/json?.resolution)*json?.resolution,0,0);
4446
while(i < json?.prices?.length) {
4547
val = json.prices[i];

lib/SvelteUi/src/AmsWebServer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,11 +777,12 @@ void AmsWebServer::priceJson(uint8_t direction) {
777777
prices[i] = ps->getPricePoint(direction, i);
778778
}
779779

780-
snprintf_P(buf, BufferSize, PSTR("{\"currency\":\"%s\",\"source\":\"%s\",\"resolution\":%d,\"direction\":\"%s\",\"importExportPriceDifferent\":%s,\"prices\":["),
780+
snprintf_P(buf, BufferSize, PSTR("{\"currency\":\"%s\",\"source\":\"%s\",\"resolution\":%d,\"direction\":\"%s\",\"cursor\":%d,\"importExportPriceDifferent\":%s,\"prices\":["),
781781
ps->getCurrency(),
782782
ps->getSource(),
783783
ps->getResolutionInMinutes(),
784784
direction == PRICE_DIRECTION_IMPORT ? "import" : direction == PRICE_DIRECTION_EXPORT ? "export" : "both",
785+
ps->getCurrentPricePointIndex(),
785786
ps->isExportPricesDifferentFromImport() ? "true" : "false"
786787
);
787788

0 commit comments

Comments
 (0)