Add support for megawatt (#15818)
This commit is contained in:
parent
06e2b16145
commit
536712dab3
19 changed files with 179 additions and 99 deletions
|
|
@ -256,7 +256,7 @@ import "@h2d2/shopicons/es/regular/home";
|
|||
import SmartCostLimit from "./SmartCostLimit.vue";
|
||||
import CustomSelect from "./CustomSelect.vue";
|
||||
import GenericModal from "./GenericModal.vue";
|
||||
import formatter from "../mixins/formatter";
|
||||
import formatter, { POWER_UNIT } from "../mixins/formatter";
|
||||
import collector from "../mixins/collector";
|
||||
import api from "../api";
|
||||
import smartCostAvailable from "../utils/smartCostAvailable";
|
||||
|
|
@ -363,13 +363,13 @@ export default {
|
|||
.filter(({ capacity }) => capacity > 0)
|
||||
.map(({ soc, capacity }) => {
|
||||
const multipleBatteries = this.battery.length > 1;
|
||||
const energy = this.fmtKWh(
|
||||
const energy = this.fmtWh(
|
||||
(capacity / 100) * soc * 1e3,
|
||||
true,
|
||||
POWER_UNIT.KW,
|
||||
!multipleBatteries,
|
||||
1
|
||||
);
|
||||
const total = this.fmtKWh(capacity * 1e3, true, true, 1);
|
||||
const total = this.fmtWh(capacity * 1e3, POWER_UNIT.KW, true, 1);
|
||||
const name = multipleBatteries ? "↳ " : "";
|
||||
const formattedSoc = multipleBatteries ? ` (${this.fmtSoc(soc)})` : "";
|
||||
const formattedEnergy = this.$t("batterySettings.capacity", {
|
||||
|
|
|
|||
|
|
@ -196,7 +196,7 @@ export default {
|
|||
return fmtEnergy(
|
||||
this.planEnergy,
|
||||
optionStep(this.capacity || 100),
|
||||
this.fmtKWh,
|
||||
this.fmtWh,
|
||||
this.$t("main.targetEnergy.noLimit")
|
||||
);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ export default {
|
|||
},
|
||||
fmtPower() {
|
||||
if (this.duration > 0 && this.power > 0) {
|
||||
return `@ ${this.fmtKw(this.power)}`;
|
||||
return `@ ${this.fmtW(this.power)}`;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ export default {
|
|||
0,
|
||||
this.capacity || 100,
|
||||
this.socPerKwh,
|
||||
this.fmtKWh,
|
||||
this.fmtWh,
|
||||
this.fmtPercentage,
|
||||
"-"
|
||||
);
|
||||
|
|
|
|||
|
|
@ -100,13 +100,13 @@ export default {
|
|||
if (this.socBasedPlanning) {
|
||||
return this.fmtSoc(this.effectiveLimitSoc);
|
||||
}
|
||||
return this.fmtKWh(this.limitEnergy * 1e3);
|
||||
return this.fmtWh(this.limitEnergy * 1e3);
|
||||
},
|
||||
goalFmt: function () {
|
||||
if (this.socBasedPlanning) {
|
||||
return this.fmtSoc(this.effectivePlanSoc);
|
||||
}
|
||||
return this.fmtKWh(this.planEnergy * 1e3);
|
||||
return this.fmtWh(this.planEnergy * 1e3);
|
||||
},
|
||||
costLimitExists: function () {
|
||||
return this.smartCostLimit !== 0;
|
||||
|
|
|
|||
|
|
@ -68,10 +68,17 @@
|
|||
{{ $t("sessions.energy") }}
|
||||
</th>
|
||||
<td>
|
||||
{{ fmtKWh(chargedEnergy, chargedEnergy >= 1e3) }}
|
||||
{{
|
||||
fmtWh(
|
||||
chargedEnergy,
|
||||
chargedEnergy >= 1e3
|
||||
? POWER_UNIT.KW
|
||||
: POWER_UNIT.AUTO
|
||||
)
|
||||
}}
|
||||
<div v-if="session.chargeDuration">
|
||||
{{ fmtDurationNs(session.chargeDuration) }}
|
||||
(~{{ fmtKw(avgPower) }})
|
||||
(~{{ fmtW(avgPower) }})
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
@ -81,7 +88,7 @@
|
|||
</th>
|
||||
<td>
|
||||
{{ fmtPercentage(session.solarPercentage, 1) }}
|
||||
({{ fmtKWh(solarEnergy, solarEnergy >= 1e3) }})
|
||||
({{ fmtWh(solarEnergy, POWER_UNIT.AUTO) }})
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="session.price != null">
|
||||
|
|
@ -115,8 +122,8 @@
|
|||
{{ $t("session.meter") }}
|
||||
</th>
|
||||
<td>
|
||||
{{ fmtKWh(session.meterStart * 1e3) }}<br />
|
||||
{{ fmtKWh(session.meterStop * 1e3) }}
|
||||
{{ fmtWh(session.meterStart * 1e3) }}<br />
|
||||
{{ fmtWh(session.meterStop * 1e3) }}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
|
|
|||
|
|
@ -48,11 +48,11 @@ export default {
|
|||
}
|
||||
switch (name) {
|
||||
case "power":
|
||||
return this.fmtKw(value);
|
||||
return this.fmtW(value);
|
||||
case "energy":
|
||||
case "capacity":
|
||||
case "chargedEnergy":
|
||||
return this.fmtKWh(value * 1e3);
|
||||
return this.fmtWh(value * 1e3);
|
||||
case "soc":
|
||||
case "socLimit":
|
||||
return this.fmtPercentage(value, 1);
|
||||
|
|
@ -66,7 +66,7 @@ export default {
|
|||
case "phaseVoltages":
|
||||
return value.map((v) => this.fmtNumber(v, 0)).join(" ") + " V";
|
||||
case "phasePowers":
|
||||
return value.map((v) => this.fmtKw(v)).join(", ");
|
||||
return value.map((v) => this.fmtW(v)).join(", ");
|
||||
case "chargeStatus":
|
||||
return this.$t(`config.deviceValue.chargeStatus${value}`);
|
||||
case "gridPrice":
|
||||
|
|
@ -75,7 +75,7 @@ export default {
|
|||
case "co2":
|
||||
return this.fmtCo2Short(value);
|
||||
case "powerRange":
|
||||
return `${this.fmtKw(value[0])} / ${this.fmtKw(value[1])}`;
|
||||
return `${this.fmtW(value[0])} / ${this.fmtW(value[1])}`;
|
||||
case "currentRange":
|
||||
return `${this.fmtNumber(value[0], 1)} A / ${this.fmtNumber(value[1], 1)} A`;
|
||||
case "controllable":
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
:pvProduction="pvProduction"
|
||||
:homePower="homePower"
|
||||
:batterySoc="batterySoc"
|
||||
:powerInKw="powerInKw"
|
||||
:powerUnit="powerUnit"
|
||||
:vehicleIcons="vehicleIcons"
|
||||
/>
|
||||
</div>
|
||||
|
|
@ -79,7 +79,7 @@
|
|||
icon="sun"
|
||||
:power="pvProduction"
|
||||
:powerTooltip="pvTooltip"
|
||||
:powerInKw="powerInKw"
|
||||
:powerUnit="powerUnit"
|
||||
data-testid="energyflow-entry-production"
|
||||
/>
|
||||
<EnergyflowEntry
|
||||
|
|
@ -87,7 +87,7 @@
|
|||
:name="batteryDischargeLabel"
|
||||
icon="battery"
|
||||
:power="batteryDischarge"
|
||||
:powerInKw="powerInKw"
|
||||
:powerUnit="powerUnit"
|
||||
:soc="batterySoc"
|
||||
:details="batterySoc"
|
||||
:detailsFmt="batteryFmt"
|
||||
|
|
@ -99,7 +99,7 @@
|
|||
:name="$t('main.energyflow.gridImport')"
|
||||
icon="powersupply"
|
||||
:power="gridImport"
|
||||
:powerInKw="powerInKw"
|
||||
:powerUnit="powerUnit"
|
||||
:details="detailsValue(tariffGrid, tariffCo2)"
|
||||
:detailsFmt="detailsFmt"
|
||||
:detailsTooltip="detailsTooltip(tariffGrid, tariffCo2)"
|
||||
|
|
@ -122,7 +122,7 @@
|
|||
:name="$t('main.energyflow.homePower')"
|
||||
icon="home"
|
||||
:power="homePower"
|
||||
:powerInKw="powerInKw"
|
||||
:powerUnit="powerUnit"
|
||||
:details="detailsValue(tariffPriceHome, tariffCo2Home)"
|
||||
:detailsFmt="detailsFmt"
|
||||
:detailsTooltip="detailsTooltip(tariffPriceHome, tariffCo2Home)"
|
||||
|
|
@ -137,7 +137,7 @@
|
|||
icon="vehicle"
|
||||
:vehicleIcons="vehicleIcons"
|
||||
:power="loadpointsPower"
|
||||
:powerInKw="powerInKw"
|
||||
:powerUnit="powerUnit"
|
||||
:details="
|
||||
activeLoadpointsCount
|
||||
? detailsValue(tariffPriceLoadpoints, tariffCo2Loadpoints)
|
||||
|
|
@ -154,7 +154,7 @@
|
|||
:name="batteryChargeLabel"
|
||||
icon="battery"
|
||||
:power="batteryCharge"
|
||||
:powerInKw="powerInKw"
|
||||
:powerUnit="powerUnit"
|
||||
:soc="batterySoc"
|
||||
:details="batterySoc"
|
||||
:detailsFmt="batteryFmt"
|
||||
|
|
@ -176,7 +176,7 @@
|
|||
:name="$t('main.energyflow.pvExport')"
|
||||
icon="powersupply"
|
||||
:power="pvExport"
|
||||
:powerInKw="powerInKw"
|
||||
:powerUnit="powerUnit"
|
||||
:details="detailsValue(-tariffFeedIn)"
|
||||
:detailsFmt="detailsFmt"
|
||||
:detailsTooltip="detailsTooltip(-tariffFeedIn)"
|
||||
|
|
@ -194,7 +194,7 @@ import "@h2d2/shopicons/es/filled/square";
|
|||
import Modal from "bootstrap/js/dist/modal";
|
||||
import Visualization from "./Visualization.vue";
|
||||
import EnergyflowEntry from "./EnergyflowEntry.vue";
|
||||
import formatter from "../../mixins/formatter";
|
||||
import formatter, { POWER_UNIT } from "../../mixins/formatter";
|
||||
import AnimatedNumber from "../AnimatedNumber.vue";
|
||||
import settings from "../../settings";
|
||||
import { CO2_TYPE } from "../../units";
|
||||
|
|
@ -292,8 +292,15 @@ export default {
|
|||
pvExport: function () {
|
||||
return Math.max(0, this.gridPower * -1);
|
||||
},
|
||||
powerInKw: function () {
|
||||
return Math.max(this.gridImport, this.selfPv, this.selfBattery, this.pvExport) >= 1000;
|
||||
powerUnit: function () {
|
||||
const watt = Math.max(this.gridImport, this.selfPv, this.selfBattery, this.pvExport);
|
||||
if (watt >= 1_000_000) {
|
||||
return POWER_UNIT.MW;
|
||||
} else if (watt >= 1000) {
|
||||
return POWER_UNIT.KW;
|
||||
} else {
|
||||
return POWER_UNIT.W;
|
||||
}
|
||||
},
|
||||
inPower: function () {
|
||||
return this.gridImport + this.pvProduction + this.batteryDischarge;
|
||||
|
|
@ -308,7 +315,7 @@ export default {
|
|||
if (!Array.isArray(this.pv) || this.pv.length <= 1) {
|
||||
return;
|
||||
}
|
||||
return this.pv.map(({ power }) => this.fmtKw(power, this.powerInKw));
|
||||
return this.pv.map(({ power }) => this.fmtW(power, this.powerUnit));
|
||||
},
|
||||
batteryFmt() {
|
||||
return (soc) => this.fmtPercentage(soc, 0);
|
||||
|
|
@ -386,7 +393,7 @@ export default {
|
|||
return this.fmtPricePerKWh(value, this.currency, true);
|
||||
},
|
||||
kw: function (watt) {
|
||||
return this.fmtKw(watt, this.powerInKw);
|
||||
return this.fmtW(watt, this.powerUnit);
|
||||
},
|
||||
toggleDetails: function () {
|
||||
this.updateHeight();
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ export default {
|
|||
vehicleIcons: { type: Array },
|
||||
power: { type: Number },
|
||||
powerTooltip: { type: Array },
|
||||
powerInKw: { type: Boolean },
|
||||
powerUnit: { type: String },
|
||||
soc: { type: Number },
|
||||
details: { type: Number },
|
||||
detailsFmt: { type: Function },
|
||||
|
|
@ -98,7 +98,7 @@ export default {
|
|||
},
|
||||
methods: {
|
||||
kw: function (watt) {
|
||||
return this.fmtKw(watt, this.powerInKw);
|
||||
return this.fmtW(watt, this.powerUnit);
|
||||
},
|
||||
updatePowerTooltip() {
|
||||
this.powerTooltipInstance = this.updateTooltip(
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@
|
|||
/>
|
||||
</div>
|
||||
<div v-if="totalAdjusted <= 0" class="site-progress-bar w-100 grid-import">
|
||||
<span>{{ fmtKw(0, false, true) }}</span>
|
||||
<span>{{ fmtW(0, POWER_UNIT.AUTO, true) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="label-scale d-flex">
|
||||
|
|
@ -89,7 +89,7 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import formatter from "../../mixins/formatter";
|
||||
import formatter, { POWER_UNIT } from "../../mixins/formatter";
|
||||
import BatteryIcon from "./BatteryIcon.vue";
|
||||
import LabelBar from "./LabelBar.vue";
|
||||
import AnimatedNumber from "../AnimatedNumber.vue";
|
||||
|
|
@ -112,7 +112,7 @@ export default {
|
|||
pvProduction: { type: Number, default: 0 },
|
||||
homePower: { type: Number, default: 0 },
|
||||
batterySoc: { type: Number, default: 0 },
|
||||
powerInKw: { type: Boolean, default: false },
|
||||
powerUnit: { type: String, default: POWER_UNIT.KW },
|
||||
},
|
||||
data: function () {
|
||||
return { width: 0 };
|
||||
|
|
@ -168,7 +168,7 @@ export default {
|
|||
return "";
|
||||
}
|
||||
const withUnit = this.enoughSpaceForUnit(watt);
|
||||
return this.fmtKw(watt, this.powerInKw, withUnit);
|
||||
return this.fmtW(watt, this.powerUnit, withUnit);
|
||||
},
|
||||
powerLabelAvailableSpace(power) {
|
||||
if (this.totalAdjusted === 0) return 0;
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ export default {
|
|||
this.chargedEnergy,
|
||||
this.capacity || 100,
|
||||
this.socPerKwh,
|
||||
this.fmtKWh,
|
||||
this.fmtWh,
|
||||
this.fmtPercentage,
|
||||
this.$t("main.targetEnergy.noLimit")
|
||||
);
|
||||
|
|
@ -73,7 +73,7 @@ export default {
|
|||
return this.$emit("limit-energy-updated", parseFloat(e.target.value));
|
||||
},
|
||||
fmtEnergy: function (value) {
|
||||
return fmtEnergy(value, this.step, this.fmtKWh, this.$t("main.targetEnergy.noLimit"));
|
||||
return fmtEnergy(value, this.step, this.fmtWh, this.$t("main.targetEnergy.noLimit"));
|
||||
},
|
||||
fmtSoc: function (value) {
|
||||
return `+${this.fmtPercentage(value)}`;
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ import Mode from "./Mode.vue";
|
|||
import Vehicle from "./Vehicle.vue";
|
||||
import Phases from "./Phases.vue";
|
||||
import LabelAndValue from "./LabelAndValue.vue";
|
||||
import formatter from "../mixins/formatter";
|
||||
import formatter, { POWER_UNIT } from "../mixins/formatter";
|
||||
import collector from "../mixins/collector";
|
||||
import LoadpointSettingsButton from "./LoadpointSettingsButton.vue";
|
||||
import LoadpointSettingsModal from "./LoadpointSettingsModal.vue";
|
||||
|
|
@ -337,12 +337,10 @@ export default {
|
|||
api.delete(this.apiPath("vehicle"));
|
||||
},
|
||||
fmtPower(value) {
|
||||
const inKw = value == 0 || value >= 1000;
|
||||
return this.fmtKw(value, inKw);
|
||||
return this.fmtW(value, POWER_UNIT.AUTO);
|
||||
},
|
||||
fmtEnergy(value) {
|
||||
const inKw = value == 0 || value >= 1000;
|
||||
return this.fmtKWh(value, inKw);
|
||||
return this.fmtWh(value, POWER_UNIT.AUTO);
|
||||
},
|
||||
openSettingsModal() {
|
||||
const modal = Modal.getOrCreateInstance(
|
||||
|
|
|
|||
|
|
@ -220,7 +220,7 @@ export default {
|
|||
return this.maxPowerPhases(this.phasesConfigured);
|
||||
}
|
||||
}
|
||||
return this.fmtKw(this.maxCurrent * V * this.phasesActive);
|
||||
return this.fmtW(this.maxCurrent * V * this.phasesActive);
|
||||
},
|
||||
minPower: function () {
|
||||
if (this.chargerPhases1p3p) {
|
||||
|
|
@ -231,7 +231,7 @@ export default {
|
|||
return this.minPowerPhases(this.phasesConfigured);
|
||||
}
|
||||
}
|
||||
return this.fmtKw(this.minCurrent * V * this.phasesActive);
|
||||
return this.fmtW(this.minCurrent * V * this.phasesActive);
|
||||
},
|
||||
minCurrentOptions: function () {
|
||||
const opt1 = [...range(Math.floor(this.maxCurrent), 1), 0.5, 0.25, 0.125];
|
||||
|
|
@ -279,10 +279,10 @@ export default {
|
|||
},
|
||||
methods: {
|
||||
maxPowerPhases: function (phases) {
|
||||
return this.fmtKw(this.maxCurrent * V * phases);
|
||||
return this.fmtW(this.maxCurrent * V * phases);
|
||||
},
|
||||
minPowerPhases: function (phases) {
|
||||
return this.fmtKw(this.minCurrent * V * phases);
|
||||
return this.fmtW(this.minCurrent * V * phases);
|
||||
},
|
||||
formId: function (name) {
|
||||
return `loadpoint_${this.id}_${name}`;
|
||||
|
|
|
|||
|
|
@ -73,12 +73,22 @@
|
|||
unit="%"
|
||||
:sub1="
|
||||
$t('footer.savings.percentSelf', {
|
||||
self: fmtKw(solarCharged * 1000, true, false, 0),
|
||||
self: fmtW(
|
||||
solarCharged * 1000,
|
||||
POWER_UNIT.KW,
|
||||
false,
|
||||
0
|
||||
),
|
||||
})
|
||||
"
|
||||
:sub2="
|
||||
$t('footer.savings.percentGrid', {
|
||||
grid: fmtKw(gridCharged * 1000, true, false, 0),
|
||||
grid: fmtW(
|
||||
gridCharged * 1000,
|
||||
POWER_UNIT.KW,
|
||||
false,
|
||||
0
|
||||
),
|
||||
})
|
||||
"
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@
|
|||
|
||||
<script>
|
||||
import collector from "../mixins/collector";
|
||||
import formatter from "../mixins/formatter";
|
||||
import formatter, { POWER_UNIT } from "../mixins/formatter";
|
||||
import LabelAndValue from "./LabelAndValue.vue";
|
||||
import VehicleTitle from "./VehicleTitle.vue";
|
||||
import VehicleSoc from "./VehicleSoc.vue";
|
||||
|
|
@ -247,8 +247,7 @@ export default {
|
|||
this.$emit("remove-vehicle");
|
||||
},
|
||||
fmtEnergy(value) {
|
||||
const inKw = value == 0 || value >= 1000;
|
||||
return this.fmtKWh(value, inKw);
|
||||
return this.fmtWh(value, value == 0 ? POWER_UNIT.KW : POWER_UNIT.AUTO);
|
||||
},
|
||||
openPlanModal() {
|
||||
this.$refs.chargingPlan.openPlanModal();
|
||||
|
|
|
|||
|
|
@ -14,9 +14,17 @@ const ENERGY_PRICE_IN_SUBUNIT = {
|
|||
USD: "¢", // US cent
|
||||
};
|
||||
|
||||
export const POWER_UNIT = Object.freeze({
|
||||
W: "W",
|
||||
KW: "kW",
|
||||
MW: "MW",
|
||||
AUTO: "",
|
||||
});
|
||||
|
||||
export default {
|
||||
data: function () {
|
||||
return {
|
||||
POWER_UNIT,
|
||||
fmtLimit: 100,
|
||||
fmtDigits: 1,
|
||||
};
|
||||
|
|
@ -33,23 +41,35 @@ export default {
|
|||
val = Math.abs(val);
|
||||
return val >= this.fmtLimit ? this.round(val / 1e3, this.fmtDigits) : this.round(val, 0);
|
||||
},
|
||||
fmtKw: function (watt = 0, kw = true, withUnit = true, digits) {
|
||||
if (digits === undefined) {
|
||||
digits = kw ? 1 : 0;
|
||||
fmtW: function (watt = 0, format = POWER_UNIT.KW, withUnit = true, digits) {
|
||||
let unit = format;
|
||||
let d = digits;
|
||||
if (POWER_UNIT.AUTO === unit) {
|
||||
if (watt >= 1_000_000) {
|
||||
unit = POWER_UNIT.MW;
|
||||
} else if (watt >= 1000 || 0 === watt) {
|
||||
unit = POWER_UNIT.KW;
|
||||
} else {
|
||||
unit = POWER_UNIT.W;
|
||||
}
|
||||
}
|
||||
const value = kw ? watt / 1000 : watt;
|
||||
let unit = "";
|
||||
if (withUnit) {
|
||||
unit = kw ? " kW" : " W";
|
||||
let value = watt;
|
||||
if (POWER_UNIT.KW === unit) {
|
||||
value = watt / 1000;
|
||||
} else if (POWER_UNIT.MW === unit) {
|
||||
value = watt / 1_000_000;
|
||||
}
|
||||
if (d === undefined) {
|
||||
d = POWER_UNIT.KW === unit || POWER_UNIT.MW === unit || 0 === watt ? 1 : 0;
|
||||
}
|
||||
return `${new Intl.NumberFormat(this.$i18n?.locale, {
|
||||
style: "decimal",
|
||||
minimumFractionDigits: digits,
|
||||
maximumFractionDigits: digits,
|
||||
}).format(value)}${unit}`;
|
||||
minimumFractionDigits: d,
|
||||
maximumFractionDigits: d,
|
||||
}).format(value)}${withUnit ? ` ${unit}` : ""}`;
|
||||
},
|
||||
fmtKWh: function (watt, kw = true, withUnit = true, digits) {
|
||||
return this.fmtKw(watt, kw, withUnit, digits) + (withUnit ? "h" : "");
|
||||
fmtWh: function (watt, format = POWER_UNIT.KW, withUnit = true, digits) {
|
||||
return this.fmtW(watt, format, withUnit, digits) + (withUnit ? "h" : "");
|
||||
},
|
||||
fmtNumber: function (number, decimals, unit) {
|
||||
const style = unit ? "unit" : "decimal";
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { mount, config } from "@vue/test-utils";
|
||||
import { describe, expect, test } from "vitest";
|
||||
import formatter from "./formatter";
|
||||
import formatter, { POWER_UNIT } from "./formatter";
|
||||
|
||||
config.global.mocks["$i18n"] = { locale: "de-DE" };
|
||||
config.global.mocks["$t"] = (a) => a;
|
||||
|
|
@ -10,40 +10,77 @@ const fmt = mount({
|
|||
mixins: [formatter],
|
||||
}).componentVM;
|
||||
|
||||
describe("fmtkW", () => {
|
||||
test("should format kW and W", () => {
|
||||
expect(fmt.fmtKw(0, true)).eq("0,0 kW");
|
||||
expect(fmt.fmtKw(1200, true)).eq("1,2 kW");
|
||||
expect(fmt.fmtKw(0, false)).eq("0 W");
|
||||
expect(fmt.fmtKw(1200, false)).eq("1.200 W");
|
||||
describe("fmtW", () => {
|
||||
test("should format with units", () => {
|
||||
expect(fmt.fmtW(0, POWER_UNIT.AUTO)).eq("0,0 kW");
|
||||
expect(fmt.fmtW(1200000, POWER_UNIT.AUTO)).eq("1,2 MW");
|
||||
expect(fmt.fmtW(0, POWER_UNIT.MW)).eq("0,0 MW");
|
||||
expect(fmt.fmtW(1200000, POWER_UNIT.MW)).eq("1,2 MW");
|
||||
expect(fmt.fmtW(0, POWER_UNIT.KW)).eq("0,0 kW");
|
||||
expect(fmt.fmtW(1200000, POWER_UNIT.KW)).eq("1.200,0 kW");
|
||||
expect(fmt.fmtW(0, POWER_UNIT.W)).eq("0,0 W");
|
||||
expect(fmt.fmtW(1200000, POWER_UNIT.W)).eq("1.200.000 W");
|
||||
});
|
||||
test("should format without unit", () => {
|
||||
expect(fmt.fmtKw(0, true, false)).eq("0,0");
|
||||
expect(fmt.fmtKw(1200, true, false)).eq("1,2");
|
||||
expect(fmt.fmtKw(0, false, false)).eq("0");
|
||||
expect(fmt.fmtKw(1200, false, false)).eq("1.200");
|
||||
test("should format without units", () => {
|
||||
expect(fmt.fmtW(0, POWER_UNIT.AUTO, false)).eq("0,0");
|
||||
expect(fmt.fmtW(1200000, POWER_UNIT.AUTO, false)).eq("1,2");
|
||||
expect(fmt.fmtW(0, POWER_UNIT.MW, false)).eq("0,0");
|
||||
expect(fmt.fmtW(1200000, POWER_UNIT.MW, false)).eq("1,2");
|
||||
expect(fmt.fmtW(0, POWER_UNIT.KW, false)).eq("0,0");
|
||||
expect(fmt.fmtW(1200000, POWER_UNIT.KW, false)).eq("1.200,0");
|
||||
expect(fmt.fmtW(0, POWER_UNIT.W, false)).eq("0,0");
|
||||
expect(fmt.fmtW(1200000, POWER_UNIT.W, false)).eq("1.200.000");
|
||||
});
|
||||
test("should format a given number of digits", () => {
|
||||
expect(fmt.fmtKw(12345, true, true, 0)).eq("12 kW");
|
||||
expect(fmt.fmtKw(12345, true, true, 1)).eq("12,3 kW");
|
||||
expect(fmt.fmtKw(12345, true, true, 2)).eq("12,35 kW");
|
||||
expect(fmt.fmtW(12345, POWER_UNIT.AUTO, true, 0)).eq("12 kW");
|
||||
expect(fmt.fmtW(12345, POWER_UNIT.AUTO, true, 1)).eq("12,3 kW");
|
||||
expect(fmt.fmtW(12345, POWER_UNIT.AUTO, true, 2)).eq("12,35 kW");
|
||||
expect(fmt.fmtW(12345, POWER_UNIT.MW, true, 0)).eq("0 MW");
|
||||
expect(fmt.fmtW(12345, POWER_UNIT.MW, true, 1)).eq("0,0 MW");
|
||||
expect(fmt.fmtW(12345, POWER_UNIT.MW, true, 2)).eq("0,01 MW");
|
||||
expect(fmt.fmtW(12345, POWER_UNIT.KW, true, 0)).eq("12 kW");
|
||||
expect(fmt.fmtW(12345, POWER_UNIT.KW, true, 1)).eq("12,3 kW");
|
||||
expect(fmt.fmtW(12345, POWER_UNIT.KW, true, 2)).eq("12,35 kW");
|
||||
expect(fmt.fmtW(12345, POWER_UNIT.W, true, 0)).eq("12.345 W");
|
||||
expect(fmt.fmtW(12345, POWER_UNIT.W, true, 1)).eq("12.345,0 W");
|
||||
expect(fmt.fmtW(12345, POWER_UNIT.W, true, 2)).eq("12.345,00 W");
|
||||
});
|
||||
});
|
||||
|
||||
describe("fmtKWh", () => {
|
||||
describe("fmtWh", () => {
|
||||
test("should format with units", () => {
|
||||
expect(fmt.fmtKWh(1200)).eq("1,2 kWh");
|
||||
expect(fmt.fmtKWh(1200, true)).eq("1,2 kWh");
|
||||
expect(fmt.fmtKWh(1200, false)).eq("1.200 Wh");
|
||||
expect(fmt.fmtKWh(1200, false, false)).eq("1.200");
|
||||
expect(fmt.fmtWh(0, POWER_UNIT.AUTO)).eq("0,0 kWh");
|
||||
expect(fmt.fmtWh(1200000, POWER_UNIT.AUTO)).eq("1,2 MWh");
|
||||
expect(fmt.fmtWh(0, POWER_UNIT.MW)).eq("0,0 MWh");
|
||||
expect(fmt.fmtWh(1200000, POWER_UNIT.MW)).eq("1,2 MWh");
|
||||
expect(fmt.fmtWh(0, POWER_UNIT.KW)).eq("0,0 kWh");
|
||||
expect(fmt.fmtWh(1200000, POWER_UNIT.KW)).eq("1.200,0 kWh");
|
||||
expect(fmt.fmtWh(0, POWER_UNIT.W)).eq("0,0 Wh");
|
||||
expect(fmt.fmtWh(1200000, POWER_UNIT.W)).eq("1.200.000 Wh");
|
||||
});
|
||||
test("should format with digits", () => {
|
||||
expect(fmt.fmtKWh(56789)).eq("56,8 kWh");
|
||||
expect(fmt.fmtKWh(56789, true, true, 0)).eq("57 kWh");
|
||||
expect(fmt.fmtKWh(56789, true, true, 1)).eq("56,8 kWh");
|
||||
expect(fmt.fmtKWh(56789, true, true, 2)).eq("56,79 kWh");
|
||||
expect(fmt.fmtKWh(56789.123, false, true)).eq("56.789 Wh");
|
||||
expect(fmt.fmtKWh(56789.123, false, true, 2)).eq("56.789,12 Wh");
|
||||
test("should format without units", () => {
|
||||
expect(fmt.fmtWh(0, POWER_UNIT.AUTO, false)).eq("0,0");
|
||||
expect(fmt.fmtWh(1200000, POWER_UNIT.AUTO, false)).eq("1,2");
|
||||
expect(fmt.fmtWh(0, POWER_UNIT.MW, false)).eq("0,0");
|
||||
expect(fmt.fmtWh(1200000, POWER_UNIT.MW, false)).eq("1,2");
|
||||
expect(fmt.fmtWh(0, POWER_UNIT.KW, false)).eq("0,0");
|
||||
expect(fmt.fmtWh(1200000, POWER_UNIT.KW, false)).eq("1.200,0");
|
||||
expect(fmt.fmtWh(0, POWER_UNIT.W, false)).eq("0,0");
|
||||
expect(fmt.fmtWh(1200000, POWER_UNIT.W, false)).eq("1.200.000");
|
||||
});
|
||||
test("should format a given number of digits", () => {
|
||||
expect(fmt.fmtWh(12345, POWER_UNIT.AUTO, true, 0)).eq("12 kWh");
|
||||
expect(fmt.fmtWh(12345, POWER_UNIT.AUTO, true, 1)).eq("12,3 kWh");
|
||||
expect(fmt.fmtWh(12345, POWER_UNIT.AUTO, true, 2)).eq("12,35 kWh");
|
||||
expect(fmt.fmtWh(12345, POWER_UNIT.MW, true, 0)).eq("0 MWh");
|
||||
expect(fmt.fmtWh(12345, POWER_UNIT.MW, true, 1)).eq("0,0 MWh");
|
||||
expect(fmt.fmtWh(12345, POWER_UNIT.MW, true, 2)).eq("0,01 MWh");
|
||||
expect(fmt.fmtWh(12345, POWER_UNIT.KW, true, 0)).eq("12 kWh");
|
||||
expect(fmt.fmtWh(12345, POWER_UNIT.KW, true, 1)).eq("12,3 kWh");
|
||||
expect(fmt.fmtWh(12345, POWER_UNIT.KW, true, 2)).eq("12,35 kWh");
|
||||
expect(fmt.fmtWh(12345, POWER_UNIT.W, true, 0)).eq("12.345 Wh");
|
||||
expect(fmt.fmtWh(12345, POWER_UNIT.W, true, 1)).eq("12.345,0 Wh");
|
||||
expect(fmt.fmtWh(12345, POWER_UNIT.W, true, 2)).eq("12.345,00 Wh");
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import { POWER_UNIT } from "../mixins/formatter";
|
||||
|
||||
export function optionStep(maxEnergy) {
|
||||
if (maxEnergy < 1) return 0.05;
|
||||
if (maxEnergy < 2) return 0.1;
|
||||
|
|
@ -8,13 +10,13 @@ export function optionStep(maxEnergy) {
|
|||
return 5;
|
||||
}
|
||||
|
||||
export function fmtEnergy(energy, step, fmtKWh, zeroText) {
|
||||
export function fmtEnergy(energy, step, fmtWh, zeroText) {
|
||||
if (energy === 0) {
|
||||
return zeroText;
|
||||
}
|
||||
const inKWh = step >= 0.1;
|
||||
const digits = inKWh && step < 1 ? 1 : 0;
|
||||
return fmtKWh(energy * 1e3, inKWh, true, digits);
|
||||
return fmtWh(energy * 1e3, inKWh ? POWER_UNIT.KW : POWER_UNIT.W, true, digits);
|
||||
}
|
||||
|
||||
export function estimatedSoc(energy, socPerKwh) {
|
||||
|
|
@ -22,11 +24,11 @@ export function estimatedSoc(energy, socPerKwh) {
|
|||
return Math.round(energy * socPerKwh);
|
||||
}
|
||||
|
||||
export function energyOptions(fromEnergy, maxEnergy, socPerKwh, fmtKWh, fmtPercentage, zeroText) {
|
||||
export function energyOptions(fromEnergy, maxEnergy, socPerKwh, fmtWh, fmtPercentage, zeroText) {
|
||||
const step = optionStep(maxEnergy);
|
||||
const result = [];
|
||||
for (let energy = 0; energy <= maxEnergy; energy += step) {
|
||||
let text = fmtEnergy(energy, step, fmtKWh, zeroText);
|
||||
let text = fmtEnergy(energy, step, fmtWh, zeroText);
|
||||
const disabled = energy < fromEnergy / 1e3 && energy !== 0;
|
||||
const soc = estimatedSoc(energy, socPerKwh);
|
||||
if (soc) {
|
||||
|
|
|
|||
|
|
@ -230,7 +230,7 @@
|
|||
import Modal from "bootstrap/js/dist/modal";
|
||||
import "@h2d2/shopicons/es/regular/angledoubleleftsmall";
|
||||
import "@h2d2/shopicons/es/regular/angledoublerightsmall";
|
||||
import formatter from "../mixins/formatter";
|
||||
import formatter, { POWER_UNIT } from "../mixins/formatter";
|
||||
import api from "../api";
|
||||
import store from "../store";
|
||||
import CustomSelect from "../components/CustomSelect.vue";
|
||||
|
|
@ -299,7 +299,7 @@ export default {
|
|||
unit: "kWh",
|
||||
total: this.chargedEnergy,
|
||||
value: (session) => session.chargedEnergy,
|
||||
format: (value) => this.fmtKWh(value * 1e3, true, false),
|
||||
format: (value) => this.fmtWh(value * 1e3, POWER_UNIT.KW, false),
|
||||
},
|
||||
{
|
||||
name: "solar",
|
||||
|
|
@ -347,7 +347,7 @@ export default {
|
|||
return null;
|
||||
},
|
||||
format: (value) =>
|
||||
value ? this.fmtKw(value * 1e3, true, false, 1) : undefined,
|
||||
value ? this.fmtW(value * 1e3, POWER_UNIT.KW, false, 1) : undefined,
|
||||
},
|
||||
];
|
||||
// only columns with values are shown
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue