Skip to content

Commit

Permalink
Interpret SoC constraints defined as non instantaneous sensors (#1012)
Browse files Browse the repository at this point in the history
* Enhance test_closest_sensor to Support Variable Number of Closest Sensors (n) (#998)

* use scalars instead of scalar having limit constraint

Signed-off-by: Ahmad Wahid <ahmedwahid16101@gmail.com>

* update the test_closest_sensor, to test multiple sensor as params

Signed-off-by: Ahmad Wahid <ahmedwahid16101@gmail.com>

* update the docstring

Signed-off-by: Ahmad Wahid <ahmedwahid16101@gmail.com>

---------

Signed-off-by: Ahmad Wahid <ahmedwahid16101@gmail.com>

* [CLI] add `--offspring` flag to command flexmeasures delete beliefs (#1003)

* add --offspring flag to command flexmeasures delete beliefs

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

* add docstring

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

* fix: include offspring assets in prompt and done messages

Signed-off-by: F.N. Claessen <felix@seita.nl>

* fix: less alarming message in case a time window was passed

Signed-off-by: F.N. Claessen <felix@seita.nl>

* Improve processing time for deleting beliefs via CLI (#1005)

* speed up deleting beliefs via CLI

Signed-off-by: Ahmad Wahid <ahmedwahid16101@gmail.com>

* docs: changelog entry

Signed-off-by: F.N. Claessen <felix@seita.nl>

* fix: typo

Signed-off-by: F.N. Claessen <felix@seita.nl>

---------

Signed-off-by: Ahmad Wahid <ahmedwahid16101@gmail.com>
Signed-off-by: F.N. Claessen <felix@seita.nl>
Co-authored-by: F.N. Claessen <felix@seita.nl>

* fix: CLI message

Signed-off-by: F.N. Claessen <felix@seita.nl>

* docs: changelog entry

Signed-off-by: F.N. Claessen <felix@seita.nl>

---------

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>
Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: Ahmad Wahid <ahmedwahid16101@gmail.com>
Co-authored-by: F.N. Claessen <felix@seita.nl>
Co-authored-by: Ahmad Wahid <59763365+Ahmad-Wahid@users.noreply.github.com>

* docs: expand explanation

Signed-off-by: F.N. Claessen <felix@seita.nl>

* fix: upsample and convert to instantaneous

Signed-off-by: F.N. Claessen <felix@seita.nl>

* fix: better implementation and moved to timely-beliefs

Signed-off-by: F.N. Claessen <felix@seita.nl>

* Introduce FLEXMEASURES_FORCE_HTTPS  (#1008)

* introduce FLEXMEASURES_FORCE_HTTPS so we can control better when we want the app to answer to https. Apply in the internal API to solve a load balancer situation.

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* add warning to consider this setting before upgrading

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* build the URL right in the beginning of internal view functions

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

---------

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* add forgotten changelog entry for #1008

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* Make installable on MacOS (#1000)

* Update db setup text in toy example setup

Signed-off-by: Nikolai Rozanov <nickolay.rozanov@gmail.com>

* Fix commit message Signed-off-by: Nikolai Rozanov <nickolay@seita.nl>

Signed-off-by: Nikolai Rozanov <nickolay.rozanov@gmail.com>

* Fix commit message

Signed-off-by: Nikolai Rozanov <nickolay.rozanov@gmail.com>

* Make runnable on macos + update docs accordingly

Signed-off-by: Nikolai Rozanov <nickolay.rozanov@gmail.com>

* Post review fixes. Signed-off-by: Nikolai Rozanov <nickolay.rozanov@gmail.com>

Signed-off-by: Nikolai Rozanov <nickolay.rozanov@gmail.com>

* Post review fixes

Signed-off-by: Nikolai Rozanov <nickolay.rozanov@gmail.com>

* Add command for highs macOS installation

Signed-off-by: Nikolai Rozanov <nickolay.rozanov@gmail.com>

* Enhance test_closest_sensor to Support Variable Number of Closest Sensors (n) (#998)

* use scalars instead of scalar having limit constraint

Signed-off-by: Ahmad Wahid <ahmedwahid16101@gmail.com>

* update the test_closest_sensor, to test multiple sensor as params

Signed-off-by: Ahmad Wahid <ahmedwahid16101@gmail.com>

* update the docstring

Signed-off-by: Ahmad Wahid <ahmedwahid16101@gmail.com>

---------

Signed-off-by: Ahmad Wahid <ahmedwahid16101@gmail.com>
Signed-off-by: Nikolai Rozanov <nickolay.rozanov@gmail.com>

* [CLI] add `--offspring` flag to command flexmeasures delete beliefs (#1003)

* add --offspring flag to command flexmeasures delete beliefs

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

* add docstring

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

* fix: include offspring assets in prompt and done messages

Signed-off-by: F.N. Claessen <felix@seita.nl>

* fix: less alarming message in case a time window was passed

Signed-off-by: F.N. Claessen <felix@seita.nl>

* Improve processing time for deleting beliefs via CLI (#1005)

* speed up deleting beliefs via CLI

Signed-off-by: Ahmad Wahid <ahmedwahid16101@gmail.com>

* docs: changelog entry

Signed-off-by: F.N. Claessen <felix@seita.nl>

* fix: typo

Signed-off-by: F.N. Claessen <felix@seita.nl>

---------

Signed-off-by: Ahmad Wahid <ahmedwahid16101@gmail.com>
Signed-off-by: F.N. Claessen <felix@seita.nl>
Co-authored-by: F.N. Claessen <felix@seita.nl>

* fix: CLI message

Signed-off-by: F.N. Claessen <felix@seita.nl>

* docs: changelog entry

Signed-off-by: F.N. Claessen <felix@seita.nl>

---------

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>
Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: Ahmad Wahid <ahmedwahid16101@gmail.com>
Co-authored-by: F.N. Claessen <felix@seita.nl>
Co-authored-by: Ahmad Wahid <59763365+Ahmad-Wahid@users.noreply.github.com>
Signed-off-by: Nikolai Rozanov <nickolay.rozanov@gmail.com>

* Introduce FLEXMEASURES_FORCE_HTTPS  (#1008)

* introduce FLEXMEASURES_FORCE_HTTPS so we can control better when we want the app to answer to https. Apply in the internal API to solve a load balancer situation.

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* add warning to consider this setting before upgrading

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* build the URL right in the beginning of internal view functions

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

---------

Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nikolai Rozanov <nickolay.rozanov@gmail.com>

* add forgotten changelog entry for #1008

Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nikolai Rozanov <nickolay.rozanov@gmail.com>

* Changelog message

Signed-off-by: Nikolai Rozanov <nickolay.rozanov@gmail.com>

* Changelog message fix

Signed-off-by: Nikolai Rozanov <nickolay.rozanov@gmail.com>

* [CLI] add `--offspring` flag to command flexmeasures delete beliefs (#1003)

* add --offspring flag to command flexmeasures delete beliefs

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

* add docstring

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

* fix: include offspring assets in prompt and done messages

Signed-off-by: F.N. Claessen <felix@seita.nl>

* fix: less alarming message in case a time window was passed

Signed-off-by: F.N. Claessen <felix@seita.nl>

* Improve processing time for deleting beliefs via CLI (#1005)

* speed up deleting beliefs via CLI

Signed-off-by: Ahmad Wahid <ahmedwahid16101@gmail.com>

* docs: changelog entry

Signed-off-by: F.N. Claessen <felix@seita.nl>

* fix: typo

Signed-off-by: F.N. Claessen <felix@seita.nl>

---------

Signed-off-by: Ahmad Wahid <ahmedwahid16101@gmail.com>
Signed-off-by: F.N. Claessen <felix@seita.nl>
Co-authored-by: F.N. Claessen <felix@seita.nl>

* fix: CLI message

Signed-off-by: F.N. Claessen <felix@seita.nl>

* docs: changelog entry

Signed-off-by: F.N. Claessen <felix@seita.nl>

---------

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>
Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: Ahmad Wahid <ahmedwahid16101@gmail.com>
Co-authored-by: F.N. Claessen <felix@seita.nl>
Co-authored-by: Ahmad Wahid <59763365+Ahmad-Wahid@users.noreply.github.com>
Signed-off-by: Nikolai Rozanov <nickolay.rozanov@gmail.com>

* merge master

Signed-off-by: Nikolai Rozanov <nickolay.rozanov@gmail.com>

---------

Signed-off-by: Nikolai Rozanov <nickolay.rozanov@gmail.com>
Signed-off-by: Ahmad Wahid <ahmedwahid16101@gmail.com>
Signed-off-by: Victor Garcia Reolid <victor@seita.nl>
Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: nrozanov <50166318+nrozanov@users.noreply.github.com>
Co-authored-by: Nikolai <nrozanov@iponweb.net>
Co-authored-by: Ahmad Wahid <59763365+Ahmad-Wahid@users.noreply.github.com>
Co-authored-by: Victor <victor@seita.nl>
Co-authored-by: F.N. Claessen <felix@seita.nl>
Co-authored-by: Nicolas Höning <nicolas@seita.nl>

* [Reporting] Define belief horizon for the PandasReporter output beliefs (#1013)

* add belief horizon field

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

* using correct offset

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

* add `belief_horizon` field to schema

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

* add changelog entry

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

* fix entry

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

---------

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

* [Reporting] skip output event resolution in `PandasReporter` (#1009)

* add flag check_output_resolution and get the minimum resolution of the input data from the min of the input sensors event resolutions instead of the output sensors.

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

* ammend docstring and correct flag logic

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

* add field to schema

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

* add changelog entry

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

* handle default in function argument instead

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

---------

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

* [Reporting] Fix `PandasReporter` input event resolution (#1010)

* Get the minimum resolution of the input data from the min of the input sensors event resolutions instead of the output sensors.

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

* add changelog entry

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

---------

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

* [Scheduling] convert the units of inflexible power sensors MW (#1007)

* convert units to MW

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

* add changelog entry

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

* update docstring.

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

* add inflexible devices with different units

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

---------

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

* Align API endpoint policy w.r.t. trailing slash (#1014)

* use same trailing slash policy as in main API (none)

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* do not add slashes when calling dev API, either

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* align asset API endpoints for chart data with no trailing slash policy, as well

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* align UI Crud endpoints with no trailing slash policy, as well

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* fix test

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* align two more links

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* add changelog entry & warning

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* implement option A1 from review discussion + add comments for later

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* remove changelog warning after option A1 was implemented

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

---------

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* docs: fix typo and remove obsolete comment

Signed-off-by: F.N. Claessen <felix@seita.nl>

* refactor: use xfail

Signed-off-by: F.N. Claessen <felix@seita.nl>

* docs: add docstring param

Signed-off-by: F.N. Claessen <felix@seita.nl>

---------

Signed-off-by: Ahmad Wahid <ahmedwahid16101@gmail.com>
Signed-off-by: Victor Garcia Reolid <victor@seita.nl>
Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nikolai Rozanov <nickolay.rozanov@gmail.com>
Signed-off-by: nrozanov <50166318+nrozanov@users.noreply.github.com>
Co-authored-by: Ahmad Wahid <59763365+Ahmad-Wahid@users.noreply.github.com>
Co-authored-by: Victor <victor@seita.nl>
Co-authored-by: Nicolas Höning <nicolas@seita.nl>
Co-authored-by: nrozanov <50166318+nrozanov@users.noreply.github.com>
Co-authored-by: Nikolai <nrozanov@iponweb.net>
  • Loading branch information
6 people committed Mar 25, 2024
1 parent 8031b8f commit 3bd457a
Show file tree
Hide file tree
Showing 38 changed files with 353 additions and 115 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ dist

raw_data
instance
venv
*venv/
.eggs
.env
.vscode
Expand Down Expand Up @@ -44,3 +44,7 @@ pyproject.toml
poetry.lock
.venv
.vscode/

.DS_Store

.gitconfig.*
6 changes: 6 additions & 0 deletions .vscode/spellright.dict
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,9 @@ cron
CSV
UI
frontend
http
https
balancer
url
HTTPS
Werkzeug
26 changes: 25 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Check Python major and minor version
# For more information, see https://stackoverflow.com/a/22105036
PYV = $(shell python -c "import sys;t='{v[0]}.{v[1]}'.format(v=list(sys.version_info[:2]));sys.stdout.write(t)")
HIGHS_DIR = "../HiGHS"

# Note: use tabs
# actions which are virtual, i.e. not a script
.PHONY: install install-for-dev install-for-test install-deps install-flexmeasures run-local test freeze-deps upgrade-deps update-docs update-docs-pdf show-file-space show-data-model clean-db cli-autocomplete
.PHONY: install install-for-dev install-for-test install-deps install-flexmeasures run-local test freeze-deps upgrade-deps update-docs update-docs-pdf show-file-space show-data-model clean-db cli-autocomplete build-highs-macos install-highs-macos


# ---- Development ---
Expand Down Expand Up @@ -55,6 +56,29 @@ else
rm temp-test.in
endif
make install-flexmeasures
# Locally install HiGS on macOS
if [ "$(shell uname)" = "Darwin" ]; then \
make install-highs-macos; \
fi

$(HIGHS_DIR):
if [ ! -d $(HIGHS_DIR) ]; then \
git clone https://github.com/ERGO-Code/HiGHS.git $(HIGHS_DIR); \
fi
brew install cmake;

build-highs-macos: $(HIGHS_DIR)
cd $(HIGHS_DIR); \
git checkout latest; \
mkdir -p build; \
cd build; \
cmake ..; \
make; \
make install; \
cd ../../flexmeasures;

install-highs-macos: build-highs-macos
pip install $(HIGHS_DIR) ; \

install-deps:
make install-pip-tools
Expand Down
4 changes: 2 additions & 2 deletions ci/update-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ if ! [ -x "$(command -v docker)" ]; then
exit 1
fi

# Check if we can run docker without sudo
if ! docker ps > /dev/null 2>&1; then
# Check if we can run docker without sudo (check is not needed for Macos system)
if ! docker ps > /dev/null 2>&1 && [[ "$(uname)" != "Darwin" ]]; then
echo "Docker is not running without sudo. Please add your user to the docker group and try again."
echo "You may use the following command to do so:"
echo "sudo usermod -aG docker $USER"
Expand Down
20 changes: 18 additions & 2 deletions documentation/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,33 @@ FlexMeasures Changelog
v0.20.0 | April XX, 2024
============================

.. warning:: From this version on, the config setting `FLEXMEASURES_FORCE_HTTPS` decides whether to enforce HTTPS on requests - and it defaults to `False`. Previously, this was governed by `Flask_ENV` or `FLEXMEASURES_ENV` being set to something else than "documentation" or "development". This new way is more clear, but you might be in need of using this setting before upgrading.

New features
-------------

* Add command ``flexmeasures edit transfer-ownership`` to transfer the ownership of an asset and its children from one account to another[see `PR #983 <https://github.com/FlexMeasures/flexmeasures/pull/983>`_]
* Support defining the ``site-power-capacity``, ``site-consumption-capacity`` and ``site-production-capacity`` as a sensor in the API and CLI [see `PR #985 <https://github.com/FlexMeasures/flexmeasures/pull/985>`_]
* Support defining the ``soc-minima``, ``soc-maxima`` and ``soc-targets`` as sensors in the API [see `PR #996 <https://github.com/FlexMeasures/flexmeasures/pull/996>`_]
* Support defining the ``soc-minima``, ``soc-maxima`` and ``soc-targets`` as sensors in the API [see `PR #996 <https://github.com/FlexMeasures/flexmeasures/pull/996>`_]
* Support defining inflexible power sensors with arbitrary power and energy units [see `PR #1007 <https://github.com/FlexMeasures/flexmeasures/pull/1007>`_]
* Support saving beliefs with a ``belief_horizon`` in the ``PandasReporter``[see `PR #1013 <https://github.com/FlexMeasures/flexmeasures/pull/1013>`_]
* Skip the check of the output event resolution in any ``Reporter`` with the field ``check_output_resolution`` [see `PR #1009 <https://github.com/FlexMeasures/flexmeasures/pull/1009>`_]

Bugfixes
-----------

* Use minimum event resolution of the input (instead of the output) sensors for the belief search parameters [see `PR #1010 <https://github.com/FlexMeasures/flexmeasures/pull/1010>`_]



Infrastructure / Support
----------------------


* Improve processing time for deleting beliefs via CLI [see `PR #1005 <https://github.com/FlexMeasures/flexmeasures/pull/1005>`_]
* Support deleting beliefs via CLI for all offspring assets at once [see `PR #1003 <https://github.com/FlexMeasures/flexmeasures/pull/1003>`_]
* Add setting ``FLEXMEASURES_FORCE_HTTPS`` to explicitly toggle if HTTPS should be used for all requests [see `PR #1008 <https://github.com/FlexMeasures/flexmeasures/pull/1008>`_]
* Make flexmeasures installable locally on macOS [see `PR #1000 <https://github.com/FlexMeasures/flexmeasures/pull/1000>`_]
* Align API endpoint policy w.r.t. trailing slash [see `PR #1014 <https://github.com/FlexMeasures/flexmeasures/pull/1014>`_]


v0.19.2 | March 1, 2024
Expand Down
8 changes: 8 additions & 0 deletions documentation/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,14 @@ Allows users to make authenticated requests. If true, injects the Access-Control
Default: ``True``


FLEXMEASURES_FORCE_HTTPS
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Set to ``True`` if all requests should be forced to be HTTPS.

Default: ``False``


FLEXMEASURES_ENFORCE_SECURE_CONTENT_POLICY
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
2 changes: 1 addition & 1 deletion documentation/dev/dependency-management.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Now ― you probably have only one Python version installed. Let's say you add a

.. code-block:: bash
$ cd ci; ./update-packages.sh
$ cd ci; ./update-packages.sh; cd ../
This script will use docker to do these upgrades per Python version.

Expand Down
17 changes: 14 additions & 3 deletions documentation/dev/setup-and-guidelines.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,23 @@ Go into the ``flexmeasures`` folder and install all dependencies including the o
$ pip install highspy
On MacOS it will be installed locally by `make install-for-test` and no actions are required on your part

Alternatively, the CBC solver can be installed with:
Besides highs, the CBC solver is required for tests as well:

.. code-block:: bash
.. tabs::

.. tab:: Linux

.. code-block:: bash
$ apt-get install coinor-cbc
.. tab:: MacOS

.. code-block:: bash
$ apt-get install coinor-cbc
$ brew install cbc
Configuration
Expand Down
2 changes: 1 addition & 1 deletion documentation/features/scheduling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ With the flexibility context, we aim to describe the system in which the flexibl
- Description
* - ``inflexible-device-sensors``
- ``[3,4]``
- Power sensors that are relevant, but not flexible, such as a sensor recording rooftop solar power connected behind the main meter, whose production falls under the same contract as the flexible device(s) being scheduled. * Note:* For now, the inflexible-device-sensors need to have MW units.
- Power sensors that are relevant, but not flexible, such as a sensor recording rooftop solar power connected behind the main meter, whose production falls under the same contract as the flexible device(s) being scheduled.
* - ``consumption-price-sensor``
- ``5``
- The sensor that defines the price of consuming energy. This sensor can be recording market prices, but also CO₂ - whatever fits your optimization problem.
Expand Down
40 changes: 35 additions & 5 deletions documentation/host/data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,23 @@ On Windows:
* ``conda install psycopg2``


On Macos:

.. code-block:: bash
$ brew update
$ brew doctor
$ # Need to specify postgres version, in this example we use 13
$ brew install postgresql@13
$ brew link postgresql@13 --force
$ # Start postgres (you can change /usr/local/var/postgres to any directory you like)
$ pg_ctl -D /usr/local/var/postgres -l logfile start
Using Docker Compose:


Alternatively, you can use Docker Compose to run a postgres database. Use can use the following ``docker-compose.yml`` as a starting point:
Alternatively, you can use Docker Compose to run a postgres database. You can use the following ``docker-compose.yml`` as a starting point:


.. code-block:: yaml
Expand Down Expand Up @@ -96,9 +109,19 @@ Find the ``timezone`` setting and set it to 'UTC'.

Then restart the postgres server.

.. code-block:: bash
.. tabs::

.. tab:: Linux

$ sudo service postgresql restart
.. code-block:: bash
$ sudo service postgresql restart
.. tab:: Macos

.. code-block:: bash
$ pg_ctl -D /usr/local/var/postgres -l logfile restart
.. note:: If you are using Docker to run postgres, the ``timezone`` setting is already set to ``UTC`` by default.

Expand All @@ -120,14 +143,16 @@ Proceed to create a database as the postgres superuser (using your postgres user
$ createuser --pwprompt -U postgres flexmeasures_test # enter "flexmeasures_test" as password
$ exit
.. note:: In case you encounter the following "FAILS: sudo: unknown user postgres" you need to create "postgres" OS user with sudo rights first - better done via System preferences -> Users & Groups.


Or, from within Postgres console:

.. code-block:: sql
CREATE USER flexmeasures WITH UNENCRYPTED PASSWORD 'this-is-your-secret-choice';
CREATE USER flexmeasures WITH PASSWORD 'this-is-your-secret-choice';
CREATE DATABASE flexmeasures WITH OWNER = flexmeasures;
CREATE USER flexmeasures_test WITH UNENCRYPTED PASSWORD 'flexmeasures_test';
CREATE USER flexmeasures_test WITH PASSWORD 'flexmeasures_test';
CREATE DATABASE flexmeasures_test WITH OWNER = flexmeasures_test;
Expand Down Expand Up @@ -158,6 +183,8 @@ Add the following extensions while logged in as the postgres superuser:
CREATE EXTENSION cube;
CREATE EXTENSION earthdistance;
.. note:: Lines from above should be run seperately


If you have it, connect to the ``flexmeasures_test`` database and repeat creating these extensions there. Then ``exit``.

Expand Down Expand Up @@ -230,6 +257,7 @@ You can create users with the ``add user`` command. Check it out:

.. code-block:: bash
$ flexmeasures add account --help
$ flexmeasures add user --help
Expand Down Expand Up @@ -281,6 +309,8 @@ You can visualise the data model like this:
This will generate a picture based on the model code.
You can also generate picture based on the actual database, see inside the Makefile.

.. note:: If you encounter "error: externally-managed-environment" when running `make test` and you do it in venv, try `pip cache purge` or use pipx.

Maintenance
----------------

Expand Down
2 changes: 1 addition & 1 deletion documentation/tut/toy-example-setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Install Flexmeasures and the database
$ docker run --rm --name flexmeasures-tutorial-db -e POSTGRES_PASSWORD=fm-db-passwd -e POSTGRES_DB=flexmeasures-db -d --network=flexmeasures_network postgres:latest
$ docker run --rm --name flexmeasures-tutorial-fm --env SQLALCHEMY_DATABASE_URI=postgresql://postgres:fm-db-passwd@flexmeasures-tutorial-db:5432/flexmeasures-db --env SECRET_KEY=notsecret --env FLEXMEASURES_ENV=development --env LOGGING_LEVEL=INFO -d --network=flexmeasures_network -p 5000:5000 lfenergy/flexmeasures
To upgrade the FlexMeasures database, execute:
To establish the FlexMeasures database structure, execute:

.. code-block:: bash
Expand Down
15 changes: 9 additions & 6 deletions flexmeasures/api/dev/sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ class SensorAPI(FlaskView):
"""

route_base = "/sensor"
trailing_slash = False
# Note: when promoting these endpoints to the main API, we aim to be strict with trailing slashes, see #1014

@route("/<id>/chart/")
@route("/<id>/chart", strict_slashes=False)
@use_kwargs(
{"sensor": SensorIdField(data_key="id")},
location="path",
Expand Down Expand Up @@ -64,7 +66,7 @@ def get_chart(self, id: int, sensor: Sensor, **kwargs):
- "event_ends_before" (see the `timely-beliefs documentation <https://github.com/SeitaBV/timely-beliefs/blob/main/timely_beliefs/docs/timing.md/#events-and-sensors>`_)
- "beliefs_after" (see the `timely-beliefs documentation <https://github.com/SeitaBV/timely-beliefs/blob/main/timely_beliefs/docs/timing.md/#events-and-sensors>`_)
- "beliefs_before" (see the `timely-beliefs documentation <https://github.com/SeitaBV/timely-beliefs/blob/main/timely_beliefs/docs/timing.md/#events-and-sensors>`_)
- "include_data" (if true, chart specs include the data; if false, use the `GET /api/dev/sensor/(id)/chart_data/ <../api/dev.html#get--api-dev-sensor-(id)-chart_data->`_ endpoint to fetch data)
- "include_data" (if true, chart specs include the data; if false, use the `GET /api/dev/sensor/(id)/chart_data <../api/dev.html#get--api-dev-sensor-(id)-chart_data->`_ endpoint to fetch data)
- "chart_type" (currently 'bar_chart' and 'daily_heatmap' are supported types)
- "width" (an integer number of pixels; without it, the chart will be scaled to the full width of the container (hint: use ``<div style="width: 100%;">`` to set a div width to 100%)
- "height" (an integer number of pixels; without it, FlexMeasures sets a default, currently 300)
Expand All @@ -73,7 +75,7 @@ def get_chart(self, id: int, sensor: Sensor, **kwargs):
set_session_variables("event_starts_after", "event_ends_before", "chart_type")
return json.dumps(sensor.chart(**kwargs))

@route("/<id>/chart_data/")
@route("/<id>/chart_data", strict_slashes=False)
@use_kwargs(
{"sensor": SensorIdField(data_key="id")},
location="path",
Expand Down Expand Up @@ -108,7 +110,7 @@ def get_chart_data(self, id: int, sensor: Sensor, **kwargs):
"""
return sensor.search_beliefs(as_json=True, **kwargs)

@route("/<id>/chart_annotations/")
@route("/<id>/chart_annotations", strict_slashes=False)
@use_kwargs(
{"sensor": SensorIdField(data_key="id")},
location="path",
Expand Down Expand Up @@ -146,7 +148,7 @@ def get_chart_annotations(self, id: int, sensor: Sensor, **kwargs):
df["source"] = df["source"].astype(str)
return df.to_json(orient="records")

@route("/<id>/")
@route("/<id>", strict_slashes=False)
@use_kwargs(
{"sensor": SensorIdField(data_key="id")},
location="path",
Expand All @@ -168,8 +170,9 @@ class AssetAPI(FlaskView):
"""

route_base = "/asset"
trailing_slash = False

@route("/<id>/")
@route("/<id>", strict_slashes=False)
@use_kwargs(
{"asset": AssetIdField(data_key="id")},
location="path",
Expand Down
6 changes: 4 additions & 2 deletions flexmeasures/api/v3_0/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def delete(self, id: int, asset: GenericAsset):
current_app.logger.info("Deleted asset '%s'." % asset_name)
return {}, 204

@route("/<id>/chart/")
@route("/<id>/chart", strict_slashes=False) # strict on next version? see #1014
@use_kwargs(
{"asset": AssetIdField(data_key="id")},
location="path",
Expand Down Expand Up @@ -291,7 +291,9 @@ def get_chart(self, id: int, asset: GenericAsset, **kwargs):
set_session_variables("event_starts_after", "event_ends_before")
return json.dumps(asset.chart(**kwargs))

@route("/<id>/chart_data/")
@route(
"/<id>/chart_data", strict_slashes=False
) # strict on next version? see #1014
@use_kwargs(
{"asset": AssetIdField(data_key="id")},
location="path",
Expand Down
2 changes: 1 addition & 1 deletion flexmeasures/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def create( # noqa C901
set_secret_key(app)
if app.config.get("SECURITY_PASSWORD_SALT", None) is None:
app.config["SECURITY_PASSWORD_SALT"] = app.config["SECRET_KEY"]
if app.config.get("FLEXMEASURES_ENV") not in ("documentation", "development"):
if app.config.get("FLEXMEASURES_FORCE_HTTPS", False):
SSLify(app)

# Prepare profiling, if needed
Expand Down
Loading

0 comments on commit 3bd457a

Please sign in to comment.