diff --git a/content.yml b/content.yml index eed0a42..10d5e5f 100644 --- a/content.yml +++ b/content.yml @@ -11,8 +11,11 @@ meta: email: dbarret@irap.omp.eu role: Principal Investigator - name: Antoine Goutenoir - email: agoutenoir@irap.omp.eu + email: antoine@goutenoir.com role: Software Ninja + - name: Jean-Michel Glorian + email: Jean-Michel.Glorian@irap.omp.eu + role: Benevolent Wizard # Aka. Laws diff --git a/flaskr/controllers/main_controller.py b/flaskr/controllers/main_controller.py index b8e7ce0..6e230f9 100644 --- a/flaskr/controllers/main_controller.py +++ b/flaskr/controllers/main_controller.py @@ -45,10 +45,14 @@ def favicon(): # we want it served from the root, not from static/ @cache.cached(timeout=1000) def home(): models = get_emission_models() + models_dict = {} + for model in models: + models_dict[model.slug] = model.__dict__ return render_template( 'home.html', - models=models, + models=models_dict, colors=[model.color for model in models], + labels=[model.name for model in models], ) @@ -229,8 +233,9 @@ def compute(): # process the queue of estimation requests # GRAB AND CONFIGURE THE EMISSION MODELS ################################## - mdl_slugs = estimation.models_slugs.split("\n") - emission_models = [m for m in get_emission_models() if m.slug in mdl_slugs] + emission_models = estimation.get_models() + # mdl_slugs = estimation.models_slugs.split("\n") + # emission_models = [m for m in get_emission_models() if m.slug in mdl_slugs] # print(emission_models) # PREPARE RESULT DICTIONARY THAT WILL BE STORED ########################### diff --git a/flaskr/models.py b/flaskr/models.py index 6a6ebb4..b142e1b 100755 --- a/flaskr/models.py +++ b/flaskr/models.py @@ -1,6 +1,6 @@ from flask_admin.contrib.sqla import ModelView -from flaskr.core import generate_unique_id +from flaskr.core import generate_unique_id, models from flask_sqlalchemy import SQLAlchemy from flask_login import UserMixin, AnonymousUserMixin from werkzeug.security import generate_password_hash, check_password_hash @@ -55,12 +55,24 @@ class Estimation(db.Model): def has_failed(self): return self.status == StatusEnum.failure + _output_dict = None + def get_output_dict(self): - return yaml_load(self.output_yaml) + if self._output_dict is None: + self._output_dict = yaml_load(self.output_yaml) + return self._output_dict def has_many_to_many(self): return 'cities' in self.get_output_dict() + _models = None + + def get_models(self): + if self._models is None: + mdl_slugs = self.models_slugs.split("\n") + self._models = [m for m in models if m.slug in mdl_slugs] + return self._models + class EstimationView(ModelView): # Show only name and email columns in list view diff --git a/flaskr/templates/estimation.html b/flaskr/templates/estimation.html index 1fe93a7..c40c162 100644 --- a/flaskr/templates/estimation.html +++ b/flaskr/templates/estimation.html @@ -61,6 +61,10 @@ {% endif %}
+ Using + {% for model in estimation.get_models() %} + {{ model.name }}{{ ',' if not loop.last }} + {% endfor %} {#

Total CO2 footprint (in kilograms-equivalent) of each city

#} {#
#}
diff --git a/flaskr/templates/home.html b/flaskr/templates/home.html index 224a1ff..ca159f7 100755 --- a/flaskr/templates/home.html +++ b/flaskr/templates/home.html @@ -82,7 +82,7 @@ var ceil_value_to_magnitude = function(value) { }; -{#var models = {{ models | tojson }};#} +var models = {{ models | tojson }}; /** PLOTS **/ @@ -206,6 +206,7 @@ jQuery(document).ready(function($){ {#.useClass(true)#} {#.title("Legend")#} {#.titleWidth(100)#} + .labels({{ labels | tojson }}) .scale(color); svg.select(".legendQuant") -- libgit2 0.21.2