Forecast: solar adjust details (#19724)

This commit is contained in:
Michael Geers 2025-03-14 09:52:35 +01:00 • committed by GitHub
parent 10c0028a97
commit 5ef4b50e1f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 45 additions and 14 deletions

View file

@ -396,7 +396,12 @@ export default {
return !!this.forecast?.solar;
},
solarForecastRemainingToday() {
return this.forecast?.solar?.today?.energy || undefined;
if (!this.forecast?.solar) {
return undefined;
}
const { today, scale } = this.forecast.solar || {};
const factor = this.$hiddenFeatures() && settings.solarAdjusted && scale ? scale : 1;
return today.energy * factor;
},
solarForecastIcon() {
return this.solarForecastExists ? "forecast" : undefined;

View file

@ -40,7 +40,7 @@
/>
<div class="form-check-label">
<label for="solarForecastAdjust"
><small>🧪 {{ $t("forecast.solarAdjust") }}</small></label
><small>🧪 {{ solarAdjustText }}</small></label
>
</div>
</div>
@ -104,6 +104,17 @@ export default defineComponent({
? adjustedSolar(this.forecast.solar)
: this.forecast.solar;
},
solarAdjustText() {
let percent = "";
const scale = this.forecast.solar?.scale;
if (scale) {
const percentDiff = scale * 100 - 100;
percent = ` (${this.fmtPercentage(percentDiff, 0, true)})`;
}
return this.$t("forecast.solarAdjust", { percent });
},
},
watch: {
isModalVisible: function (newVal) {

View file

@ -341,12 +341,13 @@ export default {
}
return result;
},
fmtPercentage: function (value, digits = 0) {
return new Intl.NumberFormat(this.$i18n?.locale, {
fmtPercentage: function (value, digits = 0, forceSign = false) {
const sign = forceSign && value > 0 ? "+" : "";
return `${sign}${new Intl.NumberFormat(this.$i18n?.locale, {
style: "percent",
minimumFractionDigits: digits,
maximumFractionDigits: digits,
}).format(value / 100);
}).format(value / 100)}`;
},
hasLeadingPercentageSign: function () {
return ["tr", "ar"].includes(this.$i18n?.locale);

View file

@ -169,3 +169,17 @@ describe("getShortenedWeekdaysLabel", () => {
expect(fmt.getShortenedWeekdaysLabel([0, 2, 3, 5, 6])).eq("Di, Mi, Fr – So");
});
});
describe("fmtPercentage", () => {
test("should format percentage", () => {
expect(fmt.fmtPercentage(0)).eq("0 %");
expect(fmt.fmtPercentage(100)).eq("100 %");
expect(fmt.fmtPercentage(100, 1)).eq("100,0 %");
});
test("should force signed", () => {
expect(fmt.fmtPercentage(100, 0, true)).eq("+100 %");
expect(fmt.fmtPercentage(100, 0, false)).eq("100 %");
expect(fmt.fmtPercentage(-100, 0, true)).eq("-100 %");
expect(fmt.fmtPercentage(-100, 0, false)).eq("-100 %");
});
});

View file

@ -438,7 +438,7 @@ modalUpdateStatusStart = "Installation gestartet:"
[forecast]
modalTitle = "Vorhersage"
solarAdjust = "Solarprognose anhand der realen Produktionsdaten anpassen."
solarAdjust = "Solarprognose anhand der realen Produktionsdaten anpassen{percent}."
[forecast.co2]
average = "Durchschnitt"

View file

@ -437,7 +437,7 @@ modalUpdateStatusStart = "Installation started:"
[forecast]
modalTitle = "Forecast"
solarAdjust = "Adjust solar forecast based on real production data."
solarAdjust = "Adjust solar forecast based on real production data{percent}."
[forecast.co2]
average = "Average"

View file

@ -450,7 +450,7 @@ modalUpdateStatusStart = "L'installation a commencé:"
[forecast]
modalTitle = "Prévisions"
solarAdjust = "Ajuster la prévision solaire basé sur la production réelle."
solarAdjust = "Ajuster la prévision solaire basé sur la production réelle{percent}."
[forecast.co2]
average = "Moyenne"

View file

@ -443,7 +443,7 @@ modalUpdateStatusStart = "Installatioun ugefaang:"
[forecast]
modalTitle = "Prognose"
solarAdjust = "Solarprognose unhand vun de reale Produktionsdaten upassen."
solarAdjust = "Solarprognose unhand vun de reale Produktionsdaten upassen{percent}."
[forecast.co2]
average = "Moyenne"

View file

@ -450,7 +450,7 @@ modalUpdateStatusStart = "Instaliavimas pradėtas:"
[forecast]
modalTitle = "Prognozė"
solarAdjust = "Pakoreguoti saulės prognozę remiantis faktiškais gamybos duomenimis."
solarAdjust = "Pakoreguoti saulės prognozę remiantis faktiškais gamybos duomenimis{percent}."
[forecast.co2]
average = "Vidurkis"

View file

@ -446,7 +446,7 @@ modalUpdateStatusStart = "Instalação iniciada:"
[forecast]
modalTitle = "Previsões"
solarAdjust = "Ajustar a previsão solar com base em dados reais de produção."
solarAdjust = "Ajustar a previsão solar com base em dados reais de produção{percent}."
[forecast.co2]
average = "Média"

View file

@ -450,7 +450,7 @@ modalUpdateStatusStart = "Installationen har börjat:"
[forecast]
modalTitle = "Prognos"
solarAdjust = "Justera solprognosen baserat på verkliga produktionsvärden."
solarAdjust = "Justera solprognosen baserat på verkliga produktionsvärden{percent}."
[forecast.co2]
average = "Genomsnitt"

View file

@ -437,7 +437,7 @@ modalUpdateStatusStart = "Kurulum başladı:"
[forecast]
modalTitle = "“Öngörü”"
solarAdjust = "Güneş enerjisi tahminlerini gerçek üretim verilerine göre ayarla."
solarAdjust = "Güneş enerjisi tahminlerini gerçek üretim verilerine göre ayarla{percent}."
[forecast.co2]
average = "“Ortalama”"

View file

@ -451,7 +451,7 @@ modalUpdateStatusStart = "Встановлення розпочато:"
[forecast]
modalTitle = "Прогноз"
solarAdjust = "Скоригуйте сонячний прогноз на основі реальних даних виробництва."
solarAdjust = "Скоригуйте сонячний прогноз на основі реальних даних виробництва{percent}."
[forecast.co2]
average = "Середній"