Skip to content

Commit 5ef4b50

Browse files
authored
Forecast: solar adjust details (#19724)
1 parent 10c0028 commit 5ef4b50

File tree

13 files changed

+45
-14
lines changed

13 files changed

+45
-14
lines changed

assets/js/components/Energyflow/Energyflow.vue

+6-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,12 @@ export default {
396396
return !!this.forecast?.solar;
397397
},
398398
solarForecastRemainingToday() {
399-
return this.forecast?.solar?.today?.energy || undefined;
399+
if (!this.forecast?.solar) {
400+
return undefined;
401+
}
402+
const { today, scale } = this.forecast.solar || {};
403+
const factor = this.$hiddenFeatures() && settings.solarAdjusted && scale ? scale : 1;
404+
return today.energy * factor;
400405
},
401406
solarForecastIcon() {
402407
return this.solarForecastExists ? "forecast" : undefined;

assets/js/components/Forecast/ForecastModal.vue

+12-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
/>
4141
<div class="form-check-label">
4242
<label for="solarForecastAdjust"
43-
><small>🧪 {{ $t("forecast.solarAdjust") }}</small></label
43+
><small>🧪 {{ solarAdjustText }}</small></label
4444
>
4545
</div>
4646
</div>
@@ -104,6 +104,17 @@ export default defineComponent({
104104
? adjustedSolar(this.forecast.solar)
105105
: this.forecast.solar;
106106
},
107+
solarAdjustText() {
108+
let percent = "";
109+
110+
const scale = this.forecast.solar?.scale;
111+
if (scale) {
112+
const percentDiff = scale * 100 - 100;
113+
percent = ` (${this.fmtPercentage(percentDiff, 0, true)})`;
114+
}
115+
116+
return this.$t("forecast.solarAdjust", { percent });
117+
},
107118
},
108119
watch: {
109120
isModalVisible: function (newVal) {

assets/js/mixins/formatter.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,13 @@ export default {
341341
}
342342
return result;
343343
},
344-
fmtPercentage: function (value, digits = 0) {
345-
return new Intl.NumberFormat(this.$i18n?.locale, {
344+
fmtPercentage: function (value, digits = 0, forceSign = false) {
345+
const sign = forceSign && value > 0 ? "+" : "";
346+
return `${sign}${new Intl.NumberFormat(this.$i18n?.locale, {
346347
style: "percent",
347348
minimumFractionDigits: digits,
348349
maximumFractionDigits: digits,
349-
}).format(value / 100);
350+
}).format(value / 100)}`;
350351
},
351352
hasLeadingPercentageSign: function () {
352353
return ["tr", "ar"].includes(this.$i18n?.locale);

assets/js/mixins/formatter.test.js

+14
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,17 @@ describe("getShortenedWeekdaysLabel", () => {
169169
expect(fmt.getShortenedWeekdaysLabel([0, 2, 3, 5, 6])).eq("Di, Mi, Fr – So");
170170
});
171171
});
172+
173+
describe("fmtPercentage", () => {
174+
test("should format percentage", () => {
175+
expect(fmt.fmtPercentage(0)).eq("0 %");
176+
expect(fmt.fmtPercentage(100)).eq("100 %");
177+
expect(fmt.fmtPercentage(100, 1)).eq("100,0 %");
178+
});
179+
test("should force signed", () => {
180+
expect(fmt.fmtPercentage(100, 0, true)).eq("+100 %");
181+
expect(fmt.fmtPercentage(100, 0, false)).eq("100 %");
182+
expect(fmt.fmtPercentage(-100, 0, true)).eq("-100 %");
183+
expect(fmt.fmtPercentage(-100, 0, false)).eq("-100 %");
184+
});
185+
});

i18n/de.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ modalUpdateStatusStart = "Installation gestartet:"
438438

439439
[forecast]
440440
modalTitle = "Vorhersage"
441-
solarAdjust = "Solarprognose anhand der realen Produktionsdaten anpassen."
441+
solarAdjust = "Solarprognose anhand der realen Produktionsdaten anpassen{percent}."
442442

443443
[forecast.co2]
444444
average = "Durchschnitt"

i18n/en.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ modalUpdateStatusStart = "Installation started:"
437437

438438
[forecast]
439439
modalTitle = "Forecast"
440-
solarAdjust = "Adjust solar forecast based on real production data."
440+
solarAdjust = "Adjust solar forecast based on real production data{percent}."
441441

442442
[forecast.co2]
443443
average = "Average"

i18n/fr.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ modalUpdateStatusStart = "L'installation a commencé:"
450450

451451
[forecast]
452452
modalTitle = "Prévisions"
453-
solarAdjust = "Ajuster la prévision solaire basé sur la production réelle."
453+
solarAdjust = "Ajuster la prévision solaire basé sur la production réelle{percent}."
454454

455455
[forecast.co2]
456456
average = "Moyenne"

i18n/lb.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ modalUpdateStatusStart = "Installatioun ugefaang:"
443443

444444
[forecast]
445445
modalTitle = "Prognose"
446-
solarAdjust = "Solarprognose unhand vun de reale Produktionsdaten upassen."
446+
solarAdjust = "Solarprognose unhand vun de reale Produktionsdaten upassen{percent}."
447447

448448
[forecast.co2]
449449
average = "Moyenne"

i18n/lt.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ modalUpdateStatusStart = "Instaliavimas pradėtas:"
450450

451451
[forecast]
452452
modalTitle = "Prognozė"
453-
solarAdjust = "Pakoreguoti saulės prognozę remiantis faktiškais gamybos duomenimis."
453+
solarAdjust = "Pakoreguoti saulės prognozę remiantis faktiškais gamybos duomenimis{percent}."
454454

455455
[forecast.co2]
456456
average = "Vidurkis"

i18n/pt.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ modalUpdateStatusStart = "Instalação iniciada:"
446446

447447
[forecast]
448448
modalTitle = "Previsões"
449-
solarAdjust = "Ajustar a previsão solar com base em dados reais de produção."
449+
solarAdjust = "Ajustar a previsão solar com base em dados reais de produção{percent}."
450450

451451
[forecast.co2]
452452
average = "Média"

i18n/sv.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ modalUpdateStatusStart = "Installationen har börjat:"
450450

451451
[forecast]
452452
modalTitle = "Prognos"
453-
solarAdjust = "Justera solprognosen baserat på verkliga produktionsvärden."
453+
solarAdjust = "Justera solprognosen baserat på verkliga produktionsvärden{percent}."
454454

455455
[forecast.co2]
456456
average = "Genomsnitt"

i18n/tr.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ modalUpdateStatusStart = "Kurulum başladı:"
437437

438438
[forecast]
439439
modalTitle = "“Öngörü”"
440-
solarAdjust = "Güneş enerjisi tahminlerini gerçek üretim verilerine göre ayarla."
440+
solarAdjust = "Güneş enerjisi tahminlerini gerçek üretim verilerine göre ayarla{percent}."
441441

442442
[forecast.co2]
443443
average = "“Ortalama”"

i18n/uk.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ modalUpdateStatusStart = "Встановлення розпочато:"
451451

452452
[forecast]
453453
modalTitle = "Прогноз"
454-
solarAdjust = "Скоригуйте сонячний прогноз на основі реальних даних виробництва."
454+
solarAdjust = "Скоригуйте сонячний прогноз на основі реальних даних виробництва{percent}."
455455

456456
[forecast.co2]
457457
average = "Середній"

0 commit comments

Comments
 (0)