Skip to content

Commit

Permalink
formatting: MWh formatting starting at 10MWh (before 1)
Browse files Browse the repository at this point in the history
  • Loading branch information
naltatis committed Oct 20, 2024
1 parent 95fe91a commit 4ec3c45
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 10 deletions.
3 changes: 0 additions & 3 deletions assets/js/components/Sessions/AvgCostGroupedChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,12 @@ export default {
}
});
console.log(`${this.costType} grouped data`, aggregatedData);
const sortedEntries = Object.entries(aggregatedData).sort(
(a, b) => b[1].cost - a[1].cost
);
const labels = sortedEntries.map(([label]) => label);
const data = sortedEntries.map(([, value]) => value.cost / value.energy);
console.log(`${this.costType} grouped data`, labels, data);
const borderColors = labels.map((label) => this.colorMappings[this.groupBy][label]);
const backgroundColors = borderColors.map((color) => dimColor(color));
return {
Expand Down
2 changes: 1 addition & 1 deletion assets/js/components/Sessions/EnergyGroupedChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default {
const maxEnergy = Math.max(...this.chartData.datasets[0].data);
// sync energy units for label grid view
const unit =
maxEnergy < 1 ? POWER_UNIT.W : maxEnergy > 1e3 ? POWER_UNIT.MW : POWER_UNIT.KW;
maxEnergy < 1 ? POWER_UNIT.W : maxEnergy > 1e4 ? POWER_UNIT.MW : POWER_UNIT.KW;
const fmtShare = (value) => this.fmtPercentage((100 / total) * value, 1);
const fmtValue = (value) => this.fmtWh(value * 1e3, unit);
return this.chartData.labels.map((label, index) => ({
Expand Down
2 changes: 1 addition & 1 deletion assets/js/mixins/formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default {
let unit = format;
let d = digits;
if (POWER_UNIT.AUTO === unit) {
if (watt >= 1_000_000) {
if (watt >= 10_000_000) {
unit = POWER_UNIT.MW;
} else if (watt >= 1000 || 0 === watt) {
unit = POWER_UNIT.KW;
Expand Down
8 changes: 4 additions & 4 deletions assets/js/mixins/formatter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const fmt = mount({
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(1200000, POWER_UNIT.AUTO)).eq("1.200,0 kW");
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");
Expand All @@ -23,7 +23,7 @@ describe("fmtW", () => {
});
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(1200000, POWER_UNIT.AUTO, false)).eq("1.200,0");
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");
Expand All @@ -50,7 +50,7 @@ describe("fmtW", () => {
describe("fmtWh", () => {
test("should format with units", () => {
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(1200000, POWER_UNIT.AUTO)).eq("1.200,0 kWh");
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");
Expand All @@ -60,7 +60,7 @@ describe("fmtWh", () => {
});
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(1200000, POWER_UNIT.AUTO, false)).eq("1.200,0");
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");
Expand Down
2 changes: 1 addition & 1 deletion i18n/de.toml
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ energyGroupedTitleByGroup = "Energiemenge {byGroup}"
energySubTitle = "{energy} gesamt"
energyTitle = "{percent} Sonnenenergie"
groupedCo2TitleByGroup = "CO₂-Menge {byGroup}"
groupedPriceTitleByGroup = "Gesamtpreis {byGroup}"
groupedPriceTitleByGroup = "Kosten {byGroup}"
historyCo2SubTitle = "{value} gesamt"
historyCo2Title = "⌀ {value} CO₂-Emission"
historyPriceSubTitle = "{value} gesamt"
Expand Down

0 comments on commit 4ec3c45

Please sign in to comment.