Commit a3e9d0fc3d9e0fe406666f99734d9475084e97d8
1 parent
eb5f7e79
Exists in
master
Fix home plot legend labels.
Also, add @jglorian because he totally deserves it.
Showing
5 changed files
with
32 additions
and
7 deletions
Show diff stats
content.yml
@@ -11,8 +11,11 @@ meta: | @@ -11,8 +11,11 @@ meta: | ||
11 | email: dbarret@irap.omp.eu | 11 | email: dbarret@irap.omp.eu |
12 | role: Principal Investigator | 12 | role: Principal Investigator |
13 | - name: Antoine Goutenoir | 13 | - name: Antoine Goutenoir |
14 | - email: agoutenoir@irap.omp.eu | 14 | + email: antoine@goutenoir.com |
15 | role: Software Ninja | 15 | role: Software Ninja |
16 | + - name: Jean-Michel Glorian | ||
17 | + email: Jean-Michel.Glorian@irap.omp.eu | ||
18 | + role: Benevolent Wizard | ||
16 | 19 | ||
17 | 20 | ||
18 | # Aka. Laws | 21 | # Aka. Laws |
flaskr/controllers/main_controller.py
@@ -45,10 +45,14 @@ def favicon(): # we want it served from the root, not from static/ | @@ -45,10 +45,14 @@ def favicon(): # we want it served from the root, not from static/ | ||
45 | @cache.cached(timeout=1000) | 45 | @cache.cached(timeout=1000) |
46 | def home(): | 46 | def home(): |
47 | models = get_emission_models() | 47 | models = get_emission_models() |
48 | + models_dict = {} | ||
49 | + for model in models: | ||
50 | + models_dict[model.slug] = model.__dict__ | ||
48 | return render_template( | 51 | return render_template( |
49 | 'home.html', | 52 | 'home.html', |
50 | - models=models, | 53 | + models=models_dict, |
51 | colors=[model.color for model in models], | 54 | colors=[model.color for model in models], |
55 | + labels=[model.name for model in models], | ||
52 | ) | 56 | ) |
53 | 57 | ||
54 | 58 | ||
@@ -229,8 +233,9 @@ def compute(): # process the queue of estimation requests | @@ -229,8 +233,9 @@ def compute(): # process the queue of estimation requests | ||
229 | 233 | ||
230 | # GRAB AND CONFIGURE THE EMISSION MODELS ################################## | 234 | # GRAB AND CONFIGURE THE EMISSION MODELS ################################## |
231 | 235 | ||
232 | - mdl_slugs = estimation.models_slugs.split("\n") | ||
233 | - emission_models = [m for m in get_emission_models() if m.slug in mdl_slugs] | 236 | + emission_models = estimation.get_models() |
237 | + # mdl_slugs = estimation.models_slugs.split("\n") | ||
238 | + # emission_models = [m for m in get_emission_models() if m.slug in mdl_slugs] | ||
234 | # print(emission_models) | 239 | # print(emission_models) |
235 | 240 | ||
236 | # PREPARE RESULT DICTIONARY THAT WILL BE STORED ########################### | 241 | # PREPARE RESULT DICTIONARY THAT WILL BE STORED ########################### |
flaskr/models.py
1 | from flask_admin.contrib.sqla import ModelView | 1 | from flask_admin.contrib.sqla import ModelView |
2 | 2 | ||
3 | -from flaskr.core import generate_unique_id | 3 | +from flaskr.core import generate_unique_id, models |
4 | from flask_sqlalchemy import SQLAlchemy | 4 | from flask_sqlalchemy import SQLAlchemy |
5 | from flask_login import UserMixin, AnonymousUserMixin | 5 | from flask_login import UserMixin, AnonymousUserMixin |
6 | from werkzeug.security import generate_password_hash, check_password_hash | 6 | from werkzeug.security import generate_password_hash, check_password_hash |
@@ -55,12 +55,24 @@ class Estimation(db.Model): | @@ -55,12 +55,24 @@ class Estimation(db.Model): | ||
55 | def has_failed(self): | 55 | def has_failed(self): |
56 | return self.status == StatusEnum.failure | 56 | return self.status == StatusEnum.failure |
57 | 57 | ||
58 | + _output_dict = None | ||
59 | + | ||
58 | def get_output_dict(self): | 60 | def get_output_dict(self): |
59 | - return yaml_load(self.output_yaml) | 61 | + if self._output_dict is None: |
62 | + self._output_dict = yaml_load(self.output_yaml) | ||
63 | + return self._output_dict | ||
60 | 64 | ||
61 | def has_many_to_many(self): | 65 | def has_many_to_many(self): |
62 | return 'cities' in self.get_output_dict() | 66 | return 'cities' in self.get_output_dict() |
63 | 67 | ||
68 | + _models = None | ||
69 | + | ||
70 | + def get_models(self): | ||
71 | + if self._models is None: | ||
72 | + mdl_slugs = self.models_slugs.split("\n") | ||
73 | + self._models = [m for m in models if m.slug in mdl_slugs] | ||
74 | + return self._models | ||
75 | + | ||
64 | 76 | ||
65 | class EstimationView(ModelView): | 77 | class EstimationView(ModelView): |
66 | # Show only name and email columns in list view | 78 | # Show only name and email columns in list view |
flaskr/templates/estimation.html
@@ -61,6 +61,10 @@ | @@ -61,6 +61,10 @@ | ||
61 | {% endif %} | 61 | {% endif %} |
62 | 62 | ||
63 | <div class="row"> | 63 | <div class="row"> |
64 | + Using | ||
65 | + {% for model in estimation.get_models() %} | ||
66 | + {{ model.name }}{{ ',' if not loop.last }} | ||
67 | + {% endfor %} | ||
64 | {# <h4>Total CO<sub>2</sub> footprint (in kilograms-equivalent) of each city</h4>#} | 68 | {# <h4>Total CO<sub>2</sub> footprint (in kilograms-equivalent) of each city</h4>#} |
65 | {# <div id="cities_footprints_d3viz" class="plot-container"></div>#} | 69 | {# <div id="cities_footprints_d3viz" class="plot-container"></div>#} |
66 | <hr> | 70 | <hr> |
flaskr/templates/home.html
@@ -82,7 +82,7 @@ var ceil_value_to_magnitude = function(value) { | @@ -82,7 +82,7 @@ var ceil_value_to_magnitude = function(value) { | ||
82 | }; | 82 | }; |
83 | 83 | ||
84 | 84 | ||
85 | -{#var models = {{ models | tojson }};#} | 85 | +var models = {{ models | tojson }}; |
86 | 86 | ||
87 | 87 | ||
88 | /** PLOTS **/ | 88 | /** PLOTS **/ |
@@ -206,6 +206,7 @@ jQuery(document).ready(function($){ | @@ -206,6 +206,7 @@ jQuery(document).ready(function($){ | ||
206 | {#.useClass(true)#} | 206 | {#.useClass(true)#} |
207 | {#.title("Legend")#} | 207 | {#.title("Legend")#} |
208 | {#.titleWidth(100)#} | 208 | {#.titleWidth(100)#} |
209 | + .labels({{ labels | tojson }}) | ||
209 | .scale(color); | 210 | .scale(color); |
210 | 211 | ||
211 | svg.select(".legendQuant") | 212 | svg.select(".legendQuant") |