Skip to content

Commit

Permalink
not working any more
Browse files Browse the repository at this point in the history
  • Loading branch information
Erikvv committed Dec 18, 2024
1 parent 6665fab commit 7bb54c6
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 1,129 deletions.
1,089 changes: 13 additions & 1,076 deletions frontend/package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {ConsumptionSpec, ElectricityConsumptionRadios} from "./electricity-consu
import {LabelRow} from "./generic/label-row"
import {Purpose, Upload} from "./generic/upload"
import {ProjectConfiguration} from "./project"
import {TimeSeriesTextareaAdapter} from "./time-series-textarea"
import {TimeSeriesElectricity} from "./time-series/time-series-electricity"

export const ElectricityData = ({form, prefix, project}: {
form: UseFormReturn,
Expand Down Expand Up @@ -64,7 +64,7 @@ export const ElectricityData = ({form, prefix, project}: {
</LabelRow>
)}
{consumptionSpec === ConsumptionSpec.TEXTAREA && (
<TimeSeriesTextareaAdapter />
<TimeSeriesElectricity form={form} prefix={prefix} />
)}
{/*{consumptionSpec === ConsumptionSpec.ANNUAL_VALUES && (*/}
{/* <>*/}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {targetYear} from "./time-series-util"
import {TimeSeriesTextareaAdapter} from "./time-series-textarea-adapter"
import {FunctionComponent} from "react"
import {UseFormReturn} from "react-hook-form"
import {TimeSeriesType} from "zero-zummon"

export const TimeSeriesElectricity: FunctionComponent<{form: UseFormReturn, prefix: string}> = ({form, prefix}) => {
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>
</>
<TimeSeriesTextareaAdapter
timeSeries={form.watch(`${prefix}.quarterHourlyDelivery_kWh`)}
timeSeriesType={TimeSeriesType.ELECTRICITY_DELIVERY}
setTimeSeries={timeSeries => form.setValue(`${prefix}.quarterHourlyDelivery_kWh`, timeSeries)} />
<TimeSeriesTextareaAdapter
timeSeries={form.watch(`${prefix}.quarterHourlyFeedIn_kWh`)}
timeSeriesType={TimeSeriesType.ELECTRICITY_FEED_IN}
setTimeSeries={timeSeries => form.setValue(`${prefix}.quarterHourlyFeedIn_kWh`, timeSeries)} />
<TimeSeriesTextareaAdapter
timeSeries={form.watch(`${prefix}.quarterHourlyProduction_kWh`)}
timeSeriesType={TimeSeriesType.ELECTRICITY_PRODUCTION}
setTimeSeries={timeSeries => form.setValue(`${prefix}.quarterHourlyProduction_kWh`, timeSeries)} />
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {FunctionComponent} from "react"
import {targetYear} from "./time-series-util"
import {TimeSeries, TimeSeriesType, timeSeriesFromJson, createEmptyTimeSeriesForYear} from "zero-zummon"
import {TimeSeriesTextarea} from "./time-series-textarea"

/**
* 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?: (obj: any) => void
}> = ({
timeSeries,
timeSeriesType = TimeSeriesType.ELECTRICITY_DELIVERY,
setTimeSeries = console.log,
}) => {
const timeSeriesDomainObject = timeSeries ? timeSeriesFromJson(timeSeries) : createEmptyTimeSeriesForYear(timeSeriesType, targetYear)

return <TimeSeriesTextarea timeSeries={timeSeriesDomainObject} setTimeSeries={setTimeSeries} />
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,23 @@
import {Instant, ZonedDateTime, ZoneId, ZoneRulesProvider, convert, LocalDateTime} from "@js-joda/core"
import {LocalDateTime, ZonedDateTime, ZoneId} 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"
import {TimeSeries, TimeSeriesType} from "zero-zummon"
import {InputTextarea} from "primereact/inputtextarea"
import {LabelRow} from "../generic/label-row"
import {displayTimeZone, kotlinInstantToJsJodaInstant, prettyPrint} from "./time-series-util"

const placeholder = [0.2, 0.32, 1.2, 1.1, 0.9, 0.65].join("\n").replaceAll(".", ",")
//
// const headings = {
// [TimeSeriesType.ELECTRICITY_DELIVERY]:
// [TimeSeriesType.ELECTRICITY_DELIVERY]:
// }

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} />
}
console.log("ZONES", ZoneId.getAvailableZoneIds())

const TimeSeriesTextarea: FunctionComponent<{timeSeries: TimeSeries, setTimeSeries: (t: TimeSeries) => void}> = ({timeSeries}) => {
export const TimeSeriesTextarea: FunctionComponent<{timeSeries: TimeSeries, setTimeSeries: (t: TimeSeries) => void}> = ({timeSeries}) => {
const [internalTimeSeries, setInternalTimeSeries] = useState(timeSeries)

const localStart = kotlinInstantToJsJodaInstant(internalTimeSeries.start)
Expand All @@ -41,16 +28,7 @@ const TimeSeriesTextarea: FunctionComponent<{timeSeries: TimeSeries, setTimeSeri

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>
<h3></h3>

<LabelRow label="Datum en tijd begin kwartierwaarden">
<div style={{display: "flex", gap: "1rem"}}>
Expand Down Expand Up @@ -84,25 +62,12 @@ const TimeSeriesTextarea: FunctionComponent<{timeSeries: TimeSeries, setTimeSeri

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)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {convert, Instant} from "@js-joda/core"
import "@js-joda/timezone/dist/js-joda-timezone-2017-2027.esm.js"
import {toJsJodaInstant} from "zero-zummon"

export const targetYear = 2023
export const displayTimeZone = "Europe/Amsterdam"

// 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
export 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,
})

export function prettyPrint(instant: Instant): string {
const jsDate = convert(instant).toDate()
return dateFormatter.format(jsDate)
}
1 change: 0 additions & 1 deletion frontend/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import React from 'react'
import ReactDOM from 'react-dom/client'
import {
Expand Down
5 changes: 5 additions & 0 deletions frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import {defineConfig} from "vite"
import react from "@vitejs/plugin-react"

export default defineConfig({
esbuild: {
keepNames: true,
},
// this is a dev-only option
optimizeDeps: {
esbuildOptions: {
Expand All @@ -15,7 +18,9 @@ export default defineConfig({
port: 3000,
},
build: {
minify: false,
rollupOptions: {
treeshake: false,
output: {
entryFileNames: "[name].js",
assetFileNames: '[name].css',
Expand Down

0 comments on commit 7bb54c6

Please sign in to comment.