diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2d97e24 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,36 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### Visual Studio Code +.vscode + +### NetBeans ### +nbproject/private/ +nbbuild/ +dist/ +nbdist/ +.nb-gradle/ + +mvnw +mvnw.cmd +.DS_Store + +### Build stuff +build/ +build.sh +build.bat diff --git a/.env b/.env new file mode 100644 index 0000000..5051110 --- /dev/null +++ b/.env @@ -0,0 +1,4 @@ +PORT=8080 +LOGGING_LEVEL=INFO +MONGODB_URI=mongodb://mongo-node1:27017,mongo-node2:27018,mongo-node3:27019/electicity-prices +SPRING_PROFILES_ACTIVE=prod diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml new file mode 100644 index 0000000..986cac1 --- /dev/null +++ b/.github/workflows/build-docker-image.yml @@ -0,0 +1,16 @@ +name: Build Docker image + +on: + workflow_dispatch: + pull_request: + branches: ["main"] + +jobs: + build: + name: Build docker image + runs-on: self-hosted + + steps: + - uses: actions/checkout@v3 + - name: Build the Docker image + run: docker build . --file Dockerfile diff --git a/.github/workflows/publish-to-dockerhub.yml b/.github/workflows/publish-to-dockerhub.yml new file mode 100644 index 0000000..047832f --- /dev/null +++ b/.github/workflows/publish-to-dockerhub.yml @@ -0,0 +1,47 @@ +name: Publish to Dockerhub + +on: + release: + types: [published] + +jobs: + publish: + name: Build and Publish docker image to dockerhub + permissions: + contents: write + pull-requests: write + packages: read + runs-on: self-hosted + + steps: + - uses: actions/checkout@v3 + - name: Update Version + run: echo "${{ github.ref_name }}" > .version + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Publish to Registry + uses: elgohr/Publish-Docker-Github-Action@v5 + with: + name: daithihearn/electricity-prices + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + platforms: linux/amd64,linux/arm64/v8 + tags: "latest,${{ github.ref_name }}" + - name: Create PR with version changes + uses: peter-evans/create-pull-request@v4 + with: + token: ${{ secrets.PAT_PR }} + commit-message: Update latest version (${{ github.ref_name }}) + title: Update latest version (${{ github.ref_name }}) + body: | + Update latest version (${{ github.ref_name }}) + branch: update-version-${{ github.ref_name }} + base: main + add-paths: | + .version + labels: | + update + assignees: | + ${{ github.actor }} diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml new file mode 100644 index 0000000..ab17d9a --- /dev/null +++ b/.github/workflows/unit-tests.yml @@ -0,0 +1,25 @@ +name: Run unit tests + +on: + pull_request: + branches: [ "main" ] + +permissions: + contents: read + +jobs: + unit-tests: + name: Run unit tests + runs-on: self-hosted + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 19 + uses: actions/setup-java@v3 + with: + java-version: '19' + distribution: 'temurin' + - name: Build with Gradle + uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 + with: + arguments: test diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4d7544b --- /dev/null +++ b/.gitignore @@ -0,0 +1,45 @@ +# Compiled class file +*.class + +# Log file +*.log +logs/ + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +.gradle/ +.idea/ +id-core.iml +**/*.iml +build/ +.settings/ +.classpath +.DS_Store +.project +classes/ +frontend +/output/ +dump.rdb +/root +/out +velocity.log* +bin/ +.vscode/ + +# Deployment Script +deploy.sh \ No newline at end of file diff --git a/.version b/.version new file mode 100644 index 0000000..8acdd82 --- /dev/null +++ b/.version @@ -0,0 +1 @@ +0.0.1 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bb5c0be --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM eclipse-temurin:19 AS builder + +WORKDIR /opt/app + +COPY ./gradle ./gradle +COPY ./gradlew ./ + +RUN ./gradlew + +COPY ./build.gradle.kts ./ +COPY ./settings.gradle ./ +COPY ./system.properties ./ +COPY ./.version ./ +COPY ./src ./src + +RUN ./gradlew build publishToMavenLocal + +FROM eclipse-temurin:19 + +WORKDIR /opt/app + +COPY --from=builder /opt/app/build/libs/electricity-prices*.jar /opt/app/app.jar + +ENTRYPOINT ["java", "-Djdk.tls.client.protocols=TLSv1.2", "-jar", "./app.jar", "-XX:+UseContainerSupport"] diff --git a/HELP.md b/HELP.md new file mode 100644 index 0000000..da3ca37 --- /dev/null +++ b/HELP.md @@ -0,0 +1,29 @@ +# Read Me First +The following was discovered as part of building this project: + +* The original package name 'ie.daithi.electricity-prices' is invalid and this project uses 'ie.daithi.electricityprices' instead. + +# Getting Started + +### Reference Documentation +For further reference, please consider the following sections: + +* [Official Gradle documentation](https://docs.gradle.org) +* [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/3.1.0-M2/gradle-plugin/reference/html/) +* [Create an OCI image](https://docs.spring.io/spring-boot/docs/3.1.0-M2/gradle-plugin/reference/html/#build-image) +* [Spring Web](https://docs.spring.io/spring-boot/docs/3.1.0-M2/reference/htmlsingle/#web) +* [Spring Data MongoDB](https://docs.spring.io/spring-boot/docs/3.1.0-M2/reference/htmlsingle/#data.nosql.mongodb) + +### Guides +The following guides illustrate how to use some features concretely: + +* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) +* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) +* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/) +* [Accessing Data with MongoDB](https://spring.io/guides/gs/accessing-data-mongodb/) + +### Additional Links +These additional references should also help you: + +* [Gradle Build Scans – insights for your project's build](https://scans.gradle.com#gradle) + diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..c85b660 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,97 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import org.springframework.boot.gradle.tasks.bundling.BootJar + +buildscript { + val kotlinVersion = "1.6.10" + val springBootVersion = "2.7.7" + repositories { + mavenLocal() + mavenCentral() + } + dependencies { + classpath("org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") + } +} + +plugins { + id("org.springframework.boot") version "2.7.7" + id("maven-publish") + id("org.jetbrains.kotlin.jvm") version "1.6.10" + kotlin("plugin.spring") version "1.6.10" +} + +apply(plugin = "maven-publish") +apply(plugin = "io.spring.dependency-management") + +tasks.withType { + options.encoding = "UTF-8" +} + +repositories { + mavenLocal() + mavenCentral() +} + +version=File(".version").readText(Charsets.UTF_8) + +group = "ie.daithi.electricityprices" +java.sourceCompatibility = JavaVersion.VERSION_19 + +description = "api" + +val springBootVersion: String = "2.7.7" +val swaggerVersion: String = "2.9.2" + +dependencies { + + // Internal Dependencies + + // External Dependencies + + // Kotlin dependencies + implementation("org.jetbrains.kotlin:kotlin-reflect:1.6.10") + implementation("org.jetbrains.kotlin:kotlin-stdlib:1.6.10") + + // Spring dependencies + implementation("org.springframework.boot:spring-boot-starter:$springBootVersion") + implementation("org.springframework.boot:spring-boot-starter-web:$springBootVersion") + implementation("org.springframework.boot:spring-boot-starter-webflux:$springBootVersion") + implementation("org.springframework.boot:spring-boot-starter-data-mongodb:$springBootVersion") + + // Springfox + implementation("io.springfox:springfox-swagger2:$swaggerVersion") + implementation("io.springfox:springfox-swagger-ui:$swaggerVersion") + + // Other + implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.14.0") + implementation("org.apache.commons:commons-text:1.10.0") + + //Test + testImplementation("org.springframework.boot:spring-boot-starter-test:$springBootVersion") + testImplementation("io.mockk:mockk:1.13.2") + + +} + +tasks.withType { + useJUnitPlatform() + testLogging { + events("passed", "skipped", "failed") + } +} + +tasks.withType { + kotlinOptions { + freeCompilerArgs = listOf("-Xjsr305=strict") + jvmTarget = "17" + } +} + +tasks.getByName("bootJar") { + enabled = true +} + +tasks.getByName("jar") { + enabled = false +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..249e583 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..774fae8 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..a69d9cb --- /dev/null +++ b/gradlew @@ -0,0 +1,240 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..53a6b23 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,91 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/precios-mercados-tiempo-real.json b/precios-mercados-tiempo-real.json new file mode 100644 index 0000000..54cd679 --- /dev/null +++ b/precios-mercados-tiempo-real.json @@ -0,0 +1 @@ +{"data":{"type":"Precios mercado peninsular en tiempo real","id":"mer13","attributes":{"title":"Precios mercado peninsular en tiempo real","last-update":"2023-04-07T20:17:39.000+02:00","description":null},"meta":{"cache-control":{"cache":"MISS"}}},"included":[{"type":"PVPC (\u20ac\/MWh)","id":"1001","groupId":null,"attributes":{"title":"PVPC (\u20ac\/MWh)","description":null,"color":"#ffcf09","type":null,"magnitude":"price","composite":false,"last-update":"2023-04-07T20:17:39.000+02:00","values":[{"value":175.23,"percentage":0.5812518658572993,"datetime":"2023-04-08T00:00:00.000+02:00"},{"value":166.65,"percentage":0.5915447962515973,"datetime":"2023-04-08T01:00:00.000+02:00"},{"value":168.34,"percentage":0.5934360348292029,"datetime":"2023-04-08T02:00:00.000+02:00"},{"value":163.92,"percentage":0.596788873921433,"datetime":"2023-04-08T03:00:00.000+02:00"},{"value":166.89,"percentage":0.6010372024345446,"datetime":"2023-04-08T04:00:00.000+02:00"},{"value":167.86,"percentage":0.5994571816298837,"datetime":"2023-04-08T05:00:00.000+02:00"},{"value":171.66,"percentage":0.596455872133426,"datetime":"2023-04-08T06:00:00.000+02:00"},{"value":182.22,"percentage":0.5848444972237379,"datetime":"2023-04-08T07:00:00.000+02:00"},{"value":184.62,"percentage":0.5776053561930983,"datetime":"2023-04-08T08:00:00.000+02:00"},{"value":159.63,"percentage":0.586961317840859,"datetime":"2023-04-08T09:00:00.000+02:00"},{"value":80.29,"percentage":0.6661964819117159,"datetime":"2023-04-08T10:00:00.000+02:00"},{"value":70.52,"percentage":0.6792525524947024,"datetime":"2023-04-08T11:00:00.000+02:00"},{"value":69.06,"percentage":0.679456906729634,"datetime":"2023-04-08T12:00:00.000+02:00"},{"value":67.9,"percentage":0.6764295676429568,"datetime":"2023-04-08T13:00:00.000+02:00"},{"value":61.03,"percentage":0.709403696384982,"datetime":"2023-04-08T14:00:00.000+02:00"},{"value":56.35,"percentage":0.7380484610347087,"datetime":"2023-04-08T15:00:00.000+02:00"},{"value":45.03,"percentage":0.8182809376703616,"datetime":"2023-04-08T16:00:00.000+02:00"},{"value":55.98,"percentage":0.7367728349565675,"datetime":"2023-04-08T17:00:00.000+02:00"},{"value":73.02,"percentage":0.6751109467455622,"datetime":"2023-04-08T18:00:00.000+02:00"},{"value":154,"percentage":0.5888425802011242,"datetime":"2023-04-08T19:00:00.000+02:00"},{"value":186.09,"percentage":0.5703034017775054,"datetime":"2023-04-08T20:00:00.000+02:00"},{"value":182.51,"percentage":0.5706647489212682,"datetime":"2023-04-08T21:00:00.000+02:00"},{"value":181.08,"percentage":0.5730742452053927,"datetime":"2023-04-08T22:00:00.000+02:00"},{"value":172.44,"percentage":0.5759134326364304,"datetime":"2023-04-08T23:00:00.000+02:00"}]}},{"type":"Spot market price (\u20ac\/MWh)","id":"600","groupId":null,"attributes":{"title":"Spot market price (\u20ac\/MWh)","description":null,"color":"#df4a32","type":null,"magnitude":"price","composite":false,"last-update":"2023-04-07T14:13:44.000+02:00","values":[{"value":126.24,"percentage":0.4187481341427008,"datetime":"2023-04-08T00:00:00.000+02:00"},{"value":115.07,"percentage":0.4084552037484026,"datetime":"2023-04-08T01:00:00.000+02:00"},{"value":115.33,"percentage":0.406563965170797,"datetime":"2023-04-08T02:00:00.000+02:00"},{"value":110.75,"percentage":0.4032111260785671,"datetime":"2023-04-08T03:00:00.000+02:00"},{"value":110.78,"percentage":0.39896279756545544,"datetime":"2023-04-08T04:00:00.000+02:00"},{"value":112.16,"percentage":0.40054281837011646,"datetime":"2023-04-08T05:00:00.000+02:00"},{"value":116.14,"percentage":0.403544127866574,"datetime":"2023-04-08T06:00:00.000+02:00"},{"value":129.35,"percentage":0.4151555027762621,"datetime":"2023-04-08T07:00:00.000+02:00"},{"value":135.01,"percentage":0.4223946438069017,"datetime":"2023-04-08T08:00:00.000+02:00"},{"value":112.33,"percentage":0.4130386821591411,"datetime":"2023-04-08T09:00:00.000+02:00"},{"value":40.23,"percentage":0.33380351808828407,"datetime":"2023-04-08T10:00:00.000+02:00"},{"value":33.3,"percentage":0.3207474475052976,"datetime":"2023-04-08T11:00:00.000+02:00"},{"value":32.58,"percentage":0.32054309327036595,"datetime":"2023-04-08T12:00:00.000+02:00"},{"value":32.48,"percentage":0.3235704323570432,"datetime":"2023-04-08T13:00:00.000+02:00"},{"value":25,"percentage":0.29059630361501804,"datetime":"2023-04-08T14:00:00.000+02:00"},{"value":20,"percentage":0.26195153896529144,"datetime":"2023-04-08T15:00:00.000+02:00"},{"value":10,"percentage":0.1817190623296384,"datetime":"2023-04-08T16:00:00.000+02:00"},{"value":20,"percentage":0.2632271650434325,"datetime":"2023-04-08T17:00:00.000+02:00"},{"value":35.14,"percentage":0.3248890532544379,"datetime":"2023-04-08T18:00:00.000+02:00"},{"value":107.53,"percentage":0.4111574197988759,"datetime":"2023-04-08T19:00:00.000+02:00"},{"value":140.21,"percentage":0.4296965982224946,"datetime":"2023-04-08T20:00:00.000+02:00"},{"value":137.31,"percentage":0.4293352510787318,"datetime":"2023-04-08T21:00:00.000+02:00"},{"value":134.9,"percentage":0.42692575479460726,"datetime":"2023-04-08T22:00:00.000+02:00"},{"value":126.98,"percentage":0.42408656736356953,"datetime":"2023-04-08T23:00:00.000+02:00"}]}}]} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..d73f21f --- /dev/null +++ b/settings.gradle @@ -0,0 +1,7 @@ +pluginManagement { + repositories { + mavenCentral() + gradlePluginPortal() + } +} +rootProject.name = "electricity-prices" diff --git a/src/main/kotlin/ie/daithi/electricityprices/ElectricityPricesApplication.kt b/src/main/kotlin/ie/daithi/electricityprices/ElectricityPricesApplication.kt new file mode 100644 index 0000000..07c7d2c --- /dev/null +++ b/src/main/kotlin/ie/daithi/electricityprices/ElectricityPricesApplication.kt @@ -0,0 +1,11 @@ +package ie.daithi.electricityprices + +import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.runApplication + +@SpringBootApplication +class ElectricityPricesApplication + +fun main(args: Array) { + runApplication(*args) +} diff --git a/src/main/kotlin/ie/daithi/electricityprices/config/AppConfig.kt b/src/main/kotlin/ie/daithi/electricityprices/config/AppConfig.kt new file mode 100644 index 0000000..a651000 --- /dev/null +++ b/src/main/kotlin/ie/daithi/electricityprices/config/AppConfig.kt @@ -0,0 +1,59 @@ +package ie.daithi.electricityprices.config + +import ie.daithi.electricityprices.service.PriceService +import org.springframework.beans.factory.annotation.Value +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.ComponentScan +import org.springframework.context.annotation.Configuration +import org.springframework.http.codec.ClientCodecConfigurer +import org.springframework.scheduling.annotation.Scheduled +import org.springframework.web.reactive.function.client.ExchangeStrategies +import org.springframework.web.reactive.function.client.WebClient +import springfox.documentation.builders.PathSelectors +import springfox.documentation.builders.RequestHandlerSelectors +import springfox.documentation.service.* +import springfox.documentation.spi.DocumentationType +import springfox.documentation.spring.web.plugins.Docket +import springfox.documentation.swagger2.annotations.EnableSwagger2 +import java.util.* + +@Configuration +@ComponentScan(basePackages = ["ie.daithi.electricityprices"]) +@EnableSwagger2 +open class AppConfig(@Value("\${ree.url}") private val reeUrl: String) { + + @Bean + open fun reeRest(): WebClient { + val size = 16 * 1024 * 1024 + val strategies = ExchangeStrategies.builder() + .codecs { codecs: ClientCodecConfigurer -> + codecs.defaultCodecs().maxInMemorySize(size) + } + .build() + return WebClient.builder() + .exchangeStrategies(strategies) + .baseUrl(reeUrl) + .build() + } + + @Bean + fun api(): Docket { + return Docket(DocumentationType.SWAGGER_2) + .select() + .apis(RequestHandlerSelectors.any()) + .paths(PathSelectors.any()) + .build() + .apiInfo(apiInfo()) + } + + private fun apiInfo(): ApiInfo { + return ApiInfo( "Electricity Prices API", + "API for Electricity Prices", + "0.0.1", + "Whatever", + Contact("Daithi Hearn","https://github.com/daithihearn", "daithi.hearn@gmail.com"), + "", "", Collections.emptyList()) + } + + +} \ No newline at end of file diff --git a/src/main/kotlin/ie/daithi/electricityprices/config/MongoDbConfig.kt b/src/main/kotlin/ie/daithi/electricityprices/config/MongoDbConfig.kt new file mode 100644 index 0000000..460320f --- /dev/null +++ b/src/main/kotlin/ie/daithi/electricityprices/config/MongoDbConfig.kt @@ -0,0 +1,8 @@ +package ie.daithi.electricityprices.config + +import org.springframework.context.annotation.Configuration +import org.springframework.data.mongodb.repository.config.EnableMongoRepositories + +@Configuration +@EnableMongoRepositories(basePackages = ["ie.daithi.electricityprices.repos"]) +open class MongoDbConfig \ No newline at end of file diff --git a/src/main/kotlin/ie/daithi/electricityprices/model/Price.kt b/src/main/kotlin/ie/daithi/electricityprices/model/Price.kt new file mode 100644 index 0000000..f87b206 --- /dev/null +++ b/src/main/kotlin/ie/daithi/electricityprices/model/Price.kt @@ -0,0 +1,24 @@ +package ie.daithi.electricityprices.model + +import org.springframework.data.annotation.Id +import org.springframework.data.mongodb.core.index.CompoundIndex +import org.springframework.data.mongodb.core.index.Indexed +import org.springframework.data.mongodb.core.mapping.Document +import org.springframework.util.DigestUtils +import java.time.LocalDateTime + +@Document(collection = "prices") +@CompoundIndex(name = "date-hour", def = "{'date': 1, 'hour': 1}", unique = true) +data class Price( + @Id + val id: String, + @Indexed + val dateTime: LocalDateTime, + val price: Double, +) { + constructor(dateTime: LocalDateTime, price: Double) : this( + id = DigestUtils.md5DigestAsHex("${dateTime.year}-${dateTime.monthValue}-${dateTime.dayOfMonth}-${dateTime.hour}".toByteArray()), + dateTime = dateTime, + price = price + ) +} \ No newline at end of file diff --git a/src/main/kotlin/ie/daithi/electricityprices/model/ReePrice.kt b/src/main/kotlin/ie/daithi/electricityprices/model/ReePrice.kt new file mode 100644 index 0000000..c134aab --- /dev/null +++ b/src/main/kotlin/ie/daithi/electricityprices/model/ReePrice.kt @@ -0,0 +1,33 @@ +package ie.daithi.electricityprices.model + +import com.fasterxml.jackson.annotation.JsonProperty + +data class PriceValues ( + val value: Double, + val percentage: Double, + val datetime: String +) + +data class Attributes( + val title: String, + val description: String? = null, + val color: String? = null, + val type: String? = null, + val magnitude: String? = null, + val composite: Boolean, + @JsonProperty("last-update") + val lastUpdate: String, + val values: List +) + +data class Included( + val attributes: Attributes, + val id: String, + val type: String, + val groupId: String? = null +) + +data class ReePrice( + val data: Any, + val included: List, +) \ No newline at end of file diff --git a/src/main/kotlin/ie/daithi/electricityprices/repos/PriceRepo.kt b/src/main/kotlin/ie/daithi/electricityprices/repos/PriceRepo.kt new file mode 100644 index 0000000..a27fcf5 --- /dev/null +++ b/src/main/kotlin/ie/daithi/electricityprices/repos/PriceRepo.kt @@ -0,0 +1,11 @@ +package ie.daithi.electricityprices.repos + +import ie.daithi.electricityprices.model.Price +import org.springframework.data.repository.CrudRepository +import org.springframework.stereotype.Repository +import java.time.LocalDateTime + +@Repository +interface PriceRepo : CrudRepository { + fun dateTimeBetween(endDate: LocalDateTime, startDate: LocalDateTime): List +} \ No newline at end of file diff --git a/src/main/kotlin/ie/daithi/electricityprices/service/PriceManager.kt b/src/main/kotlin/ie/daithi/electricityprices/service/PriceManager.kt new file mode 100644 index 0000000..a1d962d --- /dev/null +++ b/src/main/kotlin/ie/daithi/electricityprices/service/PriceManager.kt @@ -0,0 +1,14 @@ +package ie.daithi.electricityprices.service + +import org.springframework.scheduling.annotation.EnableScheduling +import org.springframework.scheduling.annotation.Scheduled +import org.springframework.stereotype.Component + +@Component +@EnableScheduling +class PriceManager(private val priceService: PriceService) { + @Scheduled(cron = "0 * * * * *") + fun updatePriceData() { + priceService.updatePriceData() + } +} \ No newline at end of file diff --git a/src/main/kotlin/ie/daithi/electricityprices/service/PriceService.kt b/src/main/kotlin/ie/daithi/electricityprices/service/PriceService.kt new file mode 100644 index 0000000..ff38524 --- /dev/null +++ b/src/main/kotlin/ie/daithi/electricityprices/service/PriceService.kt @@ -0,0 +1,48 @@ +package ie.daithi.electricityprices.service + +import ie.daithi.electricityprices.model.Price +import ie.daithi.electricityprices.model.ReePrice +import ie.daithi.electricityprices.repos.PriceRepo +import org.apache.logging.log4j.LogManager +import org.springframework.stereotype.Service +import org.springframework.web.reactive.function.client.WebClient +import java.time.LocalDate +import java.time.LocalDateTime +import java.time.LocalTime +import java.time.format.DateTimeFormatter + +val dateFormatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd") +val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX") + +@Service +class PriceService( + private val priceRepo: PriceRepo, + private val reeRest: WebClient +) { + + private val logger = LogManager.getLogger(this::class.simpleName) + + fun getPrices(start: String?, end: String?): List { + val today = LocalDate.now() + val startDate = start?.let { LocalDateTime.parse(it, dateTimeFormatter) } ?: today.atStartOfDay() + val endDate = end?.let { LocalDateTime.parse(it, dateTimeFormatter) } ?: today.atTime(LocalTime.MIDNIGHT) + return priceRepo.dateTimeBetween(endDate.plusSeconds(1), startDate.minusSeconds(1)) + } + + // Calls to the API and update the latest prices + fun updatePriceData() { + logger.info("Updating price data") + val today = LocalDate.now().format(dateFormatter) + val thirtyDaysAgo = LocalDate.now().minusDays(30).format(dateFormatter) + val reePrices = reeRest.get().uri("?time_trunc=hour&start_date=${thirtyDaysAgo}T00:00&end_date=${today}T23:59").retrieve().bodyToMono(ReePrice::class.java).block() + + val pvpc = reePrices?.included?.find { it.id == "1001" } + val prices = pvpc?.attributes?.values?.map { Price( + dateTime = LocalDateTime.parse(it.datetime, dateTimeFormatter), + price = it.value / 1000 + ) } + + logger.info("Saving ${prices?.size} prices") + priceRepo.saveAll(prices ?: emptyList()) + } +} \ No newline at end of file diff --git a/src/main/kotlin/ie/daithi/electricityprices/web/controller/PriceController.kt b/src/main/kotlin/ie/daithi/electricityprices/web/controller/PriceController.kt new file mode 100644 index 0000000..12631ce --- /dev/null +++ b/src/main/kotlin/ie/daithi/electricityprices/web/controller/PriceController.kt @@ -0,0 +1,30 @@ +package ie.daithi.electricityprices.web.controller + +import ie.daithi.electricityprices.model.Price +import ie.daithi.electricityprices.service.PriceService +import io.swagger.annotations.Api +import io.swagger.annotations.ApiOperation +import io.swagger.annotations.ApiResponse +import io.swagger.annotations.ApiResponses +import org.springframework.http.HttpStatus +import org.springframework.web.bind.annotation.* +import java.time.LocalDateTime + +@RestController +@RequestMapping("/api/v1") +@Api(tags = ["Price"], description = "Endpoints that relate to electricity prices") +class PriceController( + private val priceSerice: PriceService +) { + + @GetMapping("/price") + @ResponseStatus(value = HttpStatus.OK) + @ApiOperation(value = "Get price info", notes = "Returns price info within the range provided. If no start date is provided the default is the start of the current day. If no end date is provided the default is the end of today. Dates should be given in a string form yyyy-MM-dd'T'HH:mm:ss.SSSXXX") + @ApiResponses( + ApiResponse(code = 200, message = "Request successful") + ) + @ResponseBody + fun getPrices(@RequestParam(required = false) start: String?, @RequestParam(required = false) end: String?): List { + return priceSerice.getPrices(start, end) + } +} \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..d76c621 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,27 @@ +server.address=0.0.0.0 +server.port=${PORT} + +server.error.include-message=always + +spring.jackson.default-property-inclusion=non_null +spring.mvc.pathmatch.matching-strategy=ant_path_matcher + +# MongoDB +spring.data.mongodb.uri=${MONGODB_URI:mongodb://localhost:27017/electricity-prices} +server.ssl.trusted-certificates=/etc/ssl/cert.pem + +# API +ree.url=https://apidatos.ree.es/en/datos/mercados/precios-mercados-tiempo-real + +# Logging +logging.level.org.springframework.web=WARN +logging.level.ie.daithi=${LOGGING_LEVEL:INFO} + + +# Logging pattern for the console +logging.pattern.console= %d{yyyy-MM-dd HH:mm:ss} - %msg%n + +# Logging pattern for file +logging.pattern.file= %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n +logging.file=./logs/application.log +#logging.level.org.springframework.data.mongodb=DEBUG \ No newline at end of file diff --git a/src/test/kotlin/ie/daithi/electricityprices/ElectricityPricesApplicationTests.kt b/src/test/kotlin/ie/daithi/electricityprices/ElectricityPricesApplicationTests.kt new file mode 100644 index 0000000..c66900c --- /dev/null +++ b/src/test/kotlin/ie/daithi/electricityprices/ElectricityPricesApplicationTests.kt @@ -0,0 +1,13 @@ +package ie.daithi.electricityprices + +import org.junit.jupiter.api.Test +import org.springframework.boot.test.context.SpringBootTest + +@SpringBootTest +class ElectricityPricesApplicationTests { + + @Test + fun contextLoads() { + } + +} diff --git a/system.properties b/system.properties new file mode 100644 index 0000000..8b2c327 --- /dev/null +++ b/system.properties @@ -0,0 +1,2 @@ +# Java Runtime +java.runtime.version=17 \ No newline at end of file diff --git a/temp/precios-mercados-tiempo-real.json b/temp/precios-mercados-tiempo-real.json new file mode 100644 index 0000000..b8cd7f5 --- /dev/null +++ b/temp/precios-mercados-tiempo-real.json @@ -0,0 +1,290 @@ +{ + "data": { + "type": "Precios mercado peninsular en tiempo real", + "id": "mer13", + "attributes": { + "title": "Precios mercado peninsular en tiempo real", + "last-update": "2023-03-24T20:20:13.000+01:00", + "description": null + }, + "meta": { + "cache-control": { + "cache": "MISS" + } + } + }, + "included": [ + { + "type": "PVPC (\u20ac\/MWh)", + "id": "1001", + "groupId": null, + "attributes": { + "title": "PVPC (\u20ac\/MWh)", + "description": null, + "color": "#ffcf09", + "type": null, + "magnitude": "price", + "composite": false, + "last-update": "2023-03-24T20:20:13.000+01:00", + "values": [ + { + "value": 87.31, + "percentage": 0.6372062472631732, + "datetime": "2023-03-25T00:00:00.000+01:00" + }, + { + "value": 88.45, + "percentage": 0.6438814879522458, + "datetime": "2023-03-25T01:00:00.000+01:00" + }, + { + "value": 89.97, + "percentage": 0.6469403897317898, + "datetime": "2023-03-25T02:00:00.000+01:00" + }, + { + "value": 98.71, + "percentage": 0.6319057678765765, + "datetime": "2023-03-25T03:00:00.000+01:00" + }, + { + "value": 96.11, + "percentage": 0.6364900662251656, + "datetime": "2023-03-25T04:00:00.000+01:00" + }, + { + "value": 98.74, + "percentage": 0.6315318196354334, + "datetime": "2023-03-25T05:00:00.000+01:00" + }, + { + "value": 94.74, + "percentage": 0.6326544240400668, + "datetime": "2023-03-25T06:00:00.000+01:00" + }, + { + "value": 108.46, + "percentage": 0.611973142244541, + "datetime": "2023-03-25T07:00:00.000+01:00" + }, + { + "value": 93.38, + "percentage": 0.655850540806293, + "datetime": "2023-03-25T08:00:00.000+01:00" + }, + { + "value": 68.2, + "percentage": 0.6788771650408122, + "datetime": "2023-03-25T09:00:00.000+01:00" + }, + { + "value": 52.5, + "percentage": 0.7241379310344828, + "datetime": "2023-03-25T10:00:00.000+01:00" + }, + { + "value": 54.49, + "percentage": 0.6942285641482991, + "datetime": "2023-03-25T11:00:00.000+01:00" + }, + { + "value": 31.19, + "percentage": 0.9397408858089787, + "datetime": "2023-03-25T12:00:00.000+01:00" + }, + { + "value": 30.01, + "percentage": 0.9454946439823566, + "datetime": "2023-03-25T13:00:00.000+01:00" + }, + { + "value": 28, + "percentage": 0.9964412811387899, + "datetime": "2023-03-25T14:00:00.000+01:00" + }, + { + "value": 27.31, + "percentage": 1, + "datetime": "2023-03-25T15:00:00.000+01:00" + }, + { + "value": 33.1, + "percentage": 0.9486959014044138, + "datetime": "2023-03-25T16:00:00.000+01:00" + }, + { + "value": 39.41, + "percentage": 0.7976118194697429, + "datetime": "2023-03-25T17:00:00.000+01:00" + }, + { + "value": 79.47, + "percentage": 0.6389804615260914, + "datetime": "2023-03-25T18:00:00.000+01:00" + }, + { + "value": 84.54, + "percentage": 0.6024371125204874, + "datetime": "2023-03-25T19:00:00.000+01:00" + }, + { + "value": 108.29, + "percentage": 0.584435209671326, + "datetime": "2023-03-25T20:00:00.000+01:00" + }, + { + "value": 99.72, + "percentage": 0.5910033781781544, + "datetime": "2023-03-25T21:00:00.000+01:00" + }, + { + "value": 88.61, + "percentage": 0.6006643167028201, + "datetime": "2023-03-25T22:00:00.000+01:00" + }, + { + "value": 76.93, + "percentage": 0.6112832737385777, + "datetime": "2023-03-25T23:00:00.000+01:00" + } + ] + } + }, + { + "type": "Spot market price (\u20ac\/MWh)", + "id": "600", + "groupId": null, + "attributes": { + "title": "Spot market price (\u20ac\/MWh)", + "description": null, + "color": "#df4a32", + "type": null, + "magnitude": "price", + "composite": false, + "last-update": "2023-03-24T14:13:55.000+01:00", + "values": [ + { + "value": 49.71, + "percentage": 0.36279375273682674, + "datetime": "2023-03-25T00:00:00.000+01:00" + }, + { + "value": 48.92, + "percentage": 0.35611851204775424, + "datetime": "2023-03-25T01:00:00.000+01:00" + }, + { + "value": 49.1, + "percentage": 0.35305961026821026, + "datetime": "2023-03-25T02:00:00.000+01:00" + }, + { + "value": 57.5, + "percentage": 0.3680942321234236, + "datetime": "2023-03-25T03:00:00.000+01:00" + }, + { + "value": 54.89, + "percentage": 0.3635099337748344, + "datetime": "2023-03-25T04:00:00.000+01:00" + }, + { + "value": 57.61, + "percentage": 0.3684681803645667, + "datetime": "2023-03-25T05:00:00.000+01:00" + }, + { + "value": 55.01, + "percentage": 0.3673455759599332, + "datetime": "2023-03-25T06:00:00.000+01:00" + }, + { + "value": 68.77, + "percentage": 0.38802685775545903, + "datetime": "2023-03-25T07:00:00.000+01:00" + }, + { + "value": 49, + "percentage": 0.344149459193707, + "datetime": "2023-03-25T08:00:00.000+01:00" + }, + { + "value": 32.26, + "percentage": 0.3211228349591877, + "datetime": "2023-03-25T09:00:00.000+01:00" + }, + { + "value": 20, + "percentage": 0.27586206896551724, + "datetime": "2023-03-25T10:00:00.000+01:00" + }, + { + "value": 24, + "percentage": 0.3057714358517008, + "datetime": "2023-03-25T11:00:00.000+01:00" + }, + { + "value": 2, + "percentage": 0.060259114191021396, + "datetime": "2023-03-25T12:00:00.000+01:00" + }, + { + "value": 1.73, + "percentage": 0.05450535601764335, + "datetime": "2023-03-25T13:00:00.000+01:00" + }, + { + "value": 0.1, + "percentage": 0.0035587188612099642, + "datetime": "2023-03-25T14:00:00.000+01:00" + }, + { + "value": 0, + "percentage": 0, + "datetime": "2023-03-25T15:00:00.000+01:00" + }, + { + "value": 1.79, + "percentage": 0.05130409859558613, + "datetime": "2023-03-25T16:00:00.000+01:00" + }, + { + "value": 10, + "percentage": 0.20238818053025703, + "datetime": "2023-03-25T17:00:00.000+01:00" + }, + { + "value": 44.9, + "percentage": 0.3610195384739085, + "datetime": "2023-03-25T18:00:00.000+01:00" + }, + { + "value": 55.79, + "percentage": 0.3975628874795125, + "datetime": "2023-03-25T19:00:00.000+01:00" + }, + { + "value": 77, + "percentage": 0.41556479032867394, + "datetime": "2023-03-25T20:00:00.000+01:00" + }, + { + "value": 69.01, + "percentage": 0.40899662182184554, + "datetime": "2023-03-25T21:00:00.000+01:00" + }, + { + "value": 58.91, + "percentage": 0.39933568329718006, + "datetime": "2023-03-25T22:00:00.000+01:00" + }, + { + "value": 48.92, + "percentage": 0.38871672626142234, + "datetime": "2023-03-25T23:00:00.000+01:00" + } + ] + } + } + ] +}