From 00a9fb028958a991784fc46ab60adac0943ad1db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20H=C3=B6ning?= Date: Wed, 2 Mar 2022 23:15:15 +0100 Subject: [PATCH 01/17] first version of the toy scheduling tutorial MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolas Höning --- documentation/index.rst | 52 +++- .../tut/toy-example-from-scratch.rst | 258 ++++++++++++++++++ flexmeasures/cli/data_add.py | 1 + 3 files changed, 300 insertions(+), 11 deletions(-) create mode 100644 documentation/tut/toy-example-from-scratch.rst diff --git a/documentation/index.rst b/documentation/index.rst index b3af57249..671dc3ad6 100644 --- a/documentation/index.rst +++ b/documentation/index.rst @@ -1,23 +1,53 @@ Welcome to the FlexMeasures documentation! =================================================================== -In a world with renewable energy, flexibility is crucial and valuable. +In a world with renewable energy, flexibility is crucial and valuable, e.g. for demand response. Planning ahead allows flexible assets to serve the whole system with their flexibility, e.g. by shifting or curtailing energy use. -This can also be profitable for their owners. -The *FlexMeasures Platform* is the intelligent backend to support real-time energy flexibility apps, rapidly and scalable. +> The *FlexMeasures Platform* is the intelligent backend to support real-time energy flexibility apps, rapidly and scalable. -- Developing energy flexibility services (e.g. to enable demand response) is crucial, but expensive. -- FlexMeasures reduces development costs with real-time data integrations, uncertainty models and API/UI support. +Developing energy flexibility services is expensive work. FlexMeasures reduces software development costs with: -As possible users, we see energy service companies (ESCOs) who want to build real-time apps & services around energy flexibility for their customers, or medium/large industrials who are looking for support in their internal digital tooling. However, even small companies and hobby projects might find FlexMeasures useful! +- Real-time data intelligence & integration +- Uncertainty models +- API/UI support -Let's take a closer look at the three core values: +A quick glance at usage +------------------------ + +A tiny, but full example: Let's install FlexMeasures from scratch, load hourly prices and optimize a 12h-schedule for a battery that is half full at the beginning. + +.. code-block:: bash + + pip install flexmeasures + docker pull postgres; docker run --name pg-docker -e POSTGRES_PASSWORD=docker -e POSTGRES_DB=flexmeasures-db -d -p 5433:5432 postgres:latest + export SQLALCHEMY_DATABASE_URI="postgresql://postgres:docker@127.0.0.1:5433/flexmeasures-db" && export SECRET_KEY=notsecret + flexmeasures db upgrade # create tables + flexmeasures add toy-account --kind battery # setup account & a user, a battery (Id 2) and a market (Id 3) + flexmeasures add beliefs --sensor-id 3 --source toy-user prices-tomorrow.csv # load prices, also possible per API + flexmeasures add schedule --sensor-id 2 --factor-id 3 \ + --from $(date '+%Y-%m-%d')T06:00+02:00 --duration PT12H \ + --soc-at-start 50 --roundtrip-efficiency .9 # this is also possible per API + flexmeasures show beliefs --sensor-id 2 --from $(date '+%Y-%m-%d')T06:00:00+02:00 --duration PT12H # also visible per UI, of course + +We discuss this in more depth at :ref:`tut_toy_schedule`. + + +Use cases +----------- + +As possible users, we see energy service companies (ESCOs) who want to build real-time apps & services around energy flexibility for their customers, or medium/large industrials who are looking for support in their internal digital tooling. + +However, even small companies and hobby projects might find FlexMeasures useful! + + +The three core values: +----------------------- Real-time data intelligence & integration ------------------------------------------ +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Energy flexibility services need to interact multiple times per day or hour. We equipped FlexMeasures with: @@ -27,7 +57,7 @@ Energy flexibility services need to interact multiple times per day or hour. We Uncertainty models ------------------------ +^^^^^^^^^^^^^^^^^^^^ Dealing with uncertain forecasts and outcomes is crucial. @@ -35,8 +65,8 @@ FlexMeasures is therefore built on the `timely-beliefs framework `_ and `docker `_ + +We install the FlexMeasures platform, use Docker to run a postgres database and tell FlexMeasures to create all tables. + +.. code-block:: bash + + $ pip install flexmeasures + $ docker pull postgres; docker run --name pg-docker -e POSTGRES_PASSWORD=docker -e POSTGRES_DB=flexmeasures-db -d -p 5433:5432 postgres:latest + $ export SQLALCHEMY_DATABASE_URI="postgresql://postgres:docker@127.0.0.1:5433/flexmeasures-db" && export SECRET_KEY=notsecret + $ flexmeasures db upgrade + + +Add some structural data +--------------------------------------- + +The data we need for our example is both structural (e.g. a company account, a user, an asset) and numeric (we want market prices to optimize against). + +Let's create the structural data first. + +FlexMeasures offers a command to create a toy account with a battery: + +.. code-block:: bash + + $ flexmeasures add toy-account --kind battery + + Toy account Toy Account with user toy-user@flexmeasures.io created successfully. You might want to run `flexmeasures show account --id 1` + The sensor for battery charging is . + The sensor for Day ahead prices is . + +And with that, we're done with the structural data for this tutorial! + +We can inspect what we created: + +.. code-block:: bash + + $ flexmeasures show account --id 1 + + ============================= + Account Toy Account (ID:1): + ============================= + + Account has no roles. + + All users: + + Id Name Email Last Login Roles + ---- -------- ------------------------ ------------ ------------- + 1 toy-user toy-user@flexmeasures.io account-admin + + All assets: + + Id Name Type Location + ---- ------------ -------- ----------------- + 3 toy-battery battery (52.374, 4.88969) + 2 toy-building building (52.374, 4.88969) + 1 toy-solar solar (52.374, 4.88969) + + $ flexmeasures show asset --id + + =========================== + Asset toy-battery (ID:3): + =========================== + + Type Location Attributes + ------- ----------------- --------------------- + battery (52.374, 4.88969) capacity_in_mw:0.005 + min_soc_in_mwh:0.0005 + max_soc_in_mwh:0.0045 + + All sensors in asset: + + Id Name Unit Resolution Timezone Attributes + ---- -------- ------ ------------ ---------------- ------------ + 2 charging kW 15 minutes Europe/Amsterdam + + +.. note:: Obviously, you can use the `flexmeasures` command to create your own, custom account and assets. See :ref:`cli`. And to create, edit or read asset data via the API, see :ref:`v2_0`. + +We can also look at the battery asset in the UI of FlexMeasures (start FlexMeasures with ``flexmeasures run``): + +.. image:: https://github.com/FlexMeasures/screenshots/raw/main/tut/toy-schedule/asset-view.png + :align: center + + +Add some price data +--------------------------------------- + +Now to add price data. First, we'll create the csv file with prices (EUR/MWh, see the setup for sensor 3 above) for tomorrow. + +.. code-block:: bash + + $ TOMORROW=$(date --date="next day" '+%Y-%m-%d') + $ echo "Hour,Price + ${TOMORROW}T00:00:00,10 + ${TOMORROW}T01:00:00,11 + ${TOMORROW}T02:00:00,12 + ${TOMORROW}T03:00:00,15 + ${TOMORROW}T04:00:00,18 + ${TOMORROW}T05:00:00,17 + ${TOMORROW}T06:00:00,10.5 + ${TOMORROW}T07:00:00,9 + ${TOMORROW}T08:00:00,9.5 + ${TOMORROW}T09:00:00,9 + ${TOMORROW}T10:00:00,8.5 + ${TOMORROW}T11:00:00,10 + ${TOMORROW}T12:00:00,8 + ${TOMORROW}T13:00:00,5 + ${TOMORROW}T14:00:00,4 + ${TOMORROW}T15:00:00,4 + ${TOMORROW}T16:00:00,5.5 + ${TOMORROW}T17:00:00,8 + ${TOMORROW}T18:00:00,12 + ${TOMORROW}T19:00:00,13 + ${TOMORROW}T20:00:00,14 + ${TOMORROW}T21:00:00,12.5 + ${TOMORROW}T22:00:00,10 + ${TOMORROW}T23:00:00,7" > prices-tomorrow.csv + +Note that time series data (which we call "beliefs" in FlexMeasures) can also be sent to FlexMeasures via API or imported from open data hubs like `ENTSO-E `_ or `OpenWeatherMap `_. However, in this tutorial we'll show how you can read data in from a CSV file. Sometimes that's just what you need :) + +.. code-block:: bash + + $ flexmeasures add beliefs --sensor-id 3 --source toy-user prices-tomorrow.csv + Successfully created beliefs + +In FlexMeasures, all beliefs have a data source. Here, we use the username of the user we created earlier. We could also pass a user ID, or the name of a new data source we want to use for CLI scripts. + +.. note:: Attention: We created and imported prices where the times have no time zone component! That happens a lot. FlexMeasures will then interpret them as UTC time. So if you are in Amsterdam time, the the start time for the first price, when expressed in your time zone, is actually `2022-03-03 01:00:00+01:00`. + +Let's look at the price data we just loaded: + +.. code-block:: bash + + $ flexmeasures show beliefs --sensor-id 3 --from ${TOMORROW}T01:00:00+01:00 --duration PT24H + Beliefs for Sensor 'Day ahead prices' (Id 3). + Data spans a day and starts at 2022-03-03 01:00:00+01:00. + The time resolution (x-axis) is an hour. + ┌────────────────────────────────────────────────────────────┐ + │ ▗▀▚▖ │ 18EUR/MWh + │ ▞ ▝▌ │ + │ ▐ ▚ │ + │ ▗▘ ▐ │ + │ ▌ ▌ ▖ │ + │ ▞ ▚ ▗▄▀▝▄ │ + │ ▗▘ ▐ ▗▞▀ ▚ │ 13EUR/MWh + │ ▗▄▘ ▌ ▐▘ ▚ │ + │ ▗▞▘ ▚ ▌ ▚ │ + │▞▘ ▝▄ ▗ ▐ ▝▖ │ + │ ▚▄▄▀▚▄▄ ▞▘▚ ▌ ▝▖ │ + │ ▀▀▛ ▚ ▐ ▚ │ + │ ▚ ▗▘ ▚│ 8EUR/MWh + │ ▌ ▗▘ ▝│ + │ ▝▖ ▞ │ + │ ▐▖ ▗▀ │ + │ ▝▚▄▄▄▄▘ │ + └────────────────────────────────────────────────────────────┘ + 5 10 15 20 + ██ Day ahead prices + + + +Again, we can also view these sensor data in the FlexMeasures UI: + +.. image:: https://github.com/FlexMeasures/screenshots/raw/main/tut/toy-schedule/sensor-data-prices.png + :align: center + +.. note:: Technically, these prices for tomorrow are forecasts. You can use FlexMeasures to compute forecasts yourself. See :ref:`tut_forecasting_scheduling`. + + +Make a schedule +--------------------------------------- + +Finally, we can create the schedule, which is the main benefit of FlexMeasures (smart real-time control). + +We'll ask FlexMeasures for a schedule for our charging sensor (Id 2). We also need to specify what to optimise against. Here we pass the Id of our market price sensor (3). +To keep it short, we'll only ask for a 12-hour window starting at 7am. Finally, the scheduler should know what the state of charge of the battery is when the schedule starts (50%) and what its roundtrip efficiency is (0.9). + +.. code-block:: bash + + $ flexmeasures add schedule --sensor-id 2 --factor-id 3 \ + --from ${TOMORROW}T07:00+01:00 --duration PT12H \ + --soc-at-start 50 --roundtrip-efficiency .9 + New schedule is stored. + +Great. Let's see what we made: + +.. code-block:: bash + + $ flexmeasures show beliefs --sensor-id 2 --from ${TOMORROW}T07:00:00+01:00 --duration PT12H + Beliefs for Sensor 'charging' (Id 2). + Data spans 12 hours and starts at 2022-03-03 07:00:00+01:00. + The time resolution (x-axis) is 15 minutes. + ┌────────────────────────────────────────────────────────────┐ + │ ▐ ▐▀▀▌ ▛▀▀│ + │ ▞▌ ▞ ▐ ▌ │ + │ ▌▌ ▌ ▐ ▐ │ + │ ▗▘▌ ▌ ▐ ▐ │ + │ ▐ ▐ ▗▘ ▝▖ ▐ │ + │ ▞ ▐ ▐ ▌ ▌ │ + │ ▗▘ ▐ ▐ ▌ ▌ │ + │ ▐ ▝▖ ▌ ▚ ▞ │ + │▀▘───▀▀▀▀▀▀▀▀▀▀▀▀▀▀▌────▐─────▝▀▀▀▀▀▀▀▀▜─────▐▀▀▀▀▀▀▀▀▀─────│ + │ ▌ ▞ ▐ ▗▘ │ + │ ▚ ▌ ▐ ▐ │ + │ ▐ ▗▘ ▝▖ ▌ │ + │ ▐ ▐ ▌ ▌ │ + │ ▐ ▐ ▌ ▗▘ │ + │ ▌ ▞ ▌ ▐ │ + │ ▌ ▌ ▐ ▐ │ + │ ▙▄▄▌ ▐▄▄▞ │ + └────────────────────────────────────────────────────────────┘ + 10 20 30 40 + ██ charging + + +Here, negative values denote output from the grid, so that's when the battery gets charged. + +We can also look at the charging schedule in the FlexMeasures UI (reachable via the asset page for the battery): + +.. image:: https://github.com/FlexMeasures/screenshots/raw/main/tut/toy-schedule/sensor-data-charging.png + :align: center + +Recall that we only asked for a 12 hour schedule here. We started our schedule *after* the high price peak (at 5am) and it also had to end *before* the second price peak fully realised (at 9pm). Our scheduler didn't have many opportunities to optimize, but it found some. For instance, it does buy at the lowest price (around 3pm) and sells it off when prices start rising again (around 6pm). + + +.. note:: The ``flexmeasures add schedule`` command also accepts state of charge targets, so the schedule can be more sophisticated. But that is not the point of this tutorial. \ No newline at end of file diff --git a/flexmeasures/cli/data_add.py b/flexmeasures/cli/data_add.py index 3054ad13a..70609c4a6 100755 --- a/flexmeasures/cli/data_add.py +++ b/flexmeasures/cli/data_add.py @@ -829,6 +829,7 @@ def add_toy_account(kind: str, name: str): click.echo( f"Toy account {name} with user {user.email} created successfully. You might want to run `flexmeasures show account --id {user.account.id}`" ) + click.echo(f"The sensor for battery charging is {charging_sensor}.") click.echo(f"The sensor for Day ahead prices is {day_ahead_sensor}.") From d0c15bc5ce53fdda8da1d66c3cb123375a5e089d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20H=C3=B6ning?= Date: Thu, 3 Mar 2022 15:03:51 +0100 Subject: [PATCH 02/17] allow logging settings to be set via env vars, makes for better tutorials. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolas Höning --- flexmeasures/utils/config_utils.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/flexmeasures/utils/config_utils.py b/flexmeasures/utils/config_utils.py index a17526bea..01f261239 100644 --- a/flexmeasures/utils/config_utils.py +++ b/flexmeasures/utils/config_utils.py @@ -83,7 +83,7 @@ def read_config(app: Flask, custom_path_to_config: Optional[str]): used_path_to_config = read_custom_config( app, custom_path_to_config, path_to_config_home, path_to_config_instance ) - read_required_env_vars(app) + read_env_vars(app) # Check for missing values. # Documentation runs fine without them. @@ -142,13 +142,18 @@ def read_custom_config( app.logger.warning( f"File {path_to_config} could not be found! (work dir is {os.getcwd()})" ) - app.logger.warning(f"File exists: {os.path.exists(path_to_config)}") return path_to_config -def read_required_env_vars(app: Flask): - """All required variables and the plugins can be set as env var""" - for var in required: +def read_env_vars(app: Flask): + """ + Read in what we support as environment settings. + At the moment, these are: + - All required variables + - Logging settings + - plugins (handled in plugin utils) + """ + for var in required + ["LOGGING_LEVEL", "DEBUG"]: app.config[var] = os.getenv(var, app.config.get(var, None)) From 8b6bd3ddea44634ea5bd15410afa0a9a0a72184c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20H=C3=B6ning?= Date: Thu, 3 Mar 2022 15:09:08 +0100 Subject: [PATCH 03/17] make the battery bigger (in MW), also use the upcoming roundtrip-efficiency encoding in percent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolas Höning --- documentation/index.rst | 12 +++--- .../tut/toy-example-from-scratch.rst | 40 ++++++++++--------- flexmeasures/cli/data_add.py | 4 +- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/documentation/index.rst b/documentation/index.rst index 671dc3ad6..37de72941 100644 --- a/documentation/index.rst +++ b/documentation/index.rst @@ -1,12 +1,12 @@ Welcome to the FlexMeasures documentation! =================================================================== +*FlexMeasures is the intelligent backend to support real-time energy flexibility apps, rapidly and scalable.* + In a world with renewable energy, flexibility is crucial and valuable, e.g. for demand response. Planning ahead allows flexible assets to serve the whole system with their flexibility, e.g. by shifting or curtailing energy use. -> The *FlexMeasures Platform* is the intelligent backend to support real-time energy flexibility apps, rapidly and scalable. - Developing energy flexibility services is expensive work. FlexMeasures reduces software development costs with: - Real-time data intelligence & integration @@ -17,7 +17,7 @@ Developing energy flexibility services is expensive work. FlexMeasures reduces s A quick glance at usage ------------------------ -A tiny, but full example: Let's install FlexMeasures from scratch, load hourly prices and optimize a 12h-schedule for a battery that is half full at the beginning. +A tiny, but complete example: Let's install FlexMeasures from scratch. Then, using only the terminal, load hourly prices and optimize a 12h-schedule for a battery that is half full at the beginning. .. code-block:: bash @@ -28,9 +28,9 @@ A tiny, but full example: Let's install FlexMeasures from scratch, load hourly p flexmeasures add toy-account --kind battery # setup account & a user, a battery (Id 2) and a market (Id 3) flexmeasures add beliefs --sensor-id 3 --source toy-user prices-tomorrow.csv # load prices, also possible per API flexmeasures add schedule --sensor-id 2 --factor-id 3 \ - --from $(date '+%Y-%m-%d')T06:00+02:00 --duration PT12H \ - --soc-at-start 50 --roundtrip-efficiency .9 # this is also possible per API - flexmeasures show beliefs --sensor-id 2 --from $(date '+%Y-%m-%d')T06:00:00+02:00 --duration PT12H # also visible per UI, of course + --from ${TOMORROW}T07:00+01:00 --duration PT12H \ + --soc-at-start 50 --roundtrip-efficiency 90 # this is also possible per API + flexmeasures show beliefs --sensor-id 2 --from ${TOMORROW}T07:00:00+01:00 --duration PT12H # also visible per UI, of course We discuss this in more depth at :ref:`tut_toy_schedule`. diff --git a/documentation/tut/toy-example-from-scratch.rst b/documentation/tut/toy-example-from-scratch.rst index 4d422a44d..8038ee2ef 100644 --- a/documentation/tut/toy-example-from-scratch.rst +++ b/documentation/tut/toy-example-from-scratch.rst @@ -1,6 +1,6 @@ .. _tut_toy_schedule: -Toy example: Schedule a battery, from scratch +Toy example: Scheduling a battery, from scratch =============================================== Let's walk through an example from scratch! We'll @@ -21,7 +21,7 @@ Below are the ``flexmeasures`` CLI commands we'll run, and which we'll explain s # make the schedule $ flexmeasures add schedule --sensor-id 2 --factor-id 3 \ --from $(date '+%Y-%m-%d')T06:00+02:00 --duration PT12H \ - --soc-at-start 50 --roundtrip-efficiency .9 + --soc-at-start 50 --roundtrip-efficiency 90 Okay, let's get started! @@ -38,7 +38,7 @@ We install the FlexMeasures platform, use Docker to run a postgres database and $ pip install flexmeasures $ docker pull postgres; docker run --name pg-docker -e POSTGRES_PASSWORD=docker -e POSTGRES_DB=flexmeasures-db -d -p 5433:5432 postgres:latest - $ export SQLALCHEMY_DATABASE_URI="postgresql://postgres:docker@127.0.0.1:5433/flexmeasures-db" && export SECRET_KEY=notsecret + $ export SQLALCHEMY_DATABASE_URI="postgresql://postgres:docker@127.0.0.1:5433/flexmeasures-db" SECRET_KEY=notsecret LOGGING_LEVEL="WARNING" DEBUG=0 $ flexmeasures db upgrade @@ -56,12 +56,12 @@ FlexMeasures offers a command to create a toy account with a battery: $ flexmeasures add toy-account --kind battery Toy account Toy Account with user toy-user@flexmeasures.io created successfully. You might want to run `flexmeasures show account --id 1` - The sensor for battery charging is . + The sensor for battery charging is . The sensor for Day ahead prices is . And with that, we're done with the structural data for this tutorial! -We can inspect what we created: +If you want, you can inspect what you created: .. code-block:: bash @@ -95,20 +95,22 @@ We can inspect what we created: Type Location Attributes ------- ----------------- --------------------- - battery (52.374, 4.88969) capacity_in_mw:0.005 - min_soc_in_mwh:0.0005 - max_soc_in_mwh:0.0045 + battery (52.374, 4.88969) capacity_in_mw:0.5 + min_soc_in_mwh:0.05 + max_soc_in_mwh:0.45 All sensors in asset: Id Name Unit Resolution Timezone Attributes ---- -------- ------ ------------ ---------------- ------------ - 2 charging kW 15 minutes Europe/Amsterdam + 2 charging MW 15 minutes Europe/Amsterdam +Yes, that is quite a large battery :) + .. note:: Obviously, you can use the `flexmeasures` command to create your own, custom account and assets. See :ref:`cli`. And to create, edit or read asset data via the API, see :ref:`v2_0`. -We can also look at the battery asset in the UI of FlexMeasures (start FlexMeasures with ``flexmeasures run``): +We can also look at the battery asset in the UI of FlexMeasures (start FlexMeasures with ``flexmeasures run``, username is "toy-user@flexmeasures.io", password is "toy-password"): .. image:: https://github.com/FlexMeasures/screenshots/raw/main/tut/toy-schedule/asset-view.png :align: center @@ -196,7 +198,7 @@ Again, we can also view these sensor data in the FlexMeasures UI: .. image:: https://github.com/FlexMeasures/screenshots/raw/main/tut/toy-schedule/sensor-data-prices.png :align: center -.. note:: Technically, these prices for tomorrow are forecasts. You can use FlexMeasures to compute forecasts yourself. See :ref:`tut_forecasting_scheduling`. +.. note:: Technically, these prices for tomorrow are forecasts. You can also use FlexMeasures to compute forecasts yourself. See :ref:`tut_forecasting_scheduling`. Make a schedule @@ -211,7 +213,7 @@ To keep it short, we'll only ask for a 12-hour window starting at 7am. Finally, $ flexmeasures add schedule --sensor-id 2 --factor-id 3 \ --from ${TOMORROW}T07:00+01:00 --duration PT12H \ - --soc-at-start 50 --roundtrip-efficiency .9 + --soc-at-start 50 --roundtrip-efficiency 90 New schedule is stored. Great. Let's see what we made: @@ -220,25 +222,25 @@ Great. Let's see what we made: $ flexmeasures show beliefs --sensor-id 2 --from ${TOMORROW}T07:00:00+01:00 --duration PT12H Beliefs for Sensor 'charging' (Id 2). - Data spans 12 hours and starts at 2022-03-03 07:00:00+01:00. + Data spans 12 hours and starts at 2022-03-04 07:00:00+01:00. The time resolution (x-axis) is 15 minutes. ┌────────────────────────────────────────────────────────────┐ │ ▐ ▐▀▀▌ ▛▀▀│ - │ ▞▌ ▞ ▐ ▌ │ + │ ▞▌ ▞ ▐ ▌ │ 0.4MW │ ▌▌ ▌ ▐ ▐ │ │ ▗▘▌ ▌ ▐ ▐ │ │ ▐ ▐ ▗▘ ▝▖ ▐ │ - │ ▞ ▐ ▐ ▌ ▌ │ + │ ▞ ▐ ▐ ▌ ▌ │ 0.2MW │ ▗▘ ▐ ▐ ▌ ▌ │ │ ▐ ▝▖ ▌ ▚ ▞ │ - │▀▘───▀▀▀▀▀▀▀▀▀▀▀▀▀▀▌────▐─────▝▀▀▀▀▀▀▀▀▜─────▐▀▀▀▀▀▀▀▀▀─────│ + │▀▘───▀▀▀▀▀▀▀▀▀▀▀▀▀▀▌────▐─────▝▀▀▀▀▀▀▀▀▜─────▐▀▀▀▀▀▀▀▀▀─────│ 0MW │ ▌ ▞ ▐ ▗▘ │ │ ▚ ▌ ▐ ▐ │ - │ ▐ ▗▘ ▝▖ ▌ │ + │ ▐ ▗▘ ▝▖ ▌ │ -0.2MW │ ▐ ▐ ▌ ▌ │ │ ▐ ▐ ▌ ▗▘ │ │ ▌ ▞ ▌ ▐ │ - │ ▌ ▌ ▐ ▐ │ + │ ▌ ▌ ▐ ▐ │ -0.4MW │ ▙▄▄▌ ▐▄▄▞ │ └────────────────────────────────────────────────────────────┘ 10 20 30 40 @@ -255,4 +257,4 @@ We can also look at the charging schedule in the FlexMeasures UI (reachable via Recall that we only asked for a 12 hour schedule here. We started our schedule *after* the high price peak (at 5am) and it also had to end *before* the second price peak fully realised (at 9pm). Our scheduler didn't have many opportunities to optimize, but it found some. For instance, it does buy at the lowest price (around 3pm) and sells it off when prices start rising again (around 6pm). -.. note:: The ``flexmeasures add schedule`` command also accepts state of charge targets, so the schedule can be more sophisticated. But that is not the point of this tutorial. \ No newline at end of file +.. note:: The ``flexmeasures add schedule`` command also accepts state of charge targets, so the schedule can be more sophisticated. But that is not the point of this tutorial. diff --git a/flexmeasures/cli/data_add.py b/flexmeasures/cli/data_add.py index 70609c4a6..55545b033 100755 --- a/flexmeasures/cli/data_add.py +++ b/flexmeasures/cli/data_add.py @@ -797,13 +797,13 @@ def add_toy_account(kind: str, name: str): db.session.add(asset) if asset_type == "battery": asset.attributes = dict( - capacity_in_mw=0.005, min_soc_in_mwh=0.0005, max_soc_in_mwh=0.0045 + capacity_in_mw=0.5, min_soc_in_mwh=0.05, max_soc_in_mwh=0.45 ) # add charging sensor to battery charging_sensor = Sensor( name="charging", generic_asset=asset, - unit="kW", + unit="MW", timezone="Europe/Amsterdam", event_resolution=timedelta(minutes=15), ) From 377663486eb36cc19664475a59035933ba732532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20H=C3=B6ning?= Date: Thu, 3 Mar 2022 16:29:39 +0100 Subject: [PATCH 04/17] Clearer index, update small things in tutorial and getting started MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolas Höning --- documentation/getting-started.rst | 6 +++--- documentation/index.rst | 20 ++++++++++--------- .../tut/toy-example-from-scratch.rst | 12 +++++------ 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/documentation/getting-started.rst b/documentation/getting-started.rst index aa23b7ce5..1a887c4b2 100644 --- a/documentation/getting-started.rst +++ b/documentation/getting-started.rst @@ -6,9 +6,9 @@ Getting started Quickstart ---------- -This section walks you through getting FlexMeasures to run with the least effort. We'll cover making a secret key, connecting a database and creating one user & one asset. +This section walks you through getting FlexMeasures to run. For an example with the least effort, see :ref:`tut_toy_schedule`. Here, we'll cover getting started with an installation you run continuously ― making a secret key, connecting a database and creating one user & one asset. -.. note:: Are you not hosting FlexMeasures, but want to learn how to use it? Head over to our tutorials, starting with :ref:`tut_posting_data`. +.. note:: Are you not hosting FlexMeasures, but want to learn how to interact with it? Start with :ref:`tut_posting_data`. .. warning:: Are you implementing code based on FlexMeasures, please read :ref:`note_on_datamodel_transition`. @@ -127,7 +127,7 @@ Populate the database with some standard asset types, user roles etc.: .. code-block:: - flexmeasures add structure + flexmeasures add initial-structure Add your first asset diff --git a/documentation/index.rst b/documentation/index.rst index 37de72941..fb64fe8f3 100644 --- a/documentation/index.rst +++ b/documentation/index.rst @@ -1,17 +1,17 @@ Welcome to the FlexMeasures documentation! =================================================================== -*FlexMeasures is the intelligent backend to support real-time energy flexibility apps, rapidly and scalable.* +*FlexMeasures is the intelligent & developer-friendly backend to support real-time energy flexibility apps, rapidly and scalable.* In a world with renewable energy, flexibility is crucial and valuable, e.g. for demand response. Planning ahead allows flexible assets to serve the whole system with their flexibility, e.g. by shifting or curtailing energy use. -Developing energy flexibility services is expensive work. FlexMeasures reduces software development costs with: +Developing energy flexibility services is expensive work. FlexMeasures is designed to be developer-friendly, which helps you to go to market quickly, while keeping the costs of software development at bay. FlexMeasures delivers: - Real-time data intelligence & integration - Uncertainty models -- API/UI support +- App-building (API/UI/CLI & plugin support) A quick glance at usage @@ -43,8 +43,8 @@ As possible users, we see energy service companies (ESCOs) who want to build rea However, even small companies and hobby projects might find FlexMeasures useful! -The three core values: ------------------------ +The three ways in which FlexMeasures supports developers: +--------------------------------------------------------- Real-time data intelligence & integration ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -54,6 +54,7 @@ Energy flexibility services need to interact multiple times per day or hour. We - Support for real-time updates - Forecasting for the upcoming hours - Schedule optimization +- Extensions for integrating data, e.g. from `ENTSO-E `_ or `OpenWeatherMap `_ Uncertainty models @@ -64,13 +65,13 @@ Dealing with uncertain forecasts and outcomes is crucial. FlexMeasures is therefore built on the `timely-beliefs framework `_, so we model this real-world aspect accurately. -Service building +App building ^^^^^^^^^^^^^^^^^^ Building customer-facing apps & services is where developers make impact. We make their work easy. -- Well-documented API -- Plugin support -- Plotting support +- Well-documented API and CLI +- Plugin support (add your own logic) +- Backend UI and support for plotting - Multi-tenancy @@ -110,6 +111,7 @@ The platform operator of FlexMeasures can be an Aggregator. :caption: Tutorials :maxdepth: 1 + tut/toy-example-from-scratch tut/posting_data tut/forecasting_scheduling tut/building_uis diff --git a/documentation/tut/toy-example-from-scratch.rst b/documentation/tut/toy-example-from-scratch.rst index 8038ee2ef..195d7d9e7 100644 --- a/documentation/tut/toy-example-from-scratch.rst +++ b/documentation/tut/toy-example-from-scratch.rst @@ -3,7 +3,7 @@ Toy example: Scheduling a battery, from scratch =============================================== -Let's walk through an example from scratch! We'll +Let's walk through an example from scratch! We'll ... - install FlexMeasures - create an account with a battery asset @@ -108,7 +108,7 @@ If you want, you can inspect what you created: Yes, that is quite a large battery :) -.. note:: Obviously, you can use the `flexmeasures` command to create your own, custom account and assets. See :ref:`cli`. And to create, edit or read asset data via the API, see :ref:`v2_0`. +.. note:: Obviously, you can use the ``flexmeasures`` command to create your own, custom account and assets. See :ref:`cli`. And to create, edit or read asset data via the API, see :ref:`v2_0`. We can also look at the battery asset in the UI of FlexMeasures (start FlexMeasures with ``flexmeasures run``, username is "toy-user@flexmeasures.io", password is "toy-password"): @@ -150,7 +150,7 @@ Now to add price data. First, we'll create the csv file with prices (EUR/MWh, se ${TOMORROW}T22:00:00,10 ${TOMORROW}T23:00:00,7" > prices-tomorrow.csv -Note that time series data (which we call "beliefs" in FlexMeasures) can also be sent to FlexMeasures via API or imported from open data hubs like `ENTSO-E `_ or `OpenWeatherMap `_. However, in this tutorial we'll show how you can read data in from a CSV file. Sometimes that's just what you need :) +This is time series data, in FlexMeasures we call "beliefs". Beliefs can also be sent to FlexMeasures via API or imported from open data hubs like `ENTSO-E `_ or `OpenWeatherMap `_. However, in this tutorial we'll show how you can read data in from a CSV file. Sometimes that's just what you need :) .. code-block:: bash @@ -193,7 +193,7 @@ Let's look at the price data we just loaded: -Again, we can also view these sensor data in the FlexMeasures UI: +Again, we can also view these prices in the FlexMeasures UI: .. image:: https://github.com/FlexMeasures/screenshots/raw/main/tut/toy-schedule/sensor-data-prices.png :align: center @@ -207,7 +207,7 @@ Make a schedule Finally, we can create the schedule, which is the main benefit of FlexMeasures (smart real-time control). We'll ask FlexMeasures for a schedule for our charging sensor (Id 2). We also need to specify what to optimise against. Here we pass the Id of our market price sensor (3). -To keep it short, we'll only ask for a 12-hour window starting at 7am. Finally, the scheduler should know what the state of charge of the battery is when the schedule starts (50%) and what its roundtrip efficiency is (0.9). +To keep it short, we'll only ask for a 12-hour window starting at 7am. Finally, the scheduler should know what the state of charge of the battery is when the schedule starts (50%) and what its roundtrip efficiency is (90%). .. code-block:: bash @@ -257,4 +257,4 @@ We can also look at the charging schedule in the FlexMeasures UI (reachable via Recall that we only asked for a 12 hour schedule here. We started our schedule *after* the high price peak (at 5am) and it also had to end *before* the second price peak fully realised (at 9pm). Our scheduler didn't have many opportunities to optimize, but it found some. For instance, it does buy at the lowest price (around 3pm) and sells it off when prices start rising again (around 6pm). -.. note:: The ``flexmeasures add schedule`` command also accepts state of charge targets, so the schedule can be more sophisticated. But that is not the point of this tutorial. +.. note:: The ``flexmeasures add schedule`` command also accepts state-of-charge targets, so the schedule can be more sophisticated. But that is not the point of this tutorial. See ``flexmeasures add schedule --help``. From e626a7819f8eaed427a60511392e370bd3fe4f87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20H=C3=B6ning?= Date: Thu, 3 Mar 2022 16:37:45 +0100 Subject: [PATCH 05/17] small improvements on db handling tutorial MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolas Höning --- documentation/dev/data.rst | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/documentation/dev/data.rst b/documentation/dev/data.rst index 9d13fb6b0..d04022bbb 100644 --- a/documentation/dev/data.rst +++ b/documentation/dev/data.rst @@ -1,6 +1,6 @@ .. _dev-data: -Handling data +Handling databases ============================= This document describes how to get the postgres database ready to use and maintain it (do migrations / changes to the structure). @@ -210,17 +210,18 @@ You can create some pre-determined asset types and data sources with this comman .. code-block:: bash - flexmeasures add structure + flexmeasures add initial-structure +You can also create assets in the FlexMeasures UI. -.. todo:: We should instead offer CLI commands to be able to create asset types as needed. +On the command line, you can add many things. Check what data you can add yourself: -You can create assets in the FlexMeasures UI. +.. code-block:: bash + + flexmeasures add --help -.. todo:: Maybe a CLI command would help to script all data creation. -.. todo:: We still need a decent way to load in metering data, e.g. from CSV - often, a custom loading script will be necessary anyways. -You can create forecasts for your existing metered data with this command: +For instance, you can create forecasts for your existing metered data with this command: .. code-block:: bash @@ -230,13 +231,11 @@ You can create forecasts for your existing metered data with this command: Check out it's ``--help`` content to learn more. You can set which assets and which time window you want to forecast. Of course, making forecasts takes a while for a larger dataset. You can also simply queue a job with this command (and run a worker to process the :ref:`redis-queue`). -Just to note, there are also commands to get rid of data, such as: +Just to note, there are also commands to get rid of data. Check: .. code-block:: bash - flexmeasures delete structure - flexmeasures delete measurements - flexmeasures delete forecasts + flexmeasures delete --help Check out the :ref:`cli` documentation for more details. From 9eee79ebe11047709bdedd35c0fe3f70d00689ef Mon Sep 17 00:00:00 2001 From: "F.N. Claessen" Date: Fri, 4 Mar 2022 22:24:12 +0100 Subject: [PATCH 06/17] Update tutorial against revisions of scheduling CLI command Signed-off-by: F.N. Claessen --- documentation/tut/toy-example-from-scratch.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/documentation/tut/toy-example-from-scratch.rst b/documentation/tut/toy-example-from-scratch.rst index 195d7d9e7..85c4e0c76 100644 --- a/documentation/tut/toy-example-from-scratch.rst +++ b/documentation/tut/toy-example-from-scratch.rst @@ -19,9 +19,9 @@ Below are the ``flexmeasures`` CLI commands we'll run, and which we'll explain s # load prices to optimise the schedule against $ flexmeasures add beliefs --sensor-id 3 --source toy-user prices-tomorrow.csv # make the schedule - $ flexmeasures add schedule --sensor-id 2 --factor-id 3 \ + $ flexmeasures add schedule --sensor-id 2 --optimization-context-id 3 \ --from $(date '+%Y-%m-%d')T06:00+02:00 --duration PT12H \ - --soc-at-start 50 --roundtrip-efficiency 90 + --soc-at-start 50% --roundtrip-efficiency 90% Okay, let's get started! @@ -211,9 +211,9 @@ To keep it short, we'll only ask for a 12-hour window starting at 7am. Finally, .. code-block:: bash - $ flexmeasures add schedule --sensor-id 2 --factor-id 3 \ + $ flexmeasures add schedule --sensor-id 2 --optimization-context-id 3 \ --from ${TOMORROW}T07:00+01:00 --duration PT12H \ - --soc-at-start 50 --roundtrip-efficiency 90 + --soc-at-start 50% --roundtrip-efficiency 90% New schedule is stored. Great. Let's see what we made: From ab2fe81ab17c40a644752bd9a78ee0917ceefb24 Mon Sep 17 00:00:00 2001 From: "F.N. Claessen" Date: Fri, 4 Mar 2022 22:39:19 +0100 Subject: [PATCH 07/17] typo Signed-off-by: F.N. Claessen --- documentation/tut/toy-example-from-scratch.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/tut/toy-example-from-scratch.rst b/documentation/tut/toy-example-from-scratch.rst index 85c4e0c76..3ace377ed 100644 --- a/documentation/tut/toy-example-from-scratch.rst +++ b/documentation/tut/toy-example-from-scratch.rst @@ -159,7 +159,7 @@ This is time series data, in FlexMeasures we call "beliefs". Beliefs can also be In FlexMeasures, all beliefs have a data source. Here, we use the username of the user we created earlier. We could also pass a user ID, or the name of a new data source we want to use for CLI scripts. -.. note:: Attention: We created and imported prices where the times have no time zone component! That happens a lot. FlexMeasures will then interpret them as UTC time. So if you are in Amsterdam time, the the start time for the first price, when expressed in your time zone, is actually `2022-03-03 01:00:00+01:00`. +.. note:: Attention: We created and imported prices where the times have no time zone component! That happens a lot. FlexMeasures will then interpret them as UTC time. So if you are in Amsterdam time, the start time for the first price, when expressed in your time zone, is actually `2022-03-03 01:00:00+01:00`. Let's look at the price data we just loaded: From 15c2c8234787d264058291e37732d9c57e1062f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20H=C3=B6ning?= Date: Sat, 5 Mar 2022 11:43:28 +0100 Subject: [PATCH 08/17] also replace factor-id parameter on docs index MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolas Höning --- documentation/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/index.rst b/documentation/index.rst index fb64fe8f3..f88263a0f 100644 --- a/documentation/index.rst +++ b/documentation/index.rst @@ -27,7 +27,7 @@ A tiny, but complete example: Let's install FlexMeasures from scratch. Then, usi flexmeasures db upgrade # create tables flexmeasures add toy-account --kind battery # setup account & a user, a battery (Id 2) and a market (Id 3) flexmeasures add beliefs --sensor-id 3 --source toy-user prices-tomorrow.csv # load prices, also possible per API - flexmeasures add schedule --sensor-id 2 --factor-id 3 \ + flexmeasures add schedule --sensor-id 2 --optimization-context-id 3 \ --from ${TOMORROW}T07:00+01:00 --duration PT12H \ --soc-at-start 50 --roundtrip-efficiency 90 # this is also possible per API flexmeasures show beliefs --sensor-id 2 --from ${TOMORROW}T07:00:00+01:00 --duration PT12H # also visible per UI, of course From 2c1df6c949600e84973b8b3745b5b65e456b8990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20H=C3=B6ning?= Date: Sat, 5 Mar 2022 11:51:42 +0100 Subject: [PATCH 09/17] also add percentages to schedule command in doc index MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolas Höning --- documentation/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/index.rst b/documentation/index.rst index f88263a0f..b8dfe3dd7 100644 --- a/documentation/index.rst +++ b/documentation/index.rst @@ -29,7 +29,7 @@ A tiny, but complete example: Let's install FlexMeasures from scratch. Then, usi flexmeasures add beliefs --sensor-id 3 --source toy-user prices-tomorrow.csv # load prices, also possible per API flexmeasures add schedule --sensor-id 2 --optimization-context-id 3 \ --from ${TOMORROW}T07:00+01:00 --duration PT12H \ - --soc-at-start 50 --roundtrip-efficiency 90 # this is also possible per API + --soc-at-start 50% --roundtrip-efficiency 90% # this is also possible per API flexmeasures show beliefs --sensor-id 2 --from ${TOMORROW}T07:00:00+01:00 --duration PT12H # also visible per UI, of course We discuss this in more depth at :ref:`tut_toy_schedule`. From 9ee743649e21c4950ab139815ad04d45a50294eb Mon Sep 17 00:00:00 2001 From: "F.N. Claessen" Date: Mon, 7 Mar 2022 10:24:11 +0100 Subject: [PATCH 10/17] Switch code-blocks from BashLexer to BashSessionLexer to get more appropriate code highlighting Signed-off-by: F.N. Claessen --- documentation/tut/toy-example-from-scratch.rst | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/documentation/tut/toy-example-from-scratch.rst b/documentation/tut/toy-example-from-scratch.rst index 3ace377ed..9aa4e667d 100644 --- a/documentation/tut/toy-example-from-scratch.rst +++ b/documentation/tut/toy-example-from-scratch.rst @@ -12,7 +12,7 @@ Let's walk through an example from scratch! We'll ... Below are the ``flexmeasures`` CLI commands we'll run, and which we'll explain step by step. There are some other crucial steps for installation and setup, so this becomes a complete example from scratch, but this is the meat: -.. code-block:: bash +.. code-block:: console # setup an account with a user, a battery (Id 2) and a market (Id 3) $ flexmeasures add toy-account --kind battery @@ -34,7 +34,7 @@ This example is from scratch, so we'll assume you have nothing prepared but a (U We install the FlexMeasures platform, use Docker to run a postgres database and tell FlexMeasures to create all tables. -.. code-block:: bash +.. code-block:: console $ pip install flexmeasures $ docker pull postgres; docker run --name pg-docker -e POSTGRES_PASSWORD=docker -e POSTGRES_DB=flexmeasures-db -d -p 5433:5432 postgres:latest @@ -51,7 +51,7 @@ Let's create the structural data first. FlexMeasures offers a command to create a toy account with a battery: -.. code-block:: bash +.. code-block:: console $ flexmeasures add toy-account --kind battery @@ -63,7 +63,7 @@ And with that, we're done with the structural data for this tutorial! If you want, you can inspect what you created: -.. code-block:: bash +.. code-block:: console $ flexmeasures show account --id 1 @@ -121,7 +121,7 @@ Add some price data Now to add price data. First, we'll create the csv file with prices (EUR/MWh, see the setup for sensor 3 above) for tomorrow. -.. code-block:: bash +.. code-block:: console $ TOMORROW=$(date --date="next day" '+%Y-%m-%d') $ echo "Hour,Price @@ -152,7 +152,7 @@ Now to add price data. First, we'll create the csv file with prices (EUR/MWh, se This is time series data, in FlexMeasures we call "beliefs". Beliefs can also be sent to FlexMeasures via API or imported from open data hubs like `ENTSO-E `_ or `OpenWeatherMap `_. However, in this tutorial we'll show how you can read data in from a CSV file. Sometimes that's just what you need :) -.. code-block:: bash +.. code-block:: console $ flexmeasures add beliefs --sensor-id 3 --source toy-user prices-tomorrow.csv Successfully created beliefs @@ -163,7 +163,7 @@ In FlexMeasures, all beliefs have a data source. Here, we use the username of th Let's look at the price data we just loaded: -.. code-block:: bash +.. code-block:: console $ flexmeasures show beliefs --sensor-id 3 --from ${TOMORROW}T01:00:00+01:00 --duration PT24H Beliefs for Sensor 'Day ahead prices' (Id 3). @@ -209,7 +209,7 @@ Finally, we can create the schedule, which is the main benefit of FlexMeasures ( We'll ask FlexMeasures for a schedule for our charging sensor (Id 2). We also need to specify what to optimise against. Here we pass the Id of our market price sensor (3). To keep it short, we'll only ask for a 12-hour window starting at 7am. Finally, the scheduler should know what the state of charge of the battery is when the schedule starts (50%) and what its roundtrip efficiency is (90%). -.. code-block:: bash +.. code-block:: console $ flexmeasures add schedule --sensor-id 2 --optimization-context-id 3 \ --from ${TOMORROW}T07:00+01:00 --duration PT12H \ @@ -218,7 +218,7 @@ To keep it short, we'll only ask for a 12-hour window starting at 7am. Finally, Great. Let's see what we made: -.. code-block:: bash +.. code-block:: console $ flexmeasures show beliefs --sensor-id 2 --from ${TOMORROW}T07:00:00+01:00 --duration PT12H Beliefs for Sensor 'charging' (Id 2). From 1d4d1c32cd9c14c8e0b448d1639abc5d11a73c7e Mon Sep 17 00:00:00 2001 From: "F.N. Claessen" Date: Mon, 7 Mar 2022 10:35:56 +0100 Subject: [PATCH 11/17] Update code-block lexers Signed-off-by: F.N. Claessen --- documentation/cli/commands.rst | 2 +- documentation/configuration.rst | 4 +- documentation/dev/ci.rst | 2 +- documentation/dev/data.rst | 48 ++++++++++---------- documentation/dev/error-monitoring.rst | 2 +- documentation/dev/introduction.rst | 18 ++++---- documentation/dev/plugins.rst | 2 +- documentation/getting-started.rst | 34 +++++++------- documentation/tut/forecasting_scheduling.rst | 2 +- 9 files changed, 57 insertions(+), 57 deletions(-) diff --git a/documentation/cli/commands.rst b/documentation/cli/commands.rst index 3d02fb315..3268fd5b9 100644 --- a/documentation/cli/commands.rst +++ b/documentation/cli/commands.rst @@ -11,7 +11,7 @@ Each command has more extensive documentation if you call it with ``--help``. We keep track of changes to these commands in :ref:`cli-changelog`. You can also get the current overview over the commands you have available by: -.. code-block:: +.. code-block:: console flexmeasures --help diff --git a/documentation/configuration.rst b/documentation/configuration.rst index 03e1874ee..32c3129cd 100644 --- a/documentation/configuration.rst +++ b/documentation/configuration.rst @@ -293,7 +293,7 @@ Configuration of the SQLAlchemy engine. Default: -.. code-block:: +.. code-block:: python { "pool_recycle": 299, @@ -427,7 +427,7 @@ Tuple of shown name of sender and their email address. Default: -.. code-block:: +.. code-block:: python ( "FlexMeasures", diff --git a/documentation/dev/ci.rst b/documentation/dev/ci.rst index bedf20bd1..d100a022f 100644 --- a/documentation/dev/ci.rst +++ b/documentation/dev/ci.rst @@ -44,7 +44,7 @@ Cbc needs to be present on the server where FlexMeasures runs, under the ``cbc`` You can install it on Debian like this: -.. code-block:: bash +.. code-block:: console apt-get install coinor-cbc diff --git a/documentation/dev/data.rst b/documentation/dev/data.rst index d04022bbb..e9c78f131 100644 --- a/documentation/dev/data.rst +++ b/documentation/dev/data.rst @@ -29,7 +29,7 @@ Install On Unix: -.. code-block:: bash +.. code-block:: console sudo apt-get install postgresql pip install psycopg2-binary @@ -61,7 +61,7 @@ Find the ``timezone`` setting and set it to 'UTC'. Then restart the postgres server. -.. code-block:: bash +.. code-block:: console service postgresql restart @@ -71,7 +71,7 @@ Setup the "flexmeasures" Unix user This may in fact not be needed: -.. code-block:: bash +.. code-block:: console sudo /usr/sbin/adduser flexmeasures @@ -84,7 +84,7 @@ From the terminal: Open a console (use your Windows key and type ``cmd``\ ). Proceed to create a database as the postgres superuser (using your postgres user password): -.. code-block:: bash +.. code-block:: console sudo -i -u postgres createdb -U postgres flexmeasures @@ -106,7 +106,7 @@ Or, from within Postgres console: Finally, test if you can log in as the flexmeasures user: -.. code-block:: bash +.. code-block:: console psql -U flexmeasures --password -h 127.0.0.1 -d flexmeasures @@ -121,7 +121,7 @@ Add Postgres Extensions to your database(s) To find the nearest sensors, FlexMeasures needs some extra Postgres support. Add the following extensions while logged in as the postgres superuser: -.. code-block:: bash +.. code-block:: console sudo -u postgres psql @@ -161,7 +161,7 @@ Here is a short recipe to import data from a FlexMeasures database (e.g. a demo On the to-be-exported database: -.. code-block:: bash +.. code-block:: console flexmeasures db-ops dump @@ -170,14 +170,14 @@ On the to-be-exported database: Then, we create the structure in our database anew, based on the data model given by the local codebase: -.. code-block:: bash +.. code-block:: console flexmeasures db-ops reset Then we import the data dump we made earlier: -.. code-block:: bash +.. code-block:: console flexmeasures db-ops restore @@ -192,7 +192,7 @@ Create data manually First, you can get the database structure with: -.. code-block:: bash +.. code-block:: console flexmeasures db upgrade @@ -201,14 +201,14 @@ First, you can get the database structure with: You can create users with the ``new-user`` command. Check it out: -.. code-block:: bash +.. code-block:: console flexmeasures add user --help You can create some pre-determined asset types and data sources with this command: -.. code-block:: bash +.. code-block:: console flexmeasures add initial-structure @@ -216,14 +216,14 @@ You can also create assets in the FlexMeasures UI. On the command line, you can add many things. Check what data you can add yourself: -.. code-block:: bash +.. code-block:: console flexmeasures add --help For instance, you can create forecasts for your existing metered data with this command: -.. code-block:: bash +.. code-block:: console flexmeasures add forecasts @@ -233,7 +233,7 @@ You can also simply queue a job with this command (and run a worker to process t Just to note, there are also commands to get rid of data. Check: -.. code-block:: bash +.. code-block:: console flexmeasures delete --help @@ -246,7 +246,7 @@ Visualize the data model You can visualise the data model like this: -.. code-block:: bash +.. code-block:: console make show-data-model @@ -267,7 +267,7 @@ Make first migration Run these commands from the repository root directory (read below comments first): -.. code-block:: bash +.. code-block:: console flexmeasures db init flexmeasures db migrate @@ -287,7 +287,7 @@ Make another migration Just to be clear that the ``db init`` command is needed only at the beginning - you usually do, if your model changed: -.. code-block:: bash +.. code-block:: console flexmeasures db migrate --message "Please explain what you did, it helps for later" flexmeasures db upgrade @@ -298,7 +298,7 @@ Get database structure updated The goal is that on any other computer, you can always execute -.. code-block:: bash +.. code-block:: console flexmeasures db upgrade @@ -310,7 +310,7 @@ Working with the migration history The history of migrations is at your fingertips: -.. code-block:: bash +.. code-block:: console flexmeasures db current flexmeasures db history @@ -318,7 +318,7 @@ The history of migrations is at your fingertips: You can move back and forth through the history: -.. code-block:: bash +.. code-block:: console flexmeasures db downgrade flexmeasures db upgrade @@ -331,7 +331,7 @@ Check out database status Log in into the database: -.. code-block:: bash +.. code-block:: console psql -U flexmeasures --password -h 127.0.0.1 -d flexmeasures @@ -370,7 +370,7 @@ It relies on a Redis server, which is has to be installed locally, or used on a Forecasting jobs are usually created (and enqueued) when new data comes in via the API. To asynchronously work on these forecasting jobs, run this in a console: -.. code-block:: bash +.. code-block:: console flexmeasures jobs run_worker --queue forecasting @@ -385,7 +385,7 @@ Inspect the queue and jobs The first option to inspect the state of the ``forecasting`` queue should be via the formidable `RQ dashboard `_. If you have admin rights, you can access it at ``your-flexmeasures-url/rq/``\ , so for instance ``http://localhost:5000/rq/``. You can also start RQ dashboard yourself (but you need to know the redis server credentials): -.. code-block:: bash +.. code-block:: console pip install rq-dashboard rq-dashboard --redis-host my.ip.addr.ess --redis-password secret --redis-database 0 diff --git a/documentation/dev/error-monitoring.rst b/documentation/dev/error-monitoring.rst index 94424b503..99bc4749b 100644 --- a/documentation/dev/error-monitoring.rst +++ b/documentation/dev/error-monitoring.rst @@ -10,7 +10,7 @@ When you run a FlexMeasures server, you want to stay on top of things going wron For illustration of the latter monitoring, here is one example of how we monitor tasks on a server ― the below is run in a cron script every hour and checks if every listed task ran 60, 6 or 1440 minutes ago, respectively: -.. code-block:: bash +.. code-block:: console flexmeasures monitor tasks --task get_weather_forecasts 60 --task get_recent_meter_data 6  --task import_epex_prices 1440 diff --git a/documentation/dev/introduction.rst b/documentation/dev/introduction.rst index af5b6bfbd..f4c8abb67 100644 --- a/documentation/dev/introduction.rst +++ b/documentation/dev/introduction.rst @@ -30,7 +30,7 @@ Dependencies Install all dependencies including the ones needed for development: -.. code-block:: bash +.. code-block:: console make install-for-dev @@ -46,7 +46,7 @@ Loading data If you have a SQL Dump file, you can load that: -.. code-block:: bash +.. code-block:: console psql -U {user_name} -h {host_name} -d {database_name} -f {file_path} @@ -56,14 +56,14 @@ Run locally Now, to start the web application, you can run: -.. code-block:: bash +.. code-block:: console flexmeasures run Or: -.. code-block:: bash +.. code-block:: console python run-local.py @@ -86,7 +86,7 @@ Tests You can run automated tests with: -.. code-block:: bash +.. code-block:: console make test @@ -95,7 +95,7 @@ which behind the curtains installs dependencies and calls pytest. A coverage report can be created like this: -.. code-block:: bash +.. code-block:: console pytest --cov=flexmeasures --cov-config .coveragerc @@ -104,7 +104,7 @@ You can add --cov-report=html after which a htmlcov/index.html is generated. It's also possible to use: -.. code-block:: bash +.. code-block:: console python setup.py test @@ -133,7 +133,7 @@ We also run `mypy `_ on many files to do some static type We do this so real problems are found faster and the discussion about formatting is limited. All of these can be installed by using ``pip``, but we recommend using them as a pre-commit hook. To activate that behaviour, do: -.. code-block:: bash +.. code-block:: console pip install pre-commit pre-commit install @@ -156,7 +156,7 @@ A hint about using notebooks If you edit notebooks, make sure results do not end up in git: -.. code-block:: bash +.. code-block:: console conda install -c conda-forge nbstripout nbstripout --install diff --git a/documentation/dev/plugins.rst b/documentation/dev/plugins.rst index e66ecf8be..b97b61632 100644 --- a/documentation/dev/plugins.rst +++ b/documentation/dev/plugins.rst @@ -364,6 +364,6 @@ Place this template file in the template folder of your plugin blueprint (see ab Finally, add this config setting to your FlexMeasures config file (using the template filename you chose, obviously): - .. code-block:: bash + .. code-block:: python SECURITY_LOGIN_USER_TEMPLATE = "my_user_login.html" diff --git a/documentation/getting-started.rst b/documentation/getting-started.rst index 1a887c4b2..200046fe8 100644 --- a/documentation/getting-started.rst +++ b/documentation/getting-started.rst @@ -18,7 +18,7 @@ Install FlexMeasures Install dependencies and the ``flexmeasures`` platform itself: -.. code-block:: +.. code-block:: console pip install flexmeasures @@ -30,7 +30,7 @@ Make a secret key for sessions and password salts Set a secret key which is used to sign user sessions and re-salt their passwords. The quickest way is with an environment variable, like this: -.. code-block:: +.. code-block:: console export SECRET_KEY=something-secret @@ -40,7 +40,7 @@ This suffices for a quick start. If you want to consistently use FlexMeasures, we recommend you add this setting to your config file at ``~/.flexmeasures.cfg`` and use a truly random string. Here is a Pythonic way to generate a good secret key: -.. code-block:: +.. code-block:: console python -c "import secrets; print(secrets.token_urlsafe())" @@ -51,7 +51,7 @@ Configure environment Set an environment variable to indicate in which environment you are operating (one out of development|testing|staging|production). We'll go with ``development`` here: -.. code-block:: +.. code-block:: console export FLASK_ENV=development @@ -59,7 +59,7 @@ Set an environment variable to indicate in which environment you are operating ( or: -.. code-block:: +.. code-block:: console echo "FLASK_ENV=development" >> .env @@ -74,7 +74,7 @@ Preparing the time series database * Tell ``flexmeasures`` about it: - .. code-block:: + .. code-block:: console export SQLALCHEMY_DATABASE_URI="postgresql://:@[:]/" @@ -84,7 +84,7 @@ Preparing the time series database * Create the Postgres DB structure for FlexMeasures: - .. code-block:: + .. code-block:: console flexmeasures db upgrade @@ -92,7 +92,7 @@ This suffices for a quick start. .. note:: For a more permanent configuration, you can create your FlexMeasures configuration file at ``~/.flexmeasures.cfg`` and add this: - .. code-block:: + .. code-block:: console SQLALCHEMY_DATABASE_URI="postgresql://:@[:]/" @@ -103,7 +103,7 @@ Add an account & user FlexMeasures is a tenant-based platform ― multiple clients can enjoy its services on one server. Let's create a tenant account first: -.. code-block:: +.. code-block:: console flexmeasures add account --name "Some company" @@ -111,7 +111,7 @@ This command will tell us the ID of this account. Let's assume it was ``2``. FlexMeasures is also a web-based platform, so we need to create a user to authenticate: -.. code-block:: +.. code-block:: console flexmeasures add user --username --email --account-id 2 --roles=admin @@ -125,7 +125,7 @@ Add structure Populate the database with some standard asset types, user roles etc.: -.. code-block:: +.. code-block:: console flexmeasures add initial-structure @@ -137,7 +137,7 @@ There are three ways to add assets: First, you can use the ``flexmeasures`` :ref:`cli`: -.. code-block:: +.. code-block:: console flexmeasures add asset --name "my basement battery pack" --asset-type-id 3 --latitude 65 --longitude 123.76 --account-id 2 @@ -155,7 +155,7 @@ Add your first sensor Usually, we are here because we want to measure something with respect to our assets. Each assets can have sensors for that, so let's add a power sensor to our new battery asset, using the ``flexmeasures`` :ref:`cli`: -.. code-block:: +.. code-block:: console flexmeasures add sensor --name power --unit MW --event-resolution 5 --timezone Europe/Amsterdam --asset-id 1 --attributes '{"capacity_in_mw": 7}' @@ -169,7 +169,7 @@ Run FlexMeasures It's finally time to start running FlexMeasures: -.. code-block:: +.. code-block:: console flexmeasures run @@ -189,7 +189,7 @@ There are three ways to add data: First, you can load in data from a file (CSV or Excel) via the ``flexmeasures`` :ref:`cli`: -.. code-block:: +.. code-block:: console flexmeasures add beliefs --file my-data.csv --skiprows 2 --delimiter ";" --source OurLegacyDatabase --sensor-id 1 @@ -199,7 +199,7 @@ Second, you can use the `POST /api/v2_0/postMeterData Date: Mon, 7 Mar 2022 11:58:18 +0100 Subject: [PATCH 12/17] Fix command for price input (at least, with respect to how it's displayed in the tutorial) Signed-off-by: F.N. Claessen --- .../tut/toy-example-from-scratch.rst | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/documentation/tut/toy-example-from-scratch.rst b/documentation/tut/toy-example-from-scratch.rst index 9aa4e667d..4e9a9546f 100644 --- a/documentation/tut/toy-example-from-scratch.rst +++ b/documentation/tut/toy-example-from-scratch.rst @@ -125,30 +125,30 @@ Now to add price data. First, we'll create the csv file with prices (EUR/MWh, se $ TOMORROW=$(date --date="next day" '+%Y-%m-%d') $ echo "Hour,Price - ${TOMORROW}T00:00:00,10 - ${TOMORROW}T01:00:00,11 - ${TOMORROW}T02:00:00,12 - ${TOMORROW}T03:00:00,15 - ${TOMORROW}T04:00:00,18 - ${TOMORROW}T05:00:00,17 - ${TOMORROW}T06:00:00,10.5 - ${TOMORROW}T07:00:00,9 - ${TOMORROW}T08:00:00,9.5 - ${TOMORROW}T09:00:00,9 - ${TOMORROW}T10:00:00,8.5 - ${TOMORROW}T11:00:00,10 - ${TOMORROW}T12:00:00,8 - ${TOMORROW}T13:00:00,5 - ${TOMORROW}T14:00:00,4 - ${TOMORROW}T15:00:00,4 - ${TOMORROW}T16:00:00,5.5 - ${TOMORROW}T17:00:00,8 - ${TOMORROW}T18:00:00,12 - ${TOMORROW}T19:00:00,13 - ${TOMORROW}T20:00:00,14 - ${TOMORROW}T21:00:00,12.5 - ${TOMORROW}T22:00:00,10 - ${TOMORROW}T23:00:00,7" > prices-tomorrow.csv + $ ${TOMORROW}T00:00:00,10 + $ ${TOMORROW}T01:00:00,11 + $ ${TOMORROW}T02:00:00,12 + $ ${TOMORROW}T03:00:00,15 + $ ${TOMORROW}T04:00:00,18 + $ ${TOMORROW}T05:00:00,17 + $ ${TOMORROW}T06:00:00,10.5 + $ ${TOMORROW}T07:00:00,9 + $ ${TOMORROW}T08:00:00,9.5 + $ ${TOMORROW}T09:00:00,9 + $ ${TOMORROW}T10:00:00,8.5 + $ ${TOMORROW}T11:00:00,10 + $ ${TOMORROW}T12:00:00,8 + $ ${TOMORROW}T13:00:00,5 + $ ${TOMORROW}T14:00:00,4 + $ ${TOMORROW}T15:00:00,4 + $ ${TOMORROW}T16:00:00,5.5 + $ ${TOMORROW}T17:00:00,8 + $ ${TOMORROW}T18:00:00,12 + $ ${TOMORROW}T19:00:00,13 + $ ${TOMORROW}T20:00:00,14 + $ ${TOMORROW}T21:00:00,12.5 + $ ${TOMORROW}T22:00:00,10 + $ ${TOMORROW}T23:00:00,7" > prices-tomorrow.csv This is time series data, in FlexMeasures we call "beliefs". Beliefs can also be sent to FlexMeasures via API or imported from open data hubs like `ENTSO-E `_ or `OpenWeatherMap `_. However, in this tutorial we'll show how you can read data in from a CSV file. Sometimes that's just what you need :) From 8facc41dfa58f7de526397e117dcd4a3ccddbaf8 Mon Sep 17 00:00:00 2001 From: "F.N. Claessen" Date: Mon, 7 Mar 2022 12:12:11 +0100 Subject: [PATCH 13/17] Add copybutton to documentation code-blocks Signed-off-by: F.N. Claessen --- documentation/conf.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/documentation/conf.py b/documentation/conf.py index 74f63af42..0da349918 100644 --- a/documentation/conf.py +++ b/documentation/conf.py @@ -47,6 +47,7 @@ "sphinx.ext.imgmath", "sphinx.ext.ifconfig", "sphinx.ext.todo", + "sphinx_copybutton", "sphinx_fontawesome", "sphinxcontrib.autohttp.flask", "sphinxcontrib.autohttp.flaskqref", @@ -191,6 +192,11 @@ # Example configuration for intersphinx: refer to the Python standard library. intersphinx_mapping = {"https://docs.python.org/": None} +# -- Options for copybytton extension --------------------------------------- +copybutton_prompt_is_regexp = True +copybutton_prompt_text = r">>> |\.\.\. |\$ " # Python Repl + continuation + Bash +copybutton_line_continuation_character = "\\" + # -- Options for ifconfig extension --------------------------------------- From 91b0fb52d5947a989143fdc170c58a2bd13eb548 Mon Sep 17 00:00:00 2001 From: "F.N. Claessen" Date: Mon, 7 Mar 2022 12:13:38 +0100 Subject: [PATCH 14/17] Set up the toy day-ahead market with an appropriate knowledge horizon set to a gate closure at noon Signed-off-by: F.N. Claessen --- flexmeasures/cli/data_add.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/flexmeasures/cli/data_add.py b/flexmeasures/cli/data_add.py index 55545b033..63e090410 100755 --- a/flexmeasures/cli/data_add.py +++ b/flexmeasures/cli/data_add.py @@ -11,6 +11,7 @@ import click import getpass from sqlalchemy.exc import IntegrityError +from timely_beliefs.sensors.func_store.knowledge_horizons import x_days_ago_at_y_oclock import timely_beliefs as tb from workalendar.registry import registry as workalendar_registry @@ -821,6 +822,10 @@ def add_toy_account(kind: str, name: str): unit="EUR/MWh", timezone="Europe/Amsterdam", event_resolution=timedelta(minutes=60), + knowledge_horizon=( + x_days_ago_at_y_oclock, + {"x": 1, "y": 12, "z": "Europe/Paris"}, + ), ) db.session.add(day_ahead_sensor) From 5e88d20bbb1035628b7e0cadb0d30fef8be00666 Mon Sep 17 00:00:00 2001 From: "F.N. Claessen" Date: Mon, 7 Mar 2022 12:20:15 +0100 Subject: [PATCH 15/17] Adjust tutorial note on price forecasts Signed-off-by: F.N. Claessen --- documentation/tut/toy-example-from-scratch.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/tut/toy-example-from-scratch.rst b/documentation/tut/toy-example-from-scratch.rst index 4e9a9546f..cdb20c16c 100644 --- a/documentation/tut/toy-example-from-scratch.rst +++ b/documentation/tut/toy-example-from-scratch.rst @@ -198,7 +198,7 @@ Again, we can also view these prices in the FlexMeasures UI: .. image:: https://github.com/FlexMeasures/screenshots/raw/main/tut/toy-schedule/sensor-data-prices.png :align: center -.. note:: Technically, these prices for tomorrow are forecasts. You can also use FlexMeasures to compute forecasts yourself. See :ref:`tut_forecasting_scheduling`. +.. note:: Technically, these prices for tomorrow may be forecasts (depending on whether you are running through this tutorial before or after the day-ahead market's gate closure). You can also use FlexMeasures to compute forecasts yourself. See :ref:`tut_forecasting_scheduling`. Make a schedule From 134754e5adf8a1c817679676ace02c53a1f48648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20H=C3=B6ning?= Date: Mon, 7 Mar 2022 14:30:51 +0100 Subject: [PATCH 16/17] add copybutton to doc requirements and also update vesions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolas Höning --- documentation/requirements.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/documentation/requirements.txt b/documentation/requirements.txt index 804297105..145f64adf 100644 --- a/documentation/requirements.txt +++ b/documentation/requirements.txt @@ -1,3 +1,4 @@ -sphinx==4.1.2 -sphinxcontrib.httpdomain==1.7.0 +sphinx==4.4.0 +sphinxcontrib.httpdomain==1.8.0 sphinx_fontawesome==0.0.6 +sphinx_copybutton==0.5.0 From 6d287719dc06c2f8eb6d279935ce40da39e2c3de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20H=C3=B6ning?= Date: Mon, 7 Mar 2022 14:31:48 +0100 Subject: [PATCH 17/17] also use console lexing for main page tutorial version, update use of TOMORROW variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolas Höning --- documentation/changelog.rst | 1 - documentation/index.rst | 20 +++++++++---------- .../tut/toy-example-from-scratch.rst | 2 +- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/documentation/changelog.rst b/documentation/changelog.rst index 6832fc0e4..3bd34657a 100644 --- a/documentation/changelog.rst +++ b/documentation/changelog.rst @@ -14,7 +14,6 @@ New features * Add CLI option to specify custom strings that should be interpreted as NaN values when reading in time series data from CSV [see `PR #357 `_] * Add CLI commands ``flexmeasures add sensor``, ``flexmeasures add asset-type``, ``flexmeasures add beliefs`` (which were experimental features before). [see `PR #337 `_] * Add CLI commands for showing data [see `PR #339 `_] - * Add CLI command for attaching annotations to assets: ``flexmeasures add holidays`` adds public holidays [see `PR #343 `_] * Add CLI command for resampling existing sensor data to new resolution [see `PR #360 `_] * Add CLI command to add a toy account for tutorials and trying things [see `PR #368 `_]. diff --git a/documentation/index.rst b/documentation/index.rst index b8dfe3dd7..d0854e3cd 100644 --- a/documentation/index.rst +++ b/documentation/index.rst @@ -19,18 +19,18 @@ A quick glance at usage A tiny, but complete example: Let's install FlexMeasures from scratch. Then, using only the terminal, load hourly prices and optimize a 12h-schedule for a battery that is half full at the beginning. -.. code-block:: bash - - pip install flexmeasures - docker pull postgres; docker run --name pg-docker -e POSTGRES_PASSWORD=docker -e POSTGRES_DB=flexmeasures-db -d -p 5433:5432 postgres:latest - export SQLALCHEMY_DATABASE_URI="postgresql://postgres:docker@127.0.0.1:5433/flexmeasures-db" && export SECRET_KEY=notsecret - flexmeasures db upgrade # create tables - flexmeasures add toy-account --kind battery # setup account & a user, a battery (Id 2) and a market (Id 3) - flexmeasures add beliefs --sensor-id 3 --source toy-user prices-tomorrow.csv # load prices, also possible per API - flexmeasures add schedule --sensor-id 2 --optimization-context-id 3 \ +.. code-block:: console + + $ pip install flexmeasures + $ docker pull postgres; docker run --name pg-docker -e POSTGRES_PASSWORD=docker -e POSTGRES_DB=flexmeasures-db -d -p 5433:5432 postgres:latest + $ export SQLALCHEMY_DATABASE_URI="postgresql://postgres:docker@127.0.0.1:5433/flexmeasures-db" && export SECRET_KEY=notsecret + $ flexmeasures db upgrade # create tables + $ flexmeasures add toy-account --kind battery # setup account & a user, a battery (Id 2) and a market (Id 3) + $ flexmeasures add beliefs --sensor-id 3 --source toy-user prices-tomorrow.csv # load prices, also possible per API + $ flexmeasures add schedule --sensor-id 2 --optimization-context-id 3 \ --from ${TOMORROW}T07:00+01:00 --duration PT12H \ --soc-at-start 50% --roundtrip-efficiency 90% # this is also possible per API - flexmeasures show beliefs --sensor-id 2 --from ${TOMORROW}T07:00:00+01:00 --duration PT12H # also visible per UI, of course + $ flexmeasures show beliefs --sensor-id 2 --from ${TOMORROW}T07:00:00+01:00 --duration PT12H # also visible per UI, of course We discuss this in more depth at :ref:`tut_toy_schedule`. diff --git a/documentation/tut/toy-example-from-scratch.rst b/documentation/tut/toy-example-from-scratch.rst index cdb20c16c..a1d17a2fb 100644 --- a/documentation/tut/toy-example-from-scratch.rst +++ b/documentation/tut/toy-example-from-scratch.rst @@ -20,7 +20,7 @@ Below are the ``flexmeasures`` CLI commands we'll run, and which we'll explain s $ flexmeasures add beliefs --sensor-id 3 --source toy-user prices-tomorrow.csv # make the schedule $ flexmeasures add schedule --sensor-id 2 --optimization-context-id 3 \ - --from $(date '+%Y-%m-%d')T06:00+02:00 --duration PT12H \ + --from ${TOMORROW}T07:00+01:00 --duration PT12H \ --soc-at-start 50% --roundtrip-efficiency 90%