From 04d7a3ccc40525ac6813d238b6615836654ac441 Mon Sep 17 00:00:00 2001 From: Charlotte Avery <143102500+charlotte-avery@users.noreply.github.com> Date: Fri, 12 Jul 2024 14:31:45 +0100 Subject: [PATCH 01/10] Publish to PyPI upon GitHub release (#2) * Publish to PyPI upon GitHub release Following: https://www.seanh.cc/2022/05/21/publishing-python-packages-from-github-actions/ * Use latest version * Use consistent syntax --- .github/workflows/publish.yml | 18 ++++++++++++++++++ pyproject.toml | 5 +++++ 2 files changed, 23 insertions(+) create mode 100644 .github/workflows/publish.yml create mode 100644 pyproject.toml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..b8e8a1b --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,18 @@ +name: Publish to PyPI.org +on: + release: + types: [published] +jobs: + pypi: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Build package + run: python3 -m pip install --upgrade build && python3 -m build + - name: Publish package + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..a816384 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,5 @@ +[build-system] +requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"] +build-backend = "setuptools.build_meta" + +[tool.setuptools_scm] From 8b0679b6c366c0bbad7a432ec23362755cb3a1c1 Mon Sep 17 00:00:00 2001 From: Charlotte Avery Date: Fri, 12 Jul 2024 15:01:20 +0100 Subject: [PATCH 02/10] Update setup --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index a5c35c1..558555f 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -from setuptools import find_packages, setup +from setuptools import setup setup( name="smart-buildings-rating-calculator", @@ -9,7 +9,7 @@ long_description=open("README.md").read(), long_description_content_type="text/markdown", url="https://github.com/centrefornetzero/smart-building-rating-calculator", - packages=find_packages("src", package_dir={"": "src"}), + package_dir={"": "src"}, classifiers=[ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", From 31c97e084332787ddf0076148595d812faf679fd Mon Sep 17 00:00:00 2001 From: Charlotte Avery Date: Fri, 12 Jul 2024 16:09:13 +0100 Subject: [PATCH 03/10] Remove version number from setup --- setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.py b/setup.py index 558555f..5ce596e 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,6 @@ setup( name="smart-buildings-rating-calculator", - version="0.2.0", author="Centre for Net Zero", author_email="data@centrefornetzero.org", description="The calculation to generate a smart building rating", From 5a17ca369db3c536d678380cf656431bd4b0ac6c Mon Sep 17 00:00:00 2001 From: ianlmgoddard Date: Mon, 29 Jul 2024 15:02:52 +0100 Subject: [PATCH 04/10] remove relative imports, edit setup to find package and install deps --- README.md | 4 ++-- setup.py | 8 ++++++-- .../calculate_sbr_score.py | 8 ++++---- src/smart_building_rating_calculator/flex_archetype.py | 4 ++-- .../initiate_user_inputs.py | 2 +- .../intermediate_scoring.py | 2 +- tests/test_sbr_calculator.py | 10 +++++----- 7 files changed, 21 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 88c4b78..4628bee 100644 --- a/README.md +++ b/README.md @@ -44,8 +44,8 @@ Inputs must have datatypes as defined in `src/smart_building_rating_calculator/i Example of how to call `sbr_score` in python: ```ruby -from src.smart_building_rating_calculator.calculate_sbr_score import sbr_score -from src.smart_building_rating_calculator.inputs import ( +from smart_building_rating_calculator.calculate_sbr_score import sbr_score +from smart_building_rating_calculator.inputs import ( BatterySize, EVChargerPower, HeatingSource, diff --git a/setup.py b/setup.py index 5ce596e..b413ba3 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -from setuptools import setup +from setuptools import find_packages, setup setup( name="smart-buildings-rating-calculator", @@ -9,10 +9,14 @@ long_description_content_type="text/markdown", url="https://github.com/centrefornetzero/smart-building-rating-calculator", package_dir={"": "src"}, + packages=find_packages(where="src"), + install_requires=[ + "pandas", + ], classifiers=[ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", ], - python_requires="==3.11", + python_requires=">=3.11", ) diff --git a/src/smart_building_rating_calculator/calculate_sbr_score.py b/src/smart_building_rating_calculator/calculate_sbr_score.py index 2946a7d..ecd02c5 100644 --- a/src/smart_building_rating_calculator/calculate_sbr_score.py +++ b/src/smart_building_rating_calculator/calculate_sbr_score.py @@ -2,9 +2,9 @@ import pandas as pd -from src.smart_building_rating_calculator.flex_archetype import calc_flex_archetype -from src.smart_building_rating_calculator.initiate_user_inputs import prep_user_inputs -from src.smart_building_rating_calculator.inputs import ( +from smart_building_rating_calculator.flex_archetype import calc_flex_archetype +from smart_building_rating_calculator.initiate_user_inputs import prep_user_inputs +from smart_building_rating_calculator.inputs import ( BatterySize, EVChargerPower, HeatingSource, @@ -12,7 +12,7 @@ SolarInverterSize, UserInputs, ) -from src.smart_building_rating_calculator.intermediate_scoring import calc_sbr_score +from smart_building_rating_calculator.intermediate_scoring import calc_sbr_score def calc_sbr(sbr_val: float) -> str: diff --git a/src/smart_building_rating_calculator/flex_archetype.py b/src/smart_building_rating_calculator/flex_archetype.py index 219cf32..98c234a 100644 --- a/src/smart_building_rating_calculator/flex_archetype.py +++ b/src/smart_building_rating_calculator/flex_archetype.py @@ -2,8 +2,8 @@ Based on Andy's calcuations, this module calculates the flex archetype of a building based on the user inputs and the SBR value. """ -from src.smart_building_rating_calculator.flexer_enums import FlexArchetype -from src.smart_building_rating_calculator.inputs import ( +from smart_building_rating_calculator.flexer_enums import FlexArchetype +from smart_building_rating_calculator.inputs import ( HeatingSource, HotWaterSource, UserInputs, diff --git a/src/smart_building_rating_calculator/initiate_user_inputs.py b/src/smart_building_rating_calculator/initiate_user_inputs.py index ca1789a..ef4b441 100644 --- a/src/smart_building_rating_calculator/initiate_user_inputs.py +++ b/src/smart_building_rating_calculator/initiate_user_inputs.py @@ -1,4 +1,4 @@ -from src.smart_building_rating_calculator.inputs import ( +from smart_building_rating_calculator.inputs import ( BatterySize, EVChargerPower, HeatingSource, diff --git a/src/smart_building_rating_calculator/intermediate_scoring.py b/src/smart_building_rating_calculator/intermediate_scoring.py index 3803189..c729ff5 100644 --- a/src/smart_building_rating_calculator/intermediate_scoring.py +++ b/src/smart_building_rating_calculator/intermediate_scoring.py @@ -1,7 +1,7 @@ from dataclasses import replace from typing import List -from src.smart_building_rating_calculator.inputs import ( +from smart_building_rating_calculator.inputs import ( BatterySize, EVChargerPower, HeatingSource, diff --git a/tests/test_sbr_calculator.py b/tests/test_sbr_calculator.py index b2b1590..b81e436 100644 --- a/tests/test_sbr_calculator.py +++ b/tests/test_sbr_calculator.py @@ -5,13 +5,13 @@ import pytest -from src.smart_building_rating_calculator.calculate_sbr_score import ( +from smart_building_rating_calculator.calculate_sbr_score import ( get_sbr_scores, sbr_score, ) -from src.smart_building_rating_calculator.flex_archetype import FlexArchetype -from src.smart_building_rating_calculator.initiate_user_inputs import prep_user_inputs -from src.smart_building_rating_calculator.inputs import ( +from smart_building_rating_calculator.flex_archetype import FlexArchetype +from smart_building_rating_calculator.initiate_user_inputs import prep_user_inputs +from smart_building_rating_calculator.inputs import ( BatterySize, EVChargerPower, HeatingSource, @@ -19,7 +19,7 @@ SolarInverterSize, UserInputs, ) -from src.smart_building_rating_calculator.intermediate_scoring import ( +from smart_building_rating_calculator.intermediate_scoring import ( calc_alternative_heating_score, calc_alternative_hot_water_score, calc_elec_heating_score, From 0ae8d690c74aa9fd7a35d6b1b77d41367a8da00a Mon Sep 17 00:00:00 2001 From: ianlmgoddard Date: Mon, 29 Jul 2024 15:21:58 +0100 Subject: [PATCH 05/10] export functions and inputs to public API --- src/__init__.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/__init__.py b/src/__init__.py index e69de29..f42e651 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -0,0 +1,17 @@ +from smart_building_rating_calculator.calculate_sbr_score import sbr_score +from smart_building_rating_calculator.inputs import ( + BatterySize, + EVChargerPower, + HeatingSource, + HotWaterSource, + SolarInverterSize, +) + +__all__ = [ + "sbr_score", + "BatterySize", + "EVChargerPower", + "HeatingSource", + "HotWaterSource", + "SolarInverterSize", +] From 68fc65f7bebc92fd88513cc6b5724a436988ee56 Mon Sep 17 00:00:00 2001 From: ianlmgoddard Date: Mon, 29 Jul 2024 15:34:07 +0100 Subject: [PATCH 06/10] move exports to correct folder --- src/__init__.py | 17 ----------------- .../__init__.py | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/__init__.py b/src/__init__.py index f42e651..e69de29 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -1,17 +0,0 @@ -from smart_building_rating_calculator.calculate_sbr_score import sbr_score -from smart_building_rating_calculator.inputs import ( - BatterySize, - EVChargerPower, - HeatingSource, - HotWaterSource, - SolarInverterSize, -) - -__all__ = [ - "sbr_score", - "BatterySize", - "EVChargerPower", - "HeatingSource", - "HotWaterSource", - "SolarInverterSize", -] diff --git a/src/smart_building_rating_calculator/__init__.py b/src/smart_building_rating_calculator/__init__.py index e69de29..afa193d 100644 --- a/src/smart_building_rating_calculator/__init__.py +++ b/src/smart_building_rating_calculator/__init__.py @@ -0,0 +1,17 @@ +from .calculate_sbr_score import sbr_score +from .inputs import ( + BatterySize, + EVChargerPower, + HeatingSource, + HotWaterSource, + SolarInverterSize, +) + +__all__ = [ + "sbr_score", + "BatterySize", + "EVChargerPower", + "HeatingSource", + "HotWaterSource", + "SolarInverterSize", +] From 13706e6e506c528a32f96a27883e0ae6d412f7d8 Mon Sep 17 00:00:00 2001 From: ianlmgoddard Date: Tue, 30 Jul 2024 11:11:55 +0100 Subject: [PATCH 07/10] update ReadME and dependency management --- Pipfile | 1 + README.md | 78 +++++++------------ setup.py | 6 +- .../__init__.py | 4 +- 4 files changed, 35 insertions(+), 54 deletions(-) diff --git a/Pipfile b/Pipfile index cb8052d..ca383be 100644 --- a/Pipfile +++ b/Pipfile @@ -1,4 +1,5 @@ [packages] +smart_building_rating_calculator = {editable = true, path = "."} pandas = "*" [dev-packages] diff --git a/README.md b/README.md index 4628bee..803548b 100644 --- a/README.md +++ b/README.md @@ -1,49 +1,29 @@ # Smart building rating calculator -The calculation to generate a Smart Building Rating (SBR) and SBR 'archetype' +This package allows users to calculate Smart Building Ratings (SBR) and their associated SBR 'archetype'. In brief, the smart building rating is a metric that measures a building’s potential to flex its energy demand. More information on the concept and methodology used to compute the SBR can be found on our [website](https://www.centrefornetzero.org/impact/smart-building-rating). -## python-template +## Installation -Centre for Net Zero's template for Python projects. +To install this package, run -Tools: - -* [Pipenv](https://github.com/pypa/pipenv) for dependency management -* [Pytest](https://github.com/pytest-dev/pytest/) for testing -* [Mypy](https://mypy.readthedocs.io/en/stable/) for type checking -* [Flake8](https://flake8.pycqa.org/en/latest/) for linting -* [isort](https://github.com/PyCQA/isort) and [black](https://github.com/psf/black) for formatting - -Github Actions workflows: -* `test_and_lint.yaml` runs checks on a Ubuntu Github-hosted runner. - -## Python Setup - -You need to [set up your Python environment](https://docs.google.com/document/d/1Tg0eKalqOp-IJEeH7aShc9fYF5zn95H6jxEk25BLLUE/) first. - -1. Clone this repo. -2. Run `make setup` in your terminal. - -In step 2 this will: - -* Run `pipenv sync --dev` to install dependencies. -* Install your local pre-commit environment which will be used to maintain code standards -* Check the tests work by running `pipenv run pytest` +``` +pip install smart-building-rating-calculator +``` -## Performing SBR calculation +## Performing the SBR calculation -Main SBR calcuation is done with the `sbr_score` (`src/smart_building_rating_calculator/calculate_sbr_score.py`) function which takes in user inputs, and outputs: +The main SBR calculation is done with the [`sbr_score`](src/smart_building_rating_calculator/calculate_sbr_score.py) function which takes in user inputs, and outputs: 1) SBR value (between 0 and 100) 2) SBR rating (A-G) -3) Flex Archetype (see `src/smart_building_rating_calculator/flexer_enums.py`). +3) Flex Archetype (see [`flexer_enums.py`](`src/smart_building_rating_calculator/flexer_enums.py`)). -Inputs must have datatypes as defined in `src/smart_building_rating_calculator/inputs.py` -- Most inputs are `bool` type (True/False) -- Others are StrEnum type e.g., `charger_power` must have a value of `EVChargerPower("3 kW")`, `EVChargerPower("7 kW")`, `EVChargerPower("22 kW")`, or `EVChargerPower("None")` -- Upon calling `sbr_score`, correct input datatypes are automatically checked for. An error is raised if input datatypes are incorrect. +Inputs must have datatypes as defined in [`inputs.py`](src/smart_building_rating_calculator/inputs.py`) +- Most inputs are `bool` type (`True`/`False`) +- Others are `StrEnum` type e.g., `charger_power` must have a value of `EVChargerPower("3 kW")`, `EVChargerPower("7 kW")`, `EVChargerPower("22 kW")`, or `EVChargerPower("None")` +- Upon calling `sbr_score`, correct input datatypes are automatically checked. An error is raised if input datatypes are incorrect. -Example of how to call `sbr_score` in python: +Here's an example of how to compute the SBR for a given set of inputs, using the `sbr_score` function. -```ruby +```python from smart_building_rating_calculator.calculate_sbr_score import sbr_score from smart_building_rating_calculator.inputs import ( BatterySize, @@ -53,18 +33,18 @@ from smart_building_rating_calculator.inputs import ( SolarInverterSize, ) sbr_val, sbr, flex_archetype = sbr_score( - smart_meter=True, - smart_ev_charger=True, - charger_power=EVChargerPower("7 kW"), - smart_v2g_enabled=True, - home_battery=True, - battery_size=BatterySize("8kWh or greater"), - solar_pv=True, - pv_inverter_size=SolarInverterSize("4 kW or less"), - electric_heating=True, - heating_source=HeatingSource("Heat Pump"), - hot_water_source=HotWaterSource("Heat Battery / Electric Hot Water Tank"), - secondary_heating=True, - secondary_hot_water=True, - integrated_control_sys=True) + smart_meter=True, + smart_ev_charger=True, + charger_power=EVChargerPower("7 kW"), + smart_v2g_enabled=True, + home_battery=True, + battery_size=BatterySize("8kWh or greater"), + solar_pv=True, + pv_inverter_size=SolarInverterSize("4 kW or less"), + electric_heating=True, + heating_source=HeatingSource("Heat Pump"), + hot_water_source=HotWaterSource("Heat Battery / Electric Hot Water Tank"), + secondary_heating=True, + secondary_hot_water=True, + integrated_control_sys=True) ``` diff --git a/setup.py b/setup.py index b413ba3..9e3d978 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,7 @@ from setuptools import find_packages, setup +install_requires = ["pandas>=2.2.2"] + setup( name="smart-buildings-rating-calculator", author="Centre for Net Zero", @@ -10,9 +12,7 @@ url="https://github.com/centrefornetzero/smart-building-rating-calculator", package_dir={"": "src"}, packages=find_packages(where="src"), - install_requires=[ - "pandas", - ], + install_requires=install_requires, classifiers=[ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", diff --git a/src/smart_building_rating_calculator/__init__.py b/src/smart_building_rating_calculator/__init__.py index afa193d..f42e651 100644 --- a/src/smart_building_rating_calculator/__init__.py +++ b/src/smart_building_rating_calculator/__init__.py @@ -1,5 +1,5 @@ -from .calculate_sbr_score import sbr_score -from .inputs import ( +from smart_building_rating_calculator.calculate_sbr_score import sbr_score +from smart_building_rating_calculator.inputs import ( BatterySize, EVChargerPower, HeatingSource, From f701484e17df37cf83717616c7ba3588b8e7e596 Mon Sep 17 00:00:00 2001 From: ianlmgoddard Date: Tue, 30 Jul 2024 11:14:42 +0100 Subject: [PATCH 08/10] update pandas dep --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 9e3d978..71a0403 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -install_requires = ["pandas>=2.2.2"] +install_requires = ["pandas>=2.2"] setup( name="smart-buildings-rating-calculator", From 00c9c1acfbed2c8c8faca838e75b9c1f41be4e41 Mon Sep 17 00:00:00 2001 From: ianlmgoddard Date: Tue, 30 Jul 2024 11:58:23 +0100 Subject: [PATCH 09/10] buildings --> building --- .gitignore | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 7f5bbb3..a44a251 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,4 @@ __pycache__/ env build dist -smart_buildings_rating_calculator.egg-info +smart_building_rating_calculator.egg-info diff --git a/setup.py b/setup.py index 71a0403..049efde 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ install_requires = ["pandas>=2.2"] setup( - name="smart-buildings-rating-calculator", + name="smart-building-rating-calculator", author="Centre for Net Zero", author_email="data@centrefornetzero.org", description="The calculation to generate a smart building rating", From ce7fbadfe1092652e5d25e64ce4c4703c364ead9 Mon Sep 17 00:00:00 2001 From: ianlmgoddard Date: Tue, 30 Jul 2024 15:09:04 +0100 Subject: [PATCH 10/10] Release v0.0.0 --- setup.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/setup.py b/setup.py index 049efde..7db6f58 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,12 @@ from setuptools import find_packages, setup +VERSION = "v0.0.0" + install_requires = ["pandas>=2.2"] setup( name="smart-building-rating-calculator", + version=VERSION, author="Centre for Net Zero", author_email="data@centrefornetzero.org", description="The calculation to generate a smart building rating",