Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
A
acc_cdc
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse du dépôt
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté GitLab
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Ce projet est archivé. Le dépôt et les autres ressources du projet sont en lecture seule.
Afficher davantage de fils d'Ariane
Le Filament
Opération Auto-Consommation Collective
acc_cdc
Validations
f448440a
Valider
f448440a
rédigé
28 avr. 2021
par
Juliana
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Add route and function cut
parent
3dc81392
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
3
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
3 fichiers modifiés
controllers/main.py
+6
-194
6 ajouts, 194 suppressions
controllers/main.py
models/enercoop_operation.py
+198
-150
198 ajouts, 150 suppressions
models/enercoop_operation.py
models/enercoop_operation_graph.py
+3
-12
3 ajouts, 12 suppressions
models/enercoop_operation_graph.py
avec
207 ajouts
et
356 suppressions
controllers/main.py
+
6
−
194
Voir le fichier @
f448440a
...
...
@@ -4,202 +4,14 @@ import json
from
odoo
import
http
from
odoo.http
import
request
from
odoo.http
import
Response
from
datetime
import
datetime
,
timedelta
from
pytz
import
timezone
class
Main
(
http
.
Controller
):
@http.route
(
"
/get_data
"
,
auth
=
'
none
'
,
type
=
'
http
'
,
method
=
[
'
GET
'
])
def
method_get
(
self
,
**
post
):
headers
=
{
'
Content-Type
'
:
'
application/json
'
}
# if post.get('type_cdc', ''):
# type_cdc = post.get('type_cdc', '')
@http.route
([
'
/get_data_conso
'
],
type
=
'
json
'
,
auth
=
"
user
"
,
website
=
True
)
def
get_conso
(
self
,
operation_id
,
scale
,
**
kw
):
values
=
operation_id
.
graph_view_conso
(
scale
)
if
post
.
get
(
'
operation_id
'
,
''
):
operation_id
=
post
.
get
(
'
operation_id
'
,
''
)
if
post
.
get
(
'
date_start
'
,
''
):
date_start
=
datetime
.
strptime
(
post
.
get
(
'
date_start
'
,
''
),
"
%Y-%m-%dT%H:%M:%S
"
)
if
post
.
get
(
'
date_end
'
,
''
):
date_end
=
datetime
.
strptime
(
post
.
get
(
'
date_end
'
,
''
),
"
%Y-%m-%dT%H:%M:%S
"
)
if
post
.
get
(
'
type_date
'
,
''
):
type_date
=
post
.
get
(
'
type_date
'
,
''
)
cdc_week_month
=
[]
data_autocons
=
[]
data_cons
=
[]
data_prod
=
[]
data_surplus
=
[]
# Data by year / month
if
type_date
==
"
year
"
:
cdc_ids
=
request
.
env
[
'
enercoop.enedis.cdc
'
].
sudo
().
read_group
(
[(
'
enercoop_operation_id
'
,
'
=
'
,
operation_id
),
(
'
date_slot
'
,
'
>=
'
,
date_start
),
(
'
date_slot
'
,
'
<
'
,
date_end
)],
[
'
power
'
,
'
enercoop_operation_id
'
,
'
date_slot
'
],
[
'
comp_data_type
'
,
'
date_slot:month
'
],
orderby
=
'
comp_data_type
'
,
lazy
=
False
)
for
cdc
in
cdc_ids
:
value_power
=
cdc
[
'
power
'
]
/
1000
/
2
value_hour
=
cdc
[
'
date_slot:month
'
]
data
=
{
'
x
'
:
value_hour
,
'
y
'
:
value_power
,
}
if
cdc
[
'
comp_data_type
'
]
==
'
autocons
'
:
data_autocons
.
append
(
data
)
if
cdc
[
'
comp_data_type
'
]
==
'
cons
'
:
data_cons
.
append
(
data
)
if
cdc
[
'
comp_data_type
'
]
==
'
prod
'
:
data_prod
.
append
(
data
)
if
cdc
[
'
comp_data_type
'
]
==
'
surplus
'
:
data_surplus
.
append
(
data
)
# Data by week,month / day
if
type_date
==
"
week
"
or
type_date
==
"
month
"
:
cdc_ids
=
request
.
env
[
'
enercoop.enedis.cdc
'
].
sudo
().
read_group
(
[(
'
enercoop_operation_id
'
,
'
=
'
,
operation_id
),
(
'
date_slot
'
,
'
>=
'
,
date_start
),
(
'
date_slot
'
,
'
<
'
,
date_end
)],
[
'
power
'
,
'
enercoop_operation_id
'
,
'
date_slot
'
],
[
'
comp_data_type
'
,
'
date_slot:day
'
],
orderby
=
'
comp_data_type
'
,
lazy
=
False
)
for
cdc
in
cdc_ids
:
value_power
=
cdc
[
'
power
'
]
/
1000
/
2
value_hour
=
cdc
[
'
date_slot:day
'
]
data
=
{
'
x
'
:
value_hour
,
'
y
'
:
value_power
,
}
if
cdc
[
'
comp_data_type
'
]
==
'
autocons
'
:
data_autocons
.
append
(
data
)
if
cdc
[
'
comp_data_type
'
]
==
'
cons
'
:
data_cons
.
append
(
data
)
if
cdc
[
'
comp_data_type
'
]
==
'
prod
'
:
data_prod
.
append
(
data
)
if
cdc
[
'
comp_data_type
'
]
==
'
surplus
'
:
data_surplus
.
append
(
data
)
cdc_jour
=
[]
# Data by day / hour
if
type_date
==
"
day
"
:
date_end
=
date_start
+
timedelta
(
days
=
1
)
cdc_ids
=
request
.
env
[
'
enercoop.enedis.cdc
'
].
sudo
().
read_group
(
[(
'
enercoop_operation_id
'
,
'
=
'
,
operation_id
),
(
'
date_slot
'
,
'
>=
'
,
date_start
),
(
'
date_slot
'
,
'
<
'
,
date_end
)],
[
'
power
'
,
'
enercoop_operation_id
'
,
'
date_slot
'
],
[
'
comp_data_type
'
,
'
date_slot:hour
'
],
orderby
=
'
comp_data_type
'
,
lazy
=
False
)
for
cdc
in
cdc_ids
:
value_power
=
cdc
[
'
power
'
]
value_hour
=
cdc
[
'
date_slot:hour
'
]
data
=
{
'
x
'
:
value_hour
,
'
y
'
:
value_power
,
}
if
cdc
[
'
comp_data_type
'
]
==
'
autocons
'
:
data_autocons
.
append
(
data
)
if
cdc
[
'
comp_data_type
'
]
==
'
cons
'
:
data_cons
.
append
(
data
)
if
cdc
[
'
comp_data_type
'
]
==
'
prod
'
:
data_prod
.
append
(
data
)
if
cdc
[
'
comp_data_type
'
]
==
'
surplus
'
:
data_surplus
.
append
(
data
)
bilan_cdc
=
request
.
env
[
'
enercoop.enedis.cdc
'
].
sudo
().
read_group
(
[(
'
enercoop_operation_id
'
,
'
=
'
,
operation_id
),
(
'
date_slot
'
,
'
>=
'
,
date_start
),
(
'
date_slot
'
,
'
<
'
,
date_end
)],
[
'
power
'
,
'
enercoop_operation_id
'
],
[
'
comp_data_type
'
],
orderby
=
'
comp_data_type
'
,
lazy
=
False
)
for
bilan
in
bilan_cdc
:
if
bilan
[
'
comp_data_type
'
]
==
'
autocons
'
:
power_autocons
=
bilan
[
'
power
'
]
/
1000
/
2
if
bilan
[
'
comp_data_type
'
]
==
'
cons
'
:
power_cons
=
bilan
[
'
power
'
]
/
1000
/
2
if
bilan
[
'
comp_data_type
'
]
==
'
surplus
'
:
power_surplus
=
bilan
[
'
power
'
]
/
1000
/
2
if
bilan
[
'
comp_data_type
'
]
==
'
prod
'
:
power_prod
=
bilan
[
'
power
'
]
/
1000
/
2
power_tot
=
power_autocons
+
power_cons
percent_autocons
=
power_autocons
*
100
/
power_tot
percent_cons
=
power_cons
*
100
/
power_tot
power_prod_tot
=
power_autocons
+
power_surplus
percent_autocons_prod
=
power_autocons
*
100
/
power_prod_tot
percent_surplus_prod
=
power_surplus
*
100
/
power_prod_tot
data_autocons
.
append
({
'
bilan_cons
'
:
{
'
power
'
:
power_autocons
,
'
percent
'
:
percent_autocons
},
'
bilan_prod
'
:
{
'
power
'
:
power_autocons
,
'
percent
'
:
percent_autocons_prod
},
})
data_cons
.
append
({
'
bilan_cons
'
:
{
'
power
'
:
power_cons
,
'
percent
'
:
percent_cons
}
})
data_surplus
.
append
({
'
bilan_prod
'
:
{
'
power
'
:
power_surplus
,
'
percent
'
:
percent_surplus_prod
}
})
if
type_date
==
"
day
"
:
cdc_jour
.
append
({
'
type
'
:
'
autocons
'
,
'
data
'
:
data_autocons
,
})
cdc_jour
.
append
({
'
type
'
:
'
cons
'
,
'
data
'
:
data_cons
})
cdc_jour
.
append
({
'
type
'
:
'
prod
'
,
'
data
'
:
data_prod
})
cdc_jour
.
append
({
'
type
'
:
'
surplus
'
,
'
data
'
:
data_surplus
})
if
type_date
==
"
week
"
or
type_date
==
"
month
"
:
cdc_week_month
.
append
({
'
type
'
:
'
autocons
'
,
'
data
'
:
data_autocons
,
})
cdc_week_month
.
append
({
'
type
'
:
'
cons
'
,
'
data
'
:
data_cons
})
cdc_week_month
.
append
({
'
type
'
:
'
prod
'
,
'
data
'
:
data_prod
})
cdc_week_month
.
append
({
'
type
'
:
'
surplus
'
,
'
data
'
:
data_surplus
})
print
(
"
---- TEST ------
"
)
return
True
\ No newline at end of file
@http.route
([
'
/get_data_prod
'
],
type
=
'
json
'
,
auth
=
"
user
"
,
website
=
True
)
def
get_conso
(
self
,
operation_id
,
scale
,
**
kw
):
values
=
operation_id
.
graph_view_prod
(
scale
)
\ No newline at end of file
Ce diff est replié.
Cliquez pour l'agrandir.
models/enercoop_operation.py
+
198
−
150
Voir le fichier @
f448440a
...
...
@@ -32,6 +32,47 @@ class EnercoopOperation(models.Model):
# ------------------------------------------------------
# CRUD methods (ORM overrides)
# ------------------------------------------------------
@api.model
def
graph_view
(
self
,
domain
,
scale
):
# Function call when load Qweb views
result_graph
=
{}
# Get the operations depending to the domain
operation_ids
=
self
.
env
[
'
enercoop.operation
'
].
search
(
domain
)
if
operation_ids
:
# Get date start and date end depending on type of scale
date_start
,
date_end
=
operation_ids
.
get_last_day
(
scale
)
# Get the data to display in chart
chart_data
=
operation_ids
.
get_cdc
(
scale
,
date_start
,
date_end
)
# Build the chart depending on data calculated
result_graph
=
operation_ids
.
chart_data_cons
(
chart_data
)
result_graph_prod
=
operation_ids
.
chart_data_prod
(
chart_data
)
result_graph
.
update
(
result_graph_prod
)
return
result_graph
# ------------------------------------------------------
# Actions
# ------------------------------------------------------
def
action_view_courbes
(
self
):
self
.
ensure_one
()
action
=
self
.
env
[
"
ir.actions.actions
"
].
_for_xml_id
(
"
enercoop_cdc.enercoop_operation_action_client_courbes
"
)
action
[
'
params
'
]
=
{
'
operation_ids
'
:
self
.
ids
,
}
action
[
'
context
'
]
=
{
'
active_id
'
:
self
.
id
,
'
active_ids
'
:
self
.
ids
,
'
search_default_name
'
:
self
.
name
,
}
return
action
# ------------------------------------------------------
# Business methods
# ------------------------------------------------------
def
get_last_day
(
self
,
scale
):
# Get last date slot recorded
last_record
=
self
.
env
[
'
enercoop.enedis.cdc
'
].
search
([
...
...
@@ -55,27 +96,10 @@ class EnercoopOperation(models.Model):
return
date_start
,
date_end
@api.model
def
graph_view
(
self
,
domain
,
scale
):
# Création des variables
# date_start = datetime.strptime('2021-03-09T00:00:00', "%Y-%m-%dT%H:%M:%S")
def
chart_data_cons
(
self
,
chart_data
):
# Creation chart
result
=
{}
operation_ids
=
self
.
env
[
'
enercoop.operation
'
].
search
(
domain
)
# Get last date slot recorded
if
operation_ids
:
date_start
,
date_end
=
operation_ids
.
get_last_day
(
scale
)
# last_record = self.env['enercoop.enedis.cdc'].search([
# ('enercoop_operation_id', '=', operation_ids.ids),
# ], limit=1, order='date_slot DESC')
# date_end = last_record.date_slot
chart_data
=
operation_ids
.
get_cdc
(
scale
,
date_start
,
date_end
)
# Création des graphes
result
=
{
'
line_chart_conso
'
:
{
result
[
'
line_chart_conso
'
]
=
{
'
type
'
:
'
line
'
,
'
data
'
:
{
'
labels
'
:
chart_data
[
'
label
'
],
...
...
@@ -100,8 +124,8 @@ class EnercoopOperation(models.Model):
},
],
},
},
'
donuts_chart_conso
'
:
{
}
result
[
'
donuts_chart_conso
'
]
=
{
'
type
'
:
'
doughnut
'
,
'
data
'
:
{
'
labels
'
:
chart_data
[
'
label_doughnut
'
],
...
...
@@ -115,8 +139,8 @@ class EnercoopOperation(models.Model):
'
borderWidth
'
:
1
}],
},
}
,
'
histo_chart_conso
'
:
{
}
result
[
'
histo_chart_conso
'
]
=
{
'
type
'
:
'
bar
'
,
'
data
'
:
{
'
labels
'
:
chart_data
[
'
label
'
],
...
...
@@ -134,8 +158,13 @@ class EnercoopOperation(models.Model):
'
borderColor
'
:
'
rgba(79, 129, 189, 1)
'
,
}]
}
},
'
line_chart_prod
'
:
{
}
return
result
def
chart_data_prod
(
self
,
chart_data
):
# Creation chart
result
=
{}
result
[
'
line_chart_prod
'
]
=
{
'
type
'
:
'
line
'
,
'
data
'
:
{
'
labels
'
:
chart_data
[
'
label
'
],
...
...
@@ -154,8 +183,8 @@ class EnercoopOperation(models.Model):
},
],
},
}
,
'
donuts_chart_prod
'
:
{
}
result
[
'
donuts_chart_prod
'
]
=
{
'
type
'
:
'
doughnut
'
,
'
data
'
:
{
'
labels
'
:
chart_data
[
'
label_doughnut_prod
'
],
...
...
@@ -169,8 +198,8 @@ class EnercoopOperation(models.Model):
'
borderWidth
'
:
1
}],
},
}
,
'
histo_chart_prod
'
:
{
}
result
[
'
histo_chart_prod
'
]
=
{
'
type
'
:
'
bar
'
,
'
data
'
:
{
'
labels
'
:
chart_data
[
'
label
'
],
...
...
@@ -188,39 +217,19 @@ class EnercoopOperation(models.Model):
'
borderColor
'
:
'
rgba(192, 80, 77, 1)
'
,
}]
}
},
}
return
result
# ------------------------------------------------------
# Actions
# ------------------------------------------------------
def
action_view_courbes
(
self
):
self
.
ensure_one
()
action
=
self
.
env
[
"
ir.actions.actions
"
].
_for_xml_id
(
"
enercoop_cdc.enercoop_operation_action_client_courbes
"
)
action
[
'
params
'
]
=
{
'
operation_ids
'
:
self
.
ids
,
}
action
[
'
context
'
]
=
{
'
active_id
'
:
self
.
id
,
'
active_ids
'
:
self
.
ids
,
'
search_default_name
'
:
self
.
name
,
}
return
action
# ------------------------------------------------------
# Business methods
# ------------------------------------------------------
def
get_cdc
(
self
,
type
,
date_start
,
date_end
):
cdc_jour
=
[]
# for operation in self:
label_line_cons
=
[]
data_autocons
=
[]
data_cons
=
[]
data_prod
=
[]
data_surplus
=
[]
# Depending on type scale, define the date slot type
# Data by day / hour for type = day
# Data by week / day for type = week
# Data by month / day for type = month
...
...
@@ -232,6 +241,7 @@ class EnercoopOperation(models.Model):
else
:
type_date
=
'
date_slot:day
'
# Get all data group by curves type and date
cdc_ids
=
self
.
env
[
'
enercoop.enedis.cdc
'
].
sudo
().
read_group
(
[(
'
enercoop_operation_id
'
,
'
=
'
,
self
.
ids
),
(
'
date_slot
'
,
'
>=
'
,
date_start
),
...
...
@@ -239,6 +249,7 @@ class EnercoopOperation(models.Model):
[
'
power
'
,
'
enercoop_operation_id
'
,
'
date_slot
'
],
[
'
comp_data_type
'
,
type_date
],
orderby
=
'
comp_data_type, date_slot ASC
'
,
lazy
=
False
)
# Get the date for the abscissa axis
cdc_date_ids
=
self
.
env
[
'
enercoop.enedis.cdc
'
].
sudo
().
read_group
(
[(
'
enercoop_operation_id
'
,
'
=
'
,
self
.
ids
),
(
'
date_slot
'
,
'
>=
'
,
date_start
),
...
...
@@ -246,10 +257,12 @@ class EnercoopOperation(models.Model):
[
'
enercoop_operation_id
'
,
'
date_slot
'
],
[
type_date
],
orderby
=
'
date_slot ASC
'
,
lazy
=
False
)
# Build the abscissa axis with the right format date
for
cdc
in
cdc_date_ids
:
value_hour
=
cdc
[
type_date
]
label_line_cons
.
append
(
value_hour
)
# Build the ordinate axis for each data type (autoconso/conso/prod/surplus)
for
cdc
in
cdc_ids
:
if
type
==
'
day
'
:
value_power
=
round
((
cdc
[
'
power
'
]
/
2
),
2
)
...
...
@@ -265,6 +278,7 @@ class EnercoopOperation(models.Model):
if
cdc
[
'
comp_data_type
'
]
==
'
surplus
'
:
data_surplus
.
append
(
value_power
)
# Get the data to build the chart Bilan
bilan_cdc
=
self
.
env
[
'
enercoop.enedis.cdc
'
].
sudo
().
read_group
(
[(
'
enercoop_operation_id
'
,
'
=
'
,
self
.
ids
),
(
'
date_slot
'
,
'
>=
'
,
date_start
),
...
...
@@ -272,6 +286,7 @@ class EnercoopOperation(models.Model):
[
'
power
'
,
'
enercoop_operation_id
'
],
[
'
comp_data_type
'
],
orderby
=
'
comp_data_type
'
,
lazy
=
False
)
# Build the ordinate axis for each data type (autoconso/conso/prod/surplus)
for
bilan
in
bilan_cdc
:
if
bilan
[
'
comp_data_type
'
]
==
'
autocons
'
:
power_autocons
=
bilan
[
'
power
'
]
/
1000
/
2
...
...
@@ -312,3 +327,36 @@ class EnercoopOperation(models.Model):
}
return
cdc_jour
# ------------------------------------------------------
# Functions to manage route
# ------------------------------------------------------
def
graph_view_conso
(
self
,
scale
):
# Function call when load Qweb views
result_graph
=
{}
# Get date start and date end depending on type of scale
date_start
,
date_end
=
self
.
get_last_day
(
scale
)
# Get the data to display in chart
chart_data
=
self
.
get_cdc
(
scale
,
date_start
,
date_end
)
# Build the chart depending on data calculated
result_graph
=
self
.
chart_data_cons
(
chart_data
)
return
result_graph
def
graph_view_prod
(
self
,
scale
):
# Function call when load Qweb views
result_graph
=
{}
# Get date start and date end depending on type of scale
date_start
,
date_end
=
self
.
get_last_day
(
scale
)
# Get the data to display in chart
chart_data
=
self
.
get_cdc
(
scale
,
date_start
,
date_end
)
# Build the chart depending on data calculated
result_graph
=
self
.
chart_data_prod
(
chart_data
)
return
result_graph
\ No newline at end of file
Ce diff est replié.
Cliquez pour l'agrandir.
models/enercoop_operation_graph.py
+
3
−
12
Voir le fichier @
f448440a
...
...
@@ -13,6 +13,8 @@ class EnercoopOperation(models.Model):
def
_qweb_prepare_qcontext
(
self
,
view_id
,
domain
):
values
=
super
().
_qweb_prepare_qcontext
(
view_id
,
domain
)
operations
=
self
.
search
(
domain
)
# Prepare Values to display in qweb view
values
.
update
(
operations
.
_plan_prepare_values
())
return
values
...
...
@@ -44,14 +46,3 @@ class EnercoopOperation(models.Model):
values
[
'
data_values
'
]
=
data_values
return
values
\ No newline at end of file
def
plan_prepare_values
(
self
):
values
=
{
'
operations
'
:
self
,
}
date_start
=
datetime
.
strptime
(
'
2021-03-09T17:00:00
'
,
"
%Y-%m-%dT%H:%M:%S
"
)
conso_by_day
=
self
.
get_cdc_conso_day
(
date_start
)
values
[
'
conso_by_day
'
]
=
conso_by_day
return
values
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter