Add settings and extension recommendations (#139)

- Added recommended settings for the Pylance and Pyright extensions
- Enabled pytest and debugging support in configuration
- Reformatted code with Prettier
---------
Co-authored-by: Chris <git@nootch.de>
This commit is contained in:
Chris 2024-11-10 23:00:16 +01:00 committed by GitHub
parent 1ed06fc270
commit de9fe2ddc9
10 changed files with 135 additions and 84 deletions

View File

@ -16,7 +16,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
python-version: "3.12"
- name: Install dependencies
run: |
@ -26,4 +26,4 @@ jobs:
- name: Run Pytest
run: |
pip install -e .
python -m pytest -vs --cov modules --cov-report term-missing tests/
python -m pytest -vs --cov src --cov-report term-missing tests/

4
.gitignore vendored
View File

@ -4,9 +4,7 @@ output/
# Default ignore folders and files for VS Code, Python
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/*.shared.json
!.vscode/extensions.json
!.vscode/*.code-snippets

View File

@ -1,24 +1,24 @@
# Exclude some file types from automatic code style
exclude: \.(json|csv)$
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-merge-conflict
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
name: isort
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.8
hooks:
# Run the linter and fix simple issues automatically
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-merge-conflict
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
name: isort
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.8
hooks:
# Run the linter and fix simple issues automatically
- id: ruff
args: [--fix]
# Run the formatter.
- id: ruff-format

14
.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,14 @@
{
"recommendations": [
//python
"ms-python.python",
"ms-python.debugpy",
"charliermarsh.ruff",
"ms-python.mypy-type-checker",
// misc
"swellaby.workspace-config-plus", // allows user and shared settings
"christian-kohler.path-intellisense",
"esbenp.prettier-vscode"
]
}

13
.vscode/settings.shared.json vendored Normal file
View File

@ -0,0 +1,13 @@
{
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff"
},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.defaultFoldingRangeProvider": "charliermarsh.ruff",
"editor.formatOnSave": true,
"python.analysis.autoImportCompletions": true,
"mypy-type-checker.importStrategy": "fromEnvironment",
"python.testing.pytestArgs": [],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}

View File

@ -6,7 +6,7 @@ The `EOS` project is in early development, therefore we encourage contribution i
## Bug Reports
Please report flaws or vulnerabilities in the [GitHub Issue Tracker]((https://github.com/Akkudoktor-EOS/EOS/issues)) using the corresponding issue template.
Please report flaws or vulnerabilities in the [GitHub Issue Tracker](https://github.com/Akkudoktor-EOS/EOS/issues) using the corresponding issue template.
## Ideas & Features
@ -44,5 +44,5 @@ pre-commit run --all-files
Use `pytest` to run tests locally:
```bash
python -m pytest -vs --cov modules --cov-report term-missing tests/
python -m pytest -vs --cov src --cov-report term-missing tests/
```

View File

@ -68,7 +68,7 @@ test-setup: pip-dev
# Target to run tests.
test:
@echo "Running tests..."
.venv/bin/pytest
.venv/bin/pytest -vs --cov src --cov-report term-missing
# Run entire setup on docker
docker-run:

116
README.md
View File

@ -56,6 +56,7 @@ To always use the Python version from the virtual environment, you should activa
```bash
source .venv/bin/activate
```
(for Bash users, the default under Linux) or
```zsh
@ -93,7 +94,6 @@ These classes work together to enable a detailed simulation and optimization of
Each class is designed to be easily customized and extended to integrate additional functions or improvements. For example, new methods can be added for more accurate modeling of PV system or battery behavior. Developers are invited to modify and extend the system according to their needs.
# Input for the Flask Server (as of 30.07.2024)
Describes the structure and data types of the JSON object sent to the Flask server, with a forecast period of 48 hours.
@ -101,75 +101,88 @@ Describes the structure and data types of the JSON object sent to the Flask serv
## JSON Object Fields
### `strompreis_euro_pro_wh`
- **Description**: An array of floats representing the electricity price in euros per watt-hour for different time intervals.
- **Type**: Array
- **Element Type**: Float
- **Length**: 48
### `gesamtlast`
- **Description**: An array of floats representing the total load (consumption) in watts for different time intervals.
- **Type**: Array
- **Element Type**: Float
- **Length**: 48
### `pv_forecast`
- **Description**: An array of floats representing the forecasted photovoltaic output in watts for different time intervals.
- **Type**: Array
- **Element Type**: Float
- **Length**: 48
### `temperature_forecast`
- **Description**: An array of floats representing the temperature forecast in degrees Celsius for different time intervals.
- **Type**: Array
- **Element Type**: Float
- **Length**: 48
### `pv_soc`
- **Description**: An integer representing the state of charge of the PV battery at the **start** of the current hour (not the current state).
- **Type**: Integer
### `pv_akku_cap`
- **Description**: An integer representing the capacity of the photovoltaic battery in watt-hours.
- **Type**: Integer
### `einspeiseverguetung_euro_pro_wh`
- **Description**: A float representing the feed-in compensation in euros per watt-hour.
- **Type**: Float
### `eauto_min_soc`
- **Description**: An integer representing the minimum state of charge (SOC) of the electric vehicle in percentage.
- **Type**: Integer
### `eauto_cap`
- **Description**: An integer representing the capacity of the electric vehicle battery in watt-hours.
- **Type**: Integer
### `eauto_charge_efficiency`
- **Description**: A float representing the charging efficiency of the electric vehicle.
- **Type**: Float
### `eauto_charge_power`
- **Description**: An integer representing the charging power of the electric vehicle in watts.
- **Type**: Integer
### `eauto_soc`
- **Description**: An integer representing the current state of charge (SOC) of the electric vehicle in percentage.
- **Type**: Integer
### `start_solution`
- **Description**: Can be `null` or contain a previous solution (if available).
- **Type**: `null` or object
### `haushaltsgeraet_wh`
- **Description**: An integer representing the energy consumption of a household device in watt-hours.
- **Type**: Integer
### `haushaltsgeraet_dauer`
- **Description**: An integer representing the usage duration of a household device in hours.
- **Type**: Integer
# JSON Output Description
This document describes the structure and data types of the JSON output returned by the Flask server, with a forecast period of 48 hours.
@ -179,9 +192,11 @@ This document describes the structure and data types of the JSON output returned
## JSON Output Fields (as of 30.7.2024)
### discharge_hours_bin
An array that indicates for each hour of the forecast period (in this example, 48 hours) whether energy is discharged from the battery or not. The values are either `0` (no discharge) or `1` (discharge).
### eauto_obj
This object contains information related to the electric vehicle and its charging and discharging behavior:
- **charge_array**: Indicates for each hour whether the EV is charging (`0` for no charging, `1` for charging).
@ -210,12 +225,15 @@ This object contains information related to the electric vehicle and its chargin
- **Type**: Integer
### eautocharge_hours_float
An array of binary values (0 or 1) that indicates whether the EV will be charged in a certain hour.
- **Type**: Array
- **Element Type**: Integer (0 or 1)
- **Length**: 48
### result
This object contains the results of the simulation and provides insights into various parameters over the entire forecast period:
- **E-Auto_SoC_pro_Stunde**: The state of charge of the EV for each hour.
@ -264,57 +282,61 @@ This object contains the results of the simulation and provides insights into va
- **Length**: 35
### simulation_data
An object containing the simulated data.
- **E-Auto_SoC_pro_Stunde**: An array of floats representing the simulated state of charge of the electric car per hour.
- **Type**: Array
- **Element Type**: Float
- **Length**: 35
- **Eigenverbrauch_Wh_pro_Stunde**: An array of floats representing the simulated self-consumption in watt-hours per hour.
- **Type**: Array
- **Element Type**: Float
- **Length**: 35
- **Einnahmen_Euro_pro_Stunde**: An array of floats representing the simulated income in euros per hour.
- **Type**: Array
- **Element Type**: Float
- **Length**: 35
- **Gesamt_Verluste**: The total simulated losses in watt-hours.
- **Type**: Float
- **Gesamtbilanz_Euro**: The total simulated balance in euros.
- **Type**: Float
- **Gesamteinnahmen_Euro**: The total simulated income in euros.
- **Type**: Float
- **Gesamtkosten_Euro**: The total simulated costs in euros.
- **Type**: Float
- **Haushaltsgeraet_wh_pro_stunde**: An array of floats representing the simulated energy consumption of a household appliance in watt-hours per hour.
- **Type**: Array
- **Element Type**: Float
- **Length**: 35
- **Kosten_Euro_pro_Stunde**: An array of floats representing the simulated costs in euros per hour.
- **Type**: Array
- **Element Type**: Float
- **Length**: 35
- **Netzbezug_Wh_pro_Stunde**: An array of floats representing the simulated grid consumption in watt-hours per hour.
- **Type**: Array
- **Element Type**: Float
- **Length**: 35
- **Netzeinspeisung_Wh_pro_Stunde**: An array of floats representing the simulated grid feed-in in watt-hours per hour.
- **Type**: Array
- **Element Type**: Float
- **Length**: 35
- **Verluste_Pro_Stunde**: An array of floats representing the simulated losses per hour.
- **Type**: Array
- **Element Type**: Float
- **Length**: 35
- **akku_soc_pro_stunde**: An array of floats representing the simulated state of charge of the battery in percentage per hour.
- **Type**: Array
- **Element Type**: Float
- **Length**: 35
- **E-Auto_SoC_pro_Stunde**: An array of floats representing the simulated state of charge of the electric car per hour.
- **Type**: Array
- **Element Type**: Float
- **Length**: 35
- **Eigenverbrauch_Wh_pro_Stunde**: An array of floats representing the simulated self-consumption in watt-hours per hour.
- **Type**: Array
- **Element Type**: Float
- **Length**: 35
- **Einnahmen_Euro_pro_Stunde**: An array of floats representing the simulated income in euros per hour.
- **Type**: Array
- **Element Type**: Float
- **Length**: 35
- **Gesamt_Verluste**: The total simulated losses in watt-hours.
- **Type**: Float
- **Gesamtbilanz_Euro**: The total simulated balance in euros.
- **Type**: Float
- **Gesamteinnahmen_Euro**: The total simulated income in euros.
- **Type**: Float
- **Gesamtkosten_Euro**: The total simulated costs in euros.
- **Type**: Float
- **Haushaltsgeraet_wh_pro_stunde**: An array of floats representing the simulated energy consumption of a household appliance in watt-hours per hour.
- **Type**: Array
- **Element Type**: Float
- **Length**: 35
- **Kosten_Euro_pro_Stunde**: An array of floats representing the simulated costs in euros per hour.
- **Type**: Array
- **Element Type**: Float
- **Length**: 35
- **Netzbezug_Wh_pro_Stunde**: An array of floats representing the simulated grid consumption in watt-hours per hour.
- **Type**: Array
- **Element Type**: Float
- **Length**: 35
- **Netzeinspeisung_Wh_pro_Stunde**: An array of floats representing the simulated grid feed-in in watt-hours per hour.
- **Type**: Array
- **Element Type**: Float
- **Length**: 35
- **Verluste_Pro_Stunde**: An array of floats representing the simulated losses per hour.
- **Type**: Array
- **Element Type**: Float
- **Length**: 35
- **akku_soc_pro_stunde**: An array of floats representing the simulated state of charge of the battery in percentage per hour.
- **Type**: Array
- **Element Type**: Float
- **Length**: 35
### spuelstart
- **Description**: Can be `null` or contain an object representing the start of washing (if applicable).
- **Type**: null or object
### start_solution
- **Description**: An array of binary values (0 or 1) representing a possible starting solution for the simulation.
- **Type**: Array
- **Element Type**: Integer (0 or 1)

View File

@ -1,22 +1,22 @@
---
networks:
eos:
name: 'eos'
name: "eos"
services:
eos:
image: 'akkudoktor/eos:${EOS_VERSION}'
image: "akkudoktor/eos:${EOS_VERSION}"
read_only: true
build:
context: .
dockerfile: 'Dockerfile'
dockerfile: "Dockerfile"
args:
PYTHON_VERSION: '${PYTHON_VERSION}'
PYTHON_VERSION: "${PYTHON_VERSION}"
init: true
environment:
FLASK_RUN_PORT: '${EOS_PORT}'
FLASK_RUN_PORT: "${EOS_PORT}"
networks:
- 'eos'
- "eos"
volumes:
- ./src/akkudoktoreos/config.py:/opt/eos/akkudoktoreos/config.py:ro
ports:
- '${EOS_PORT}:${EOS_PORT}'
- "${EOS_PORT}:${EOS_PORT}"

View File

@ -33,6 +33,11 @@ include = ["akkudoktoreos", "akkudoktoreosserver", ]
[tool.setuptools.package-data]
akkudoktoreosserver = ["data/*.npz", ]
[tool.pyright]
# used in Pylance extension for language server
# type check is done by mypy, disable to avoid unwanted errors
typeCheckingMode = "off"
[tool.isort]
profile = "black"
@ -46,6 +51,5 @@ ignore = [
[tool.pytest.ini_options]
minversion = "8.3.3"
addopts = "--cov=src"
pythonpath = [ "src", ]
testpaths = [ "tests", ]