Skip to content

Commit 96e53b2

Browse files
committed
Add basic example about framework usage.
1 parent ce6e036 commit 96e53b2

File tree

17 files changed

+2358
-3
lines changed

17 files changed

+2358
-3
lines changed

.vscode/settings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,29 @@
88
"autouse",
99
"bemcom",
1010
"caplog",
11+
"cecinverter",
1112
"dataframe",
1213
"datapoint",
1314
"datapoints",
1415
"docstrings",
1516
"dotenv",
17+
"fooc",
18+
"iloc",
1619
"instrumentator",
1720
"jwks",
1821
"JWTs",
1922
"Keycloak",
2023
"levelname",
24+
"meteo",
25+
"modelchain",
2126
"MQTT",
2227
"oidc",
2328
"oneshot",
29+
"pvlib",
30+
"pvsystem",
2431
"pyjwt",
2532
"redoc",
33+
"Sandia",
2634
"Setpoint",
2735
"setpoints",
2836
"UNVALIDATED",

build-docker-images.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
# USAGE:
3+
#
4+
# Build `latest` images with:
5+
# bash build-docker-images.sh
6+
#
7+
# Build specific version, e.g. 0.1.0 with:
8+
# bash build-docker-images.sh 0.1.0
9+
set -euo pipefail
10+
11+
IMAGE_NAME="energy_service_generics"
12+
SOURCE_PATH="./source"
13+
IMAGE_TAG_BASE=${1:-latest}
14+
15+
16+
# Build each of the four versions of the image and check directly
17+
# afterwards if the image works as expected by executing the tests.
18+
# This way the script should fail faster if it doesn't make sense to
19+
# build another version, as the tests will fail anyway to the problems
20+
# already present in the the previous build.
21+
# NOTE: The builds are in such an order that as much as possible of layers
22+
# can be reused to keep build times low.
23+
docker build --target esg-base -t $IMAGE_NAME:${IMAGE_TAG_BASE} $SOURCE_PATH
24+
docker run --rm -t $IMAGE_NAME:$IMAGE_TAG_BASE pytest
25+
docker build --target esg-service -t $IMAGE_NAME:${IMAGE_TAG_BASE}-service $SOURCE_PATH
26+
docker run --rm -t $IMAGE_NAME:${IMAGE_TAG_BASE}-service pytest
27+
docker build --target esg-pandas -t $IMAGE_NAME:${IMAGE_TAG_BASE}-pandas $SOURCE_PATH
28+
docker run --rm -t $IMAGE_NAME:${IMAGE_TAG_BASE}-pandas pytest
29+
docker build --target esg-service-pandas -t $IMAGE_NAME:${IMAGE_TAG_BASE}-service-pandas $SOURCE_PATH
30+
docker run --rm -t $IMAGE_NAME:${IMAGE_TAG_BASE}-service-pandas pytest
31+
32+
printf "\033[0;32m\n" # Make text green
33+
printf "Success! "
34+
printf "\033[0m" # Make text normal again.
35+
printf "Built these images:\n"
36+
echo $IMAGE_NAME:$IMAGE_TAG_BASE
37+
echo $IMAGE_NAME:${IMAGE_TAG_BASE}-service
38+
echo $IMAGE_NAME:${IMAGE_TAG_BASE}-pandas
39+
echo $IMAGE_NAME:${IMAGE_TAG_BASE}-service-pandas
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2024 FZI Research Center for Information Technology
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-FileCopyrightText: 2024 FZI Research Center for Information Technology
16+
# SPDX-License-Identifier: Apache-2.0
17+
18+
services:
19+
energy-service-generics-basic-example-autotest:
20+
container_name: energy-service-generics-basic-example-autotest
21+
build:
22+
context: ./source
23+
dockerfile: Dockerfile-worker
24+
init: true # Faster shutdown.
25+
entrypoint: [ "auto-pytest" ]
26+
command: [ "/source/service/" ]
27+
tty: true # Colorize output.
28+
restart: unless-stopped
29+
volumes:
30+
- ./source/service:/source/service/
31+
user: "${USER_ID:-1000}:${GROUP_ID:-1000}"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM energy_service_generics:latest-service
2+
3+
COPY api.py data_model.py worker.py /source/service/
4+
5+
CMD ["/source/service/api.py"]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM energy_service_generics:latest-service-pandas
2+
3+
RUN pip install pvlib scipy
4+
COPY service/ /source/service/
5+
6+
ENTRYPOINT [ "celery" ]
7+
CMD [ "--app", "worker", "worker", "--loglevel=INFO" ]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
Tests for content of fooc.py
3+
4+
Copyright 2024 FZI Research Center for Information Technology
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
SPDX-FileCopyrightText: 2024 FZI Research Center for Information Technology
19+
SPDX-License-Identifier: Apache-2.0
20+
"""
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
Copyright 2024 FZI Research Center for Information Technology
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-FileCopyrightText: 2024 FZI Research Center for Information Technology
17+
SPDX-License-Identifier: Apache-2.0
18+
"""
19+
20+
from packaging.version import Version
21+
22+
from esg.service.api import API
23+
24+
from data_model import RequestArguments, RequestOutput
25+
from data_model import FittedParameters, Observations
26+
from data_model import FitParameterArguments
27+
from worker import request_task, fit_parameters_task
28+
29+
api = API(
30+
RequestArguments=RequestArguments,
31+
RequestOutput=RequestOutput,
32+
FittedParameters=FittedParameters,
33+
Observations=Observations,
34+
FitParameterArguments=FitParameterArguments,
35+
request_task=request_task,
36+
fit_parameters_task=fit_parameters_task,
37+
title="PV Power Prediction Example Service",
38+
version=Version("0.0.1"),
39+
)
40+
41+
if __name__ == "__main__":
42+
api.run()
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""
2+
Definition of the data models for de-/serializing data and the docs.
3+
4+
Copyright 2024 FZI Research Center for Information Technology
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
SPDX-FileCopyrightText: 2024 FZI Research Center for Information Technology
19+
SPDX-License-Identifier: Apache-2.0
20+
"""
21+
22+
from esg.models.base import _BaseModel
23+
from esg.models.datapoint import ValueMessageList
24+
from esg.models.metadata import GeographicPosition, PVSystem
25+
from pydantic import Field
26+
27+
28+
class RequestArguments(_BaseModel):
29+
geographic_position: GeographicPosition
30+
31+
32+
class RequestOutput(_BaseModel):
33+
power_prediction: ValueMessageList = Field(
34+
description="Prediction of power production in W"
35+
)
36+
37+
38+
class FittedParameters(_BaseModel):
39+
pv_system: PVSystem
40+
41+
42+
class Observations(_BaseModel):
43+
measured_power: ValueMessageList = Field(
44+
description="Measured power production in W"
45+
)
46+
47+
48+
class FitParameterArguments(_BaseModel):
49+
geographic_position: GeographicPosition

0 commit comments

Comments
 (0)