-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,001 additions
and
1,275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -206,7 +206,7 @@ services: | |
} | ||
npm: | ||
image: node:22 | ||
image: node:23 | ||
working_dir: /app/frontend | ||
volumes: | ||
- .:/app | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
frontend/src/components/company-survey-v2/time-series-textarea.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import {Instant, ZonedDateTime, ZoneId, ZoneRulesProvider, convert, LocalDateTime} from "@js-joda/core" | ||
import "@js-joda/timezone/dist/js-joda-timezone-2017-2027.esm.js" | ||
import {FunctionComponent, useState} from "react" | ||
import {TimeSeries, timeSeriesFromJson, TimeSeriesType, createEmptyTimeSeriesForYear, toJsJodaInstant} from "zero-zummon" | ||
import { InputTextarea } from 'primereact/inputtextarea'; | ||
import {LabelRow} from "./generic/label-row" | ||
|
||
const targetYear = 2023 | ||
const displayTimeZone = "Europe/Amsterdam" | ||
|
||
const placeholder = [0.2, 0.32, 1.2, 1.1, 0.9, 0.65].join("\n").replaceAll(".", ",") | ||
|
||
const kwhNumberFormatter = new Intl.NumberFormat("nl-NL", {maximumFractionDigits: 1}) | ||
|
||
/** | ||
* Has a plain JS object as input and output. | ||
* Converts that objects to a {@link TimeSeries} domain object for use in {@link TimeSeriesTextarea} | ||
*/ | ||
export const TimeSeriesTextareaAdapter: FunctionComponent<{ | ||
timeSeries?: any, | ||
timeSeriesType?: TimeSeriesType, | ||
setTimeSeries?: () => void | ||
}> = ({ | ||
timeSeries, | ||
timeSeriesType = TimeSeriesType.ELECTRICITY_DELIVERY, | ||
setTimeSeries = console.log | ||
}) => { | ||
const timeSeriesDomainObject = timeSeries ? timeSeriesFromJson(timeSeries) : createEmptyTimeSeriesForYear(timeSeriesType, targetYear) | ||
|
||
return <TimeSeriesTextarea timeSeries={timeSeriesDomainObject} setTimeSeries={setTimeSeries} /> | ||
} | ||
|
||
const TimeSeriesTextarea: FunctionComponent<{timeSeries: TimeSeries, setTimeSeries: (t: TimeSeries) => void}> = ({timeSeries}) => { | ||
const [internalTimeSeries, setInternalTimeSeries] = useState(timeSeries) | ||
|
||
const localStart = kotlinInstantToJsJodaInstant(internalTimeSeries.start) | ||
.atZone(ZoneId.of(displayTimeZone)) | ||
.toLocalDateTime() | ||
|
||
const end = kotlinInstantToJsJodaInstant(internalTimeSeries.calculateEnd()) | ||
|
||
return ( | ||
<> | ||
<h2>2. Kwartierwaarden electriciteit</h2> | ||
|
||
<p>Richtlijnen</p> | ||
|
||
<ul> | ||
<li>Geef waarden op van het gehele jaar {targetYear}.</li> | ||
<li>De eerste waarde betreft het verbruik in het kwartier van 1 januari {targetYear} van 00:00 tot 00:15 CET.</li> | ||
<li>De laatste waarde betreft het verbruik in het kwartier van 31 december {targetYear} 23:45 tot 1 januari {targetYear + 1} om 00:00 CET.</li> | ||
<li>Een langere periode mag.</li> | ||
</ul> | ||
|
||
<LabelRow label="Datum en tijd begin kwartierwaarden"> | ||
<div style={{display: "flex", gap: "1rem"}}> | ||
<input type="datetime-local" id="start" name="start" defaultValue={localStart.toString()} | ||
onChange={e => { | ||
const local = LocalDateTime.parse(e.target.value) | ||
const zoned = ZonedDateTime.of(local, ZoneId.of(displayTimeZone)) | ||
setInternalTimeSeries( | ||
internalTimeSeries.withStartEpochSeconds(zoned.toEpochSecond()), | ||
) | ||
}} /> | ||
Nederlandse tijd | ||
</div> | ||
</LabelRow> | ||
|
||
<LabelRow label="Plak hier de waarden in kWh"> | ||
<InputTextarea | ||
id="values" | ||
name="values" | ||
defaultValue={internalTimeSeries.values.values().map(val => val.toLocaleString()).toArray().join("\n")} | ||
onInput={e => setInternalTimeSeries(internalTimeSeries.withValues(parseTextArea((e.target as HTMLTextAreaElement).value)))} | ||
style={{display: "block", height: "10rem"}} | ||
placeholder={placeholder} /> | ||
</LabelRow> | ||
|
||
<p>Eind kwartierwaarden: {prettyPrint(end)}</p> | ||
<p>Totaal: <span id="total">{kwhNumberFormatter.format(internalTimeSeries.sum())}</span> kWh</p> | ||
</> | ||
) | ||
} | ||
|
||
function parseTextArea(content: String): Float32Array { | ||
const lines = content.split("\n") | ||
const numberArray = lines.map(line => line | ||
.trim() | ||
.replace(",", ".") | ||
).filter(line => line).map(parseFloat) | ||
return new Float32Array(numberArray) | ||
} | ||
|
||
// This seems dubious because it mixes different versions of js-joda. | ||
// If this leads to issues we can do it with a conversion through epoch seconds | ||
const kotlinInstantToJsJodaInstant = (kotlinInstant: any): Instant => toJsJodaInstant(kotlinInstant) | ||
|
||
// We use native date formatting because js-joda does not support Dutch locale | ||
const dateFormatter = new Intl.DateTimeFormat("nl-NL", { | ||
dateStyle: "full", | ||
timeStyle: "long", | ||
timeZone: displayTimeZone, | ||
}) | ||
|
||
function prettyPrint(instant: Instant): string { | ||
const jsDate = convert(instant).toDate() | ||
return dateFormatter.format(jsDate) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
|
||
import React from 'react' | ||
import ReactDOM from 'react-dom/client' | ||
import { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import kotlinx.datetime.Instant | ||
import kotlinx.datetime.internal.JSJoda.Instant as jtInstant | ||
|
||
@JsExport | ||
fun toJsJodaInstant(instant: Instant) = jtInstant.ofEpochSecond(instant.epochSeconds.toDouble(), 0) | ||
|
||
//fun instantToEpochSeconds(instant: Instant) = instant.epochSeconds.toDouble() |