Skip to content

Commit

Permalink
Fix the copy button on tutorials and other documentation, so that onl…
Browse files Browse the repository at this point in the history
…y commands are copied and no output or comments.

Fix copybutton (#636)

* typo

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

* Fix bash console code blocks

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

* Python code block

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

* We've moved from Bitbucket to GitHub long ago

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

* Changelog entry

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

* Update sensor ids in the docker-compose documentation, too

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

* Update sensor ids and CLI option

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

---------

Signed-off-by: F.N. Claessen <felix@seita.nl>
  • Loading branch information
Flix6x committed Apr 13, 2023
1 parent 81ea6c3 commit dc99c5b
Show file tree
Hide file tree
Showing 11 changed files with 205 additions and 204 deletions.
1 change: 1 addition & 0 deletions documentation/changelog.rst
Expand Up @@ -20,6 +20,7 @@ New features
Bugfixes
-----------

* Fix copy button on tutorials and other documentation, so that only commands are copied and no output or comments [see `PR #636 <https://www.github.com/FlexMeasures/flexmeasures/pull/636>`_]

Infrastructure / Support
----------------------
Expand Down
6 changes: 3 additions & 3 deletions documentation/dev/api.rst
Expand Up @@ -14,7 +14,7 @@ This is a small guide for creating new versions of the API and its docs.
:depth: 2


Introducting a new API version
Introducing a new API version
---------------------

Larger changes to the API, other than fixes and refactoring, should be done by creating a new API version.
Expand Down Expand Up @@ -101,8 +101,8 @@ Test the entire api or just your new version:

.. code-block:: bash
pytest -k api
pytest -k v1_1
$ pytest -k api
$ pytest -k v1_1
UI Crud
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
70 changes: 35 additions & 35 deletions documentation/dev/docker-compose.rst
Expand Up @@ -19,7 +19,7 @@ Run this:

.. code-block:: bash
docker-compose build
$ docker-compose build
This pulls the images you need, and re-builds the FlexMeasures ones from code. If you change code, re-running this will re-build that image.

Expand All @@ -36,16 +36,16 @@ Start the stack like this:

.. code-block:: bash
docker-compose up
$ docker-compose up
.. warning:: This might fail if ports 5000 (Flask) or 6379 (Redis) are in use on your system. Stop these processes before you continue.

Check ``docker ps`` or ``docker-compose ps`` to see if your containers are running:


.. code-block:: console
.. code-block:: bash
± docker ps
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
beb9bf567303 flexmeasures_server "bash -c 'flexmeasur…" 44 seconds ago Up 38 seconds (health: starting) 0.0.0.0:5000->5000/tcp flexmeasures-server-1
e36cd54a7fd5 flexmeasures_worker "flexmeasures jobs r…" 44 seconds ago Up 5 seconds 5000/tcp flexmeasures-worker-1
Expand Down Expand Up @@ -86,62 +86,62 @@ The `flexmeasures-server` container already creates the toy account when it star

Let's go into the `flexmeasures-worker` container:

.. code-block:: console
.. code-block:: bash
docker exec -it flexmeasures-worker-1 bash
$ docker exec -it flexmeasures-worker-1 bash
There, we add the price data, as described in :ref:`tut_toy_schedule_price_data`. Create the prices and add them to the FlexMeasures DB in the container's bash session.

Next, we put a scheduling job in the worker's queue. This only works because we have the Redis container running ― the toy tutorial doesn't have it. The difference is that we're adding ``--as-job``:

.. code-block:: console
.. code-block:: bash
flexmeasures add schedule for-storage --sensor-id 2 --consumption-price-sensor 3 \
$ flexmeasures add schedule for-storage --sensor-id 1 --consumption-price-sensor 2 \
--start ${TOMORROW}T07:00+01:00 --duration PT12H --soc-at-start 50% \
--roundtrip-efficiency 90% --as-job
We should now see in the output of ``docker logs flexmeasures-worker-1`` something like the following:

.. code-block:: console
.. code-block:: bash
Running Scheduling Job d3e10f6d-31d2-46c6-8308-01ede48f8fdd: <Sensor 2: charging, unit: MW res.: 0:15:00>, from 2022-07-06 07:00:00+01:00 to 2022-07-06 19:00:00+01:00
So the job had been queued in Redis, was then picked up by the worker process, and the result should be in our SQL database container. Let's check!

We'll not go into the server container this time, but simply send a command:

.. code-block:: console
.. code-block:: bash
TOMORROW=$(date --date="next day" '+%Y-%m-%d')
docker exec -it flexmeasures-server-1 bash -c "flexmeasures show beliefs --sensor-id 2 --start ${TOMORROW}T07:00:00+01:00 --duration PT12H"
$ TOMORROW=$(date --date="next day" '+%Y-%m-%d')
$ docker exec -it flexmeasures-server-1 bash -c "flexmeasures show beliefs --sensor-id 1 --start ${TOMORROW}T07:00:00+01:00 --duration PT12H"
The charging/discharging schedule should be there:

.. code-block:: console
.. code-block:: bash
┌────────────────────────────────────────────────────────────┐
│ ▐ ▐▀▀▌ ▛▀▀│
│ ▞▌ ▞ ▐ ▌ │ 0.4MW
│ ▌▌ ▌ ▐ ▐ │
▗▘▌ ▌ ▐ ▐ │
│ ▐ ▐ ▗▘ ▝▖ ▐ │
▌ │ 0.2MW
▗▘ ▌ │
│ ▐ ▝▖
│▀▘───▀▀▀▀▀▀▀▀▀▀▀▀▀▀▌────▐─────▀▀▀▀▀▀▀▀─────▐▀▀▀▀▀▀▀▀▀─────│ 0MW
▗▘
▗▘ ▝▖ │ -0.2MW
▌ ▗▘
▌ ▞ ▌ ▐
▌ ▌ ▐ ▐ │ -0.4MW
▙▄▄▌ ▐▄▄▞
│ ▐ ▐▀▀▌ ▛▀▀│ 0.5MW
│ ▞▌ ▌ ▌ ▌ │
│ ▌▌ ▌ ▐ ▗▘ │
▌▌ ▌ ▐ ▐ │
│ ▐ ▐ ▐ │
▝▖ ▞ │
▌ │
│ ▐ ▝▖
│▀▘───▀▀▀▀─────▌────▀▀▀▀▀▀▀▀▀▌─────▐▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▘───│ 0.0MW
▗▘
▝▖
▌ ▗▘
▌ ▐
▝▖ ▌ ▌ ▞
▙▄▟ ▐▄▄▌ │ -0.5MW
└────────────────────────────────────────────────────────────┘
10 20 30 40
██ charging
10 20 30 40
██ discharging
Like in the original toy tutorial, we can also check in the server container's `web UI <http://localhost:5000/sensors/2/>`_ (username is "toy-user@flexmeasures.io", password is "toy-password"):
Like in the original toy tutorial, we can also check in the server container's `web UI <http://localhost:5000/sensors/1/>`_ (username is "toy-user@flexmeasures.io", password is "toy-password"):

.. image:: https://github.com/FlexMeasures/screenshots/raw/main/tut/toy-schedule/sensor-data-charging.png
:align: center
Expand All @@ -167,8 +167,8 @@ You can run tests in the flexmeasures docker container, using the database servi

After you've started the compose stack with ``docker-compose up``, run:

.. code-block:: console
.. code-block:: bash
docker exec -it -e SQLALCHEMY_TEST_DATABASE_URI="postgresql://fm-test-db-user:fm-test-db-pass@test-db:5432/fm-test-db" flexmeasures-server-1 pytest
$ docker exec -it -e SQLALCHEMY_TEST_DATABASE_URI="postgresql://fm-test-db-user:fm-test-db-pass@test-db:5432/fm-test-db" flexmeasures-server-1 pytest
This rounds up the dev experience offered by running FlexMeasures in Docker. Now you can develop FlexMeasures and also run your tests. If you develop plugins, you could extend the command being used, e.g. ``bash -c "cd /path/to/my/plugin && pytest"``.
52 changes: 26 additions & 26 deletions documentation/dev/introduction.rst
Expand Up @@ -31,9 +31,9 @@ Download FlexMeasures
^^^^^^^^^^^^^^^^^^^^^^^
Clone the `FlexMeasures repository <https://github.com/FlexMeasures/flexmeasures.git>`_ from GitHub.

.. code-block:: console
.. code-block:: bash
git clone https://github.com/FlexMeasures/flexmeasures.git
$ git clone https://github.com/FlexMeasures/flexmeasures.git
.. note:: Are you using Visual Studio Code? Then the code you just cloned also contains the editor configuration (part of) our team is using!

Expand All @@ -43,16 +43,16 @@ Dependencies

Go into the ``flexmeasures`` folder and install all dependencies including the ones needed for development:

.. code-block:: console
.. code-block:: bash
cd flexmeasures
make install-for-dev
$ cd flexmeasures
$ make install-for-dev
:ref:`Install the LP solver <install-lp-solver>`. On Unix the Cbc LP solver can be installed with:

.. code-block:: console
.. code-block:: bash
apt-get install coinor-cbc
$ apt-get install coinor-cbc
Configuration
Expand All @@ -72,26 +72,26 @@ Loading data

If you have a SQL Dump file, you can load that:

.. code-block:: console
.. code-block:: bash
psql -U {user_name} -h {host_name} -d {database_name} -f {file_path}
$ psql -U {user_name} -h {host_name} -d {database_name} -f {file_path}
Run locally
^^^^^^^^^^^^^^^^^^^^

Now, to start the web application, you can run:

.. code-block:: console
.. code-block:: bash
flexmeasures run
$ flexmeasures run
Or:

.. code-block:: console
.. code-block:: bash
python run-local.py
$ python run-local.py
And access the server at http://localhost:5000
Expand All @@ -112,27 +112,27 @@ Tests

You can run automated tests with:

.. code-block:: console
.. code-block:: bash
make test
$ make test
which behind the curtains installs dependencies and calls pytest.

A coverage report can be created like this:

.. code-block:: console
.. code-block:: bash
pytest --cov=flexmeasures --cov-config .coveragerc
$ pytest --cov=flexmeasures --cov-config .coveragerc
You can add --cov-report=html after which a htmlcov/index.html is generated.

It's also possible to use:

.. code-block:: console
.. code-block:: bash
python setup.py test
$ python setup.py test
Expand All @@ -159,10 +159,10 @@ We also run `mypy <http://mypy-lang.org/>`_ 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:: console
.. code-block:: bash
pip install pre-commit
pre-commit install
$ pip install pre-commit
$ pre-commit install
in your virtual environment.
Expand All @@ -182,10 +182,10 @@ A hint about using notebooks

If you edit notebooks, make sure results do not end up in git:

.. code-block:: console
.. code-block:: bash
conda install -c conda-forge nbstripout
nbstripout --install
$ conda install -c conda-forge nbstripout
$ nbstripout --install
(on Windows, maybe you need to look closer at https://github.com/kynan/nbstripout)
Expand All @@ -201,7 +201,7 @@ I added this to my ~/.bashrc, so I only need to type ``fm`` to get started and h
addssh(){
eval `ssh-agent -s`
ssh-add ~/.ssh/id_bitbucket
ssh-add ~/.ssh/id_github
}
fm(){
addssh
Expand Down

0 comments on commit dc99c5b

Please sign in to comment.