From 31a42c9bc5746993a706a21e363610c13af8397f Mon Sep 17 00:00:00 2001 From: thienan Date: Thu, 17 Jun 2021 10:33:04 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20graphes=20pourcentage=20d=C3=A9lais?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 1 + mondumas/models/stats.py | 10 ++++ mondumas/routes.py | 1 + mondumas/templates/stats/ca_clients.pt | 2 +- mondumas/templates/stats/ca_groupes.pt | 2 +- .../templates/stats/delais_pourcentage.pt | 55 +++++++++++++++++++ mondumas/templates/stats/stats.pt | 5 ++ mondumas/views/stats.py | 54 +++++++++++++++++- 8 files changed, 127 insertions(+), 3 deletions(-) create mode 100644 mondumas/templates/stats/delais_pourcentage.pt diff --git a/.vscode/settings.json b/.vscode/settings.json index 4b1a30b..4009d4b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,4 @@ { "html.validate.scripts": false + "editor.minimap.enabled": false } \ No newline at end of file diff --git a/mondumas/models/stats.py b/mondumas/models/stats.py index 7a61617..29bacc0 100644 --- a/mondumas/models/stats.py +++ b/mondumas/models/stats.py @@ -119,3 +119,13 @@ def get_ca_clients_3y(request, societe, datedeb): WHERE societe=:societe GROUP BY typecli;""" results = request.dbsession.execute(query, {'societe': societe, 'date_n': date3.strftime("%Y"), 'date_n-1': date2.strftime("%Y"), 'date_n': datedeb.strftime("%Y")}) return results.fetchall() + +def get_delais_pourcent(request, societe, groupe, datedeb): + + query = """SELECT + SUM(IF (delai_contact <= 2, 1, 0)) AS delais_inf, + SUM(IF (delai_contact > 2, 1, 0)) AS delais_sup + FROM bddevfac.dem_devis + WHERE societe = :societe AND GROUPE = :groupe AND date >= :datedeb;""" + results = request.dbsession.execute(query, {'societe': societe, 'groupe': groupe, 'datedeb': datedeb.strftime("%Y-%m")}) + return results.fetchall() diff --git a/mondumas/routes.py b/mondumas/routes.py index df2dccc..ba0cfff 100644 --- a/mondumas/routes.py +++ b/mondumas/routes.py @@ -79,6 +79,7 @@ def includeme(config): config.add_route('stats_delais', '/stats_delais/{societe}') config.add_route('ca_groupes', '/ca_groupes/{societe}') config.add_route('ca_clients', '/ca_clients/{societe}') + config.add_route('delais_pourcentage', '/delais_pourcentage/{societe}') # utils config.add_route('batch_nuit', '/batch_nuit/{param}') diff --git a/mondumas/templates/stats/ca_clients.pt b/mondumas/templates/stats/ca_clients.pt index f0ec189..102db24 100644 --- a/mondumas/templates/stats/ca_clients.pt +++ b/mondumas/templates/stats/ca_clients.pt @@ -71,7 +71,7 @@ title: '${title3}', }; - var chart_ca_12m = new google.visualization.SteppedAreaChart(document.getElementById('chart_ca_12m')); + var chart_ca_12m = new google.visualization.ColumnChart(document.getElementById('chart_ca_12m')); chart_ca_12m.draw(data_ca_12m, options_ca_12m); var chart_ca_3y_1 = new google.visualization.PieChart(document.getElementById('chart_ca_3y_1')); diff --git a/mondumas/templates/stats/ca_groupes.pt b/mondumas/templates/stats/ca_groupes.pt index 62ced17..93cf7f7 100644 --- a/mondumas/templates/stats/ca_groupes.pt +++ b/mondumas/templates/stats/ca_groupes.pt @@ -71,7 +71,7 @@ title: '${title3}', }; - var chart_ca_12m = new google.visualization.SteppedAreaChart(document.getElementById('chart_ca_12m')); + var chart_ca_12m = new google.visualization.ColumnChart(document.getElementById('chart_ca_12m')); chart_ca_12m.draw(data_ca_12m, options_ca_12m); var chart_ca_3y_1 = new google.visualization.PieChart(document.getElementById('chart_ca_3y_1')); diff --git a/mondumas/templates/stats/delais_pourcentage.pt b/mondumas/templates/stats/delais_pourcentage.pt new file mode 100644 index 0000000..5a1537e --- /dev/null +++ b/mondumas/templates/stats/delais_pourcentage.pt @@ -0,0 +1,55 @@ + +
+ +
+
+
+
+ +
+ +
+ +
+ +
+
+
+
+ +
+ +
+
+ + + + + +
+
+ + diff --git a/mondumas/templates/stats/stats.pt b/mondumas/templates/stats/stats.pt index afe2a67..9b53782 100644 --- a/mondumas/templates/stats/stats.pt +++ b/mondumas/templates/stats/stats.pt @@ -8,6 +8,11 @@

DELAIS MOYENS

+
+ + +

DELAIS POURCENTAGE

+

STATS DOSSIERS

diff --git a/mondumas/views/stats.py b/mondumas/views/stats.py index dc81cb1..2da5e96 100644 --- a/mondumas/views/stats.py +++ b/mondumas/views/stats.py @@ -298,7 +298,7 @@ def ca_clients(request): chart_ca_3y_3.append(d3) return { - 'page_title': "CA par groupe", + 'page_title': "CA par clients", 'url': url, 'chart_ca_12m': json.dumps(chart_ca_12m), 'chart_ca_3y_1': json.dumps(chart_ca_3y_1), @@ -312,3 +312,55 @@ def ca_clients(request): 'societe': societe, } +@view_config(route_name='delais_pourcentage', renderer='../templates/stats/delais_pourcentage.pt', permission='view') +def delais_pourcentage(request): + + societe = request.matchdict['societe'] + url = request.route_url('delais_pourcentage', societe = societe) + + datefin = date.today() + # debut = aujourd'hui - 11 mois + datedeb = datefin + relativedelta(months=-11) + + societes = ['PE','ME','PL'] + # si societe a été changé par le user + if 'societe' in request.params: + societe = request.params["societe"] + + # lire les groupes + groupes = get_stats_delai_groupe(request, societe, datedeb, datefin) + + # mémoriser le 1er de la liste + groupe = groupes[0].group2 + + # si groupe a été changé par le user + if 'groupe' in request.params: + groupe = request.params["groupe"] + + # lire les CA par mois + items = get_delais_pourcent(request, societe, groupe, datedeb) + chart_delais_p = [] + + # titre des colonnes + chart_delais_p.append(('Catégorie', 'Delais')) + title = 'POURCENTAGE DELAIS' + for item in items: + # construire la liste pour donut cible + #tooltipA = item.date + ' \nCA: '+str(item.A_ca) + ' €\nDossiers: '+str(round(item.A_nb)) + # ('+str(item.population)+')/n' + d = ('1er contact inférieur à 2j', round(item.delais_inf)) + chart_delais_p.append(d) + d = ('1er contact supérieur à 2j', round(item.delais_sup)) + chart_delais_p.append(d) + + return { + 'page_title': "Pourcentage de délais inférieurs à 2 jours", + 'url': url, + 'chart_delais_p': json.dumps(chart_delais_p), + 'title': title, + 'societes': societes, + 'societe': societe, + 'groupes': groupes, + 'groupe': groupe, + } +