Commit a3e9d0fc3d9e0fe406666f99734d9475084e97d8

Authored by Antoine Goutenoir
1 parent eb5f7e79
Exists in master

Fix home plot legend labels.

Also, add @jglorian because he totally deserves it.
content.yml
... ... @@ -11,8 +11,11 @@ meta:
11 11 email: dbarret@irap.omp.eu
12 12 role: Principal Investigator
13 13 - name: Antoine Goutenoir
14   - email: agoutenoir@irap.omp.eu
  14 + email: antoine@goutenoir.com
15 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 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 45 @cache.cached(timeout=1000)
46 46 def home():
47 47 models = get_emission_models()
  48 + models_dict = {}
  49 + for model in models:
  50 + models_dict[model.slug] = model.__dict__
48 51 return render_template(
49 52 'home.html',
50   - models=models,
  53 + models=models_dict,
51 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 233  
230 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 239 # print(emission_models)
235 240  
236 241 # PREPARE RESULT DICTIONARY THAT WILL BE STORED ###########################
... ...
flaskr/models.py
1 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 4 from flask_sqlalchemy import SQLAlchemy
5 5 from flask_login import UserMixin, AnonymousUserMixin
6 6 from werkzeug.security import generate_password_hash, check_password_hash
... ... @@ -55,12 +55,24 @@ class Estimation(db.Model):
55 55 def has_failed(self):
56 56 return self.status == StatusEnum.failure
57 57  
  58 + _output_dict = None
  59 +
58 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 65 def has_many_to_many(self):
62 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 77 class EstimationView(ModelView):
66 78 # Show only name and email columns in list view
... ...
flaskr/templates/estimation.html
... ... @@ -61,6 +61,10 @@
61 61 {% endif %}
62 62  
63 63 <div class="row">
  64 + Using
  65 + {% for model in estimation.get_models() %}
  66 + {{ model.name }}{{ ',' if not loop.last }}
  67 + {% endfor %}
64 68 {# <h4>Total CO<sub>2</sub> footprint (in kilograms-equivalent) of each city</h4>#}
65 69 {# <div id="cities_footprints_d3viz" class="plot-container"></div>#}
66 70 <hr>
... ...
flaskr/templates/home.html
... ... @@ -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 88 /** PLOTS **/
... ... @@ -206,6 +206,7 @@ jQuery(document).ready(function($){
206 206 {#.useClass(true)#}
207 207 {#.title("Legend")#}
208 208 {#.titleWidth(100)#}
  209 + .labels({{ labels | tojson }})
209 210 .scale(color);
210 211  
211 212 svg.select(".legendQuant")
... ...