diff --git a/doc/Makefile b/doc/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..d0c3cbf1020d5c292abdedf27627c6abe25e2293 --- /dev/null +++ b/doc/Makefile @@ -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 = source +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) diff --git a/doc/make.bat b/doc/make.bat new file mode 100644 index 0000000000000000000000000000000000000000..747ffb7b3033659bdd2d1e6eae41ecb00358a45e --- /dev/null +++ b/doc/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=source +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 diff --git a/doc/source/conf.py b/doc/source/conf.py new file mode 100644 index 0000000000000000000000000000000000000000..8f4132c597b54b1fb54b1d4957179cd23542b2f6 --- /dev/null +++ b/doc/source/conf.py @@ -0,0 +1,40 @@ +# Configuration file for the Sphinx documentation builder. +# +import sys, os + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +sys.path.append(os.path.abspath('_themes')) +sys.path.insert(0, os.path.abspath('../addons')) +sys.path.insert(0, os.path.abspath('../custom')) +sys.path.insert(0, os.path.abspath('../custom/acc')) +sys.path.insert(0, os.path.abspath('..')) +# 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 + +project = 'ACC Cdc' +copyright = '2022, Le Filament' +author = 'Le Filament' + +# -- General configuration --------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration + +extensions = [ + 'sphinx.ext.autodoc', 'sphinx.ext.intersphinx', + 'sphinx.ext.todo', 'sphinx.ext.viewcode' +] + +templates_path = ['_templates'] +exclude_patterns = [] + + + +# -- Options for HTML output ------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output + +html_theme = 'sphinx_rtd_theme' +html_static_path = ['_static'] diff --git a/doc/source/index.rst b/doc/source/index.rst new file mode 100644 index 0000000000000000000000000000000000000000..b039e190bacb58f447c2c494f77871827783b8d7 --- /dev/null +++ b/doc/source/index.rst @@ -0,0 +1,22 @@ +.. ACC Cdc documentation master file, created by + sphinx-quickstart on Wed Dec 7 18:37:40 2022. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to ACC Cdc's documentation! +=================================== + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + ./test.rst + + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/doc/source/test.rst b/doc/source/test.rst new file mode 100644 index 0000000000000000000000000000000000000000..ce338a44baac59ec998ba08e0df2ef247041cc3f --- /dev/null +++ b/doc/source/test.rst @@ -0,0 +1,4 @@ +CDC +=== + +.. autofunction:: odoo.addons.acc_cdc.models.acc_operation.get_power_tot diff --git a/models/acc_operation.py b/models/acc_operation.py index d09f567658c0f69ea9cf7bfd1e2ecca0bc0ea4ba..88f4213e776e113ddb81bb69440ae5dfbfb1f520 100644 --- a/models/acc_operation.py +++ b/models/acc_operation.py @@ -370,6 +370,82 @@ class AccOperation(models.Model): } return cdc_jour + def get_cdc_by_query_cons_new( + self, slot_type, date_start, date_end, prm_ids=None + ): + """ + Fonction permettant de récupérer les données pour la construction + des chart pour une ou des opérations données pour les consommateurs + :param slot_type: type de slot pour la query ('month' ou 'hour' ou 'year') + date_start: date début + date_end: date de fin + :return: un dictionnaire de données + (labels et data pour les charts à afficher) + """ + label_histo = [] + data_autocons_histo = [] + data_allocons_histo = [] + label = [] + data_autocons = [] + data_allocons = [] + data_cons = [] + data_prod = [] + data_surplus = [] + + query = """ + SELECT + A.date_slot AS date_slot, + (SUM( (CASE + WHEN comp_data_type = 'autocons' + THEN A.power ELSE 0 END) )/2) / 1000 as autocons, + (SUM( (CASE + WHEN comp_data_type = 'prod' + THEN A.power ELSE 0 END) )/2) / 1000 as prod, + ((SUM( (CASE WHEN comp_data_type = 'cons' THEN A.power ELSE 0 END)) - + SUM(CASE WHEN comp_data_type = 'autocons' THEN A.power ELSE 0 END) ) / 2) / 1000 as allocons, + (SUM( (CASE + WHEN comp_data_type = 'cons' THEN A.power + ELSE 0 END) )/2) / 1000 as cons + FROM acc_enedis_cdc A + JOIN acc_operation E ON E.id = A.acc_operation_id + WHERE A.acc_operation_id IS NOT NULL + AND A.acc_operation_id IN %s + AND A.acc_counter_id IN %s + AND A.date_slot >= %s + AND A.date_slot < %s + GROUP BY A.date_slot + ORDER BY date_slot ASC; + """ + query_params = ( + tuple(self.ids), + tuple(prm_ids.ids), + date_start, + date_end, + ) + self.env.cr.execute(query, query_params) + raw_data = self.env.cr.fetchall() + for row in raw_data: + # datetimestamp = int(round(row[0].timestamp())) + datetimestamp = int(time.mktime(row[0].timetuple())) * 1000 + data_autocons.append({"x": datetimestamp, "y": round(row[1], 2)}) + data_prod.append({"x": datetimestamp, "y": round(row[2], 2)}) + data_allocons.append({"x": datetimestamp, "y": round(row[3], 2)}) + data_cons.append({"x": datetimestamp, "y": round(row[4], 2)}) + label.append(datetimestamp) + + cdc_jour = { + "autocons": data_autocons, + "prod": data_prod, + "allocons": data_allocons, + "label": label, + "cons": data_cons, + "surplus": data_surplus, + # "autocons_histo": data_autocons_histo, + # "allocons_histo": data_allocons_histo, + # "label_histo": label_histo, + } + return cdc_jour + def get_cdc_by_query_prod(self, slot_type, date_start, date_end, prm_ids=None): """ Fonction permettant de récupérer les données pour la construction des chart @@ -696,6 +772,7 @@ class AccOperation(models.Model): "borderWidth": 1, "hoverRadius": 1, "radius": 0, + "fill": True, }, { "label": "Production solaire", @@ -705,39 +782,37 @@ class AccOperation(models.Model): "borderWidth": 2, "hoverRadius": 1, "radius": 0, - "hidden": "true" + "hidden": "true", + "fill": True, }, { "label": "Autoconso", "data": chart_data["autocons"], - "backgroundColor": "rgba(91, 154, 81, 0.4)", + "backgroundColor": "rgba(91, 154, 81, 1)", "borderColor": "rgba(91, 154, 81, 1)", "borderWidth": 2, "hoverRadius": 1, "radius": 0, + "fill": True, }, ], }, "options": { "scales": { - "xAxes": [ - { + "x": { "type": "time", "time": { - "unit": scale, + "unit": "hour", "displayFormats": {"quarter": "D MMM"}, }, "gridLines": {"offsetGridLines": offsetGridLines}, - } - ], - "yAxes": [ - { - "scaleLabel": { + }, + "y": { + "title": { "display": True, - "labelString": "kW", + "text": "kW", } - } - ], + }, }, "tooltips": { "backgroundColor": "#f5f5f5", @@ -776,14 +851,14 @@ class AccOperation(models.Model): """ result = {} - if scale_spe == "week": - data_autocons = chart_data["autocons_histo"] - data_allocons = chart_data["allocons_histo"] - data_label = chart_data["label_histo"] - else: - data_autocons = chart_data["autocons"] - data_allocons = chart_data["allocons"] - data_label = chart_data["label"] + # if scale_spe == "week": + # data_autocons = chart_data["autocons_histo"] + # data_allocons = chart_data["allocons_histo"] + # data_label = chart_data["label_histo"] + # else: + data_autocons = chart_data["autocons"] + data_allocons = chart_data["allocons"] + data_label = chart_data["label"] result["histo_chart_conso"] = { "type": "bar", "data": { @@ -814,34 +889,39 @@ class AccOperation(models.Model): "intersect": False, }, "scales": { - "xAxes": [ - { + "x": { "type": "time", "time": { - "unit": scale, - "displayFormats": {"quarter": "D MMM"}, + "unit": "day", + # "round": "day", + # "displayFormats": {"quarter": "D MMM"}, }, + # "ticks": { + # "source": "data", + # }, "stacked": True, "offset": True, "gridLines": {"offsetGridLines": True}, - } - ], - "yAxes": [ - { + }, + "y": { "stacked": True, "ticks": { "beginAtZero": True, }, - "scaleLabel": { + # "scaleLabel": { + # "display": True, + # "labelString": "kWh", + # }, + "title": { "display": True, - "labelString": "kWh", - }, - } - ], + "text": "kWh", + } + }, }, "tooltips": { "mode": "x", }, + "animation": False, }, } return result @@ -952,7 +1032,7 @@ class AccOperation(models.Model): }, "options": { "scales": { - "xAxes": [ + "x": { "type": "time", "time": { @@ -963,17 +1043,14 @@ class AccOperation(models.Model): # 'min': result.date_start, }, "gridLines": {"offsetGridLines": offsetGridLines}, - } - ], - "yAxes": [ - { + }, + "y":{ "stacked": True, "scaleLabel": { "display": True, "labelString": "kW", }, - } - ], + }, }, "tooltips": { "backgroundColor": "#f5f5f5", @@ -1103,8 +1180,7 @@ class AccOperation(models.Model): "intersect": False, }, "scales": { - "xAxes": [ - { + "x":{ "type": "time", "time": { "unit": scale, @@ -1113,10 +1189,8 @@ class AccOperation(models.Model): "stacked": True, "offset": True, "gridLines": {"offsetGridLines": True}, - } - ], - "yAxes": [ - { + }, + "y":{ "stacked": True, "ticks": { "beginAtZero": True, @@ -1126,8 +1200,7 @@ class AccOperation(models.Model): "display": True, "labelString": "kWh", }, - } - ], + }, }, "tooltips": { "mode": "x", @@ -1414,14 +1487,17 @@ class AccOperation(models.Model): acc_counter_ids = self.acc_injection_ids if type == "cons": - chart_data = self.get_cdc_by_query_cons( + # chart_data = self.get_cdc_by_query_cons( + # step_courbe, date_start, date_end, acc_counter_ids + # ) + chart_data = self.get_cdc_by_query_cons_new( step_courbe, date_start, date_end, acc_counter_ids ) - if scale == "week": - chart_data_histo = self.get_cdc_by_query_histo_cons( - "day", date_start, date_end, acc_counter_ids - ) - chart_data.update(chart_data_histo) + # if scale == "week": + # chart_data_histo = self.get_cdc_by_query_histo_cons( + # "day", date_start, date_end, acc_counter_ids + # ) + # chart_data.update(chart_data_histo) # Build the chart with data and options result_graph = self.build_graph_data_options_cons(