Skip to content

Commit

Permalink
Add Docs
Browse files Browse the repository at this point in the history
And added Forecast of Productions
  • Loading branch information
Antoine TAVANT committed Jun 23, 2024
1 parent 2756800 commit f20510c
Show file tree
Hide file tree
Showing 22 changed files with 358 additions and 30 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/page_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: documentation

on: [push, pull_request, workflow_dispatch]

permissions:
contents: write

jobs:
docs:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
- name: Install dependencies
run: |
sudo apt update
sudo apt install pandoc
sudo apt install hatch
- name: sphinx build
run: |
hatch run docs:build
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
# Upload entire repository
path: './docs/_build'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,4 @@ cython_debug/
notebooks/weather/forcasts/*.parquet
data/bronze/*/*.xls
data/bronze/*.xls
doc/_build
20 changes: 20 additions & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
61 changes: 61 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

import energy_forecast
project = 'Energetic Stress Production'
copyright = '2024, Antoine Tavant, Matthieu Colin'
author = 'Antoine Tavant, Matthieu Colin'
version = energy_forecast.version

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
'sphinx.ext.napoleon',
'sphinx.ext.autodoc',
'sphinx.ext.viewcode',
'sphinx.ext.todo',
'sphinx.ext.autodoc',
'sphinx.ext.mathjax',
'sphinx_design',
'nbsphinx',
]


templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

# define code executed for each file as if included in it
rst_prolog="""
"""

# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output


html_theme = "pydata_sphinx_theme"
html_theme_options = {
"gitlab_url": "https://gitlab.ecoco2.com/recherche/computation_toolbox",
"announcement": f"<p>Last version is v{version}</p>",
}
html_static_path = ['_static']
html_sidebars = {
"**": ["search-field.html", "sidebar-nav-bs.html", 'globaltoc.html',]
# "**": ["search-field.html", "sidebar-nav-bs.html"]
}
# If true, '()' will be appended to :func: etc. cross-reference text.
add_function_parentheses = False

html_title = f"{project} v{version} Manual"


# -- nbsphinx extension configuration ------------------------------------------
nbsphinx_execute = 'never' # never, always, or auto (only run if no output available)

# -- Extension configuration -------------------------------------------------
napoleon_use_rtype = False # move return type inline
21 changes: 21 additions & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.. Energetic Stress Production documentation master file, created by
sphinx-quickstart on Sun Jun 23 13:39:35 2024.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to Energetic Stress Production's documentation!
=======================================================

.. toctree::
:maxdepth: 2
:caption: Contents:


src/modules

Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
35 changes: 35 additions & 0 deletions doc/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
7 changes: 7 additions & 0 deletions doc/src/energy_forecast.consumption_forecast.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
energy\_forecast.consumption\_forecast module
=============================================

.. automodule:: energy_forecast.consumption_forecast
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions doc/src/energy_forecast.dashboard.dashboard.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
energy\_forecast.dashboard.dashboard module
===========================================

.. automodule:: energy_forecast.dashboard.dashboard
:members:
:undoc-members:
:show-inheritance:
18 changes: 18 additions & 0 deletions doc/src/energy_forecast.dashboard.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
energy\_forecast.dashboard package
==================================

Submodules
----------

.. toctree::
:maxdepth: 4

energy_forecast.dashboard.dashboard

Module contents
---------------

.. automodule:: energy_forecast.dashboard
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions doc/src/energy_forecast.energy.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
energy\_forecast.energy module
==============================

.. automodule:: energy_forecast.energy
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions doc/src/energy_forecast.meteo.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
energy\_forecast.meteo module
=============================

.. automodule:: energy_forecast.meteo
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions doc/src/energy_forecast.production_forecast.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
energy\_forecast.production\_forecast module
============================================

.. automodule:: energy_forecast.production_forecast
:members:
:undoc-members:
:show-inheritance:
29 changes: 29 additions & 0 deletions doc/src/energy_forecast.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
energy\_forecast package
========================

Subpackages
-----------

.. toctree::
:maxdepth: 4

energy_forecast.dashboard

Submodules
----------

.. toctree::
:maxdepth: 4

energy_forecast.consumption_forecast
energy_forecast.energy
energy_forecast.meteo
energy_forecast.production_forecast

Module contents
---------------

.. automodule:: energy_forecast
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions doc/src/modules.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
energy_forecast
===============

.. toctree::
:maxdepth: 4

energy_forecast
4 changes: 0 additions & 4 deletions notebooks/0_transform_data_RTE.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
"outputs": [],
"source": [
"import pandas as pd\n",
"import os\n",
"from pathlib import Path\n",
"import requests\n",
"import zipfile\n",
"from energy_forecast.energy import ECO2MixDownloader"
]
},
Expand Down
14 changes: 13 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Issues = "https://github.com/GreenForecast-Squad/energetic-stress-production/iss
Source = "https://github.com/GreenForecast-Squad/energetic-stress-production"

[tool.hatch.version]
path = "src/energy_forecast/__about__.py"
path = "src/energy_forecast/__init__.py"

[tool.hatch.envs.types]
extra-dependencies = [
Expand All @@ -53,6 +53,18 @@ extra-dependencies = [
[tool.hatch.envs.types.scripts]
check = "mypy --install-types --non-interactive {args:src/energy_forecast tests}"

[tool.hatch.envs.docs]
extra-dependencies = [
"sphinx",
"pydata-sphinx-theme",
"sphinx-gallery",
"sphinx_design",
"nbsphinx",
"taipy",
]
[tool.hatch.envs.docs.scripts]
build = "sphinx-build -b html doc/ doc/_build"

[tool.hatch.envs.serve]
extra-dependencies = [
"taipy",
Expand Down
1 change: 0 additions & 1 deletion src/energy_forecast/__about__.py

This file was deleted.

1 change: 1 addition & 0 deletions src/energy_forecast/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = "0.1.0"
35 changes: 16 additions & 19 deletions src/energy_forecast/consumption_forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,11 @@ class DayForecast(TypedDict):
class PredictionForecast(TypedDict):
weekly_forecasts: list[DayForecast]

class PredictionForecastAPI:
"""Access the RTE API to get the weekly forecast of consumption."""

class RTEAPROAuth2:
url_token = "https://digital.iservices.rte-france.com/token/oauth/"
url_api = "https://digital.iservices.rte-france.com/open_api/consumption/v1/weekly_forecasts"
def __init__(self, secret):
"""Initialize the API with the secret.
Parameters
----------
secret : str
The Base64 encoded secret to access the API.
See the documentation of the API to get the secret.

"""
def __init__(self, secret):
self.secret = secret
self.token = None
self.token_type = None
Expand All @@ -60,12 +50,22 @@ def get_token(self):
self.token_type = req.json()["token_type"]
self.token_expires_in = req.json()["expires_in"]
self.token_expires_at = pd.Timestamp("now") + pd.Timedelta(self.token_expires_in, unit="s")

self.headers: dict[str, str] = {
"Host": "digital.iservices.rte-france.com",
"Authorization": "Bearer {}".format(self.token),
}
def check_token(self):
"""Check if the token is still valid. If not, get a new one."""
if self.token_expires_at < pd.Timestamp("now"):
if self.token_expires_at - pd.Timestamp("now") < pd.Timedelta(10, unit="s"):
self.get_token()



class PredictionForecastAPI(RTEAPROAuth2):
"""Access the RTE API to get the weekly forecast of consumption."""

url_api = "https://digital.iservices.rte-france.com/open_api/consumption/v1/weekly_forecasts"

def get_raw_data(self, start_date, end_date=None, horizon="1w") -> PredictionForecast:
"""Retrieve the raw data from the API.
Expand All @@ -91,16 +91,13 @@ def get_raw_data(self, start_date, end_date=None, horizon="1w") -> PredictionFor
end_date = start_date + pd.Timedelta(horizon)
else:
end_date = pd.Timestamp(end_date)
headers = {
"Host": "digital.iservices.rte-france.com",
"Authorization": "Bearer {}".format(self.token),
}

params = {
"start_date": start_date.strftime("%Y-%m-%dT00:00:00+02:00"),
"end_date": end_date.strftime("%Y-%m-%dT00:00:00+02:00"),
}
req = requests.get(self.url_api,
headers=headers,
headers=self.headers,
params=params)
req.raise_for_status()
return req.json()
Expand Down
Loading

0 comments on commit f20510c

Please sign in to comment.