diff --git a/README.md b/README.md index 16cec38..b0cf382 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ # Travel Carbon Footprint Calculator +- https://travel-footprint-calculator.apps.goutenoir.com (private demo) +- http://travel-footprint-calculator.irap.omp.eu (official, for later) + + ## Overview - Content is in `content.yml`. diff --git a/content.yml b/content.yml index 79d9c02..e8d528e 100644 --- a/content.yml +++ b/content.yml @@ -599,6 +599,22 @@ estimate: It may take from a few seconds up to a few minutes, depending on the amount of locations you provided. + help: + first_name: Fill these to say hello. + last_name: We will never share your data with anyone. + origin_addresses: | + Use en_US city and country names, without diacritics. +   + The comma matters. +
+ This is either a home city and a country + or the cities and countries of the participants to the conference, meeting… + destination_addresses: | + This is either the cities and countries to travel to + or the host city and country of the conference, meeting… +
+ Please provide multiple cities and countries to compute the location + of the minimum emission. # Labels accept HTML, but not markdown # Descriptions accept neither, since we use the HTML title attribute @@ -677,6 +693,23 @@ estimation: Sorry about that. Please find the error message below.
Thank you for using our service. + lolliplot: + one_to_one: | + The carbon dioxide equivalent emission is provided for each city of destination. + Identical trips (i.e. identical destinations) are summed + and the cumulative distance is provided. + one_to_many: | + The carbon dioxide equivalent emission is provided for each city of destination. + Identical trips (i.e. identical destinations) are summed + and the cumulative distance is provided. + many_to_one: | + The carbon dioxide equivalent emission is provided for each city of origin. + Identical trips (i.e. identical origins) are summed and the cumulative distance is provided. + many_to_many: | + The carbon dioxide equivalent emission is summed + over all cities of origin and provided for each city of destination. + The cumulative distance to each city of destination is provided. + Duplicates in the destinations are removed. footer: credits: | diff --git a/flaskr/controllers/main_controller.py b/flaskr/controllers/main_controller.py index 734158d..92b13c6 100644 --- a/flaskr/controllers/main_controller.py +++ b/flaskr/controllers/main_controller.py @@ -9,7 +9,7 @@ from os.path import join from flaskr.extensions import cache, basic_auth from flaskr.forms import LoginForm, EstimateForm -from flaskr.models import db, User, Estimation, StatusEnum +from flaskr.models import db, User, Estimation, StatusEnum, ScenarioEnum from flaskr.geocoder import CachedGeocoder from flaskr.core import generate_unique_id, get_emission_models @@ -366,6 +366,7 @@ def compute(): # process the queue of estimation requests # for each of the Emission Models, and present a mean of all Models. # if 1 == len(origins): + estimation.scenario = ScenarioEnum.one_to_many results = compute_one_to_many( _origin=origins[0], _destinations=destinations, @@ -377,6 +378,7 @@ def compute(): # process the queue of estimation requests # Same as A for now. # elif 1 == len(destinations): + estimation.scenario = ScenarioEnum.many_to_one results = compute_one_to_many( _origin=destinations[0], _destinations=origins, @@ -388,6 +390,7 @@ def compute(): # process the queue of estimation requests # Run Scenario A for each Destination, and expose optimum Destination. # else: + estimation.scenario = ScenarioEnum.many_to_many unique_city_keys = [] result_cities = [] for destination in destinations: diff --git a/flaskr/models.py b/flaskr/models.py index b142e1b..e245b26 100755 --- a/flaskr/models.py +++ b/flaskr/models.py @@ -24,6 +24,13 @@ class StatusEnum(enum.Enum): failure = 'failure' +class ScenarioEnum(enum.Enum): + one_to_one = 'one_to_one' + many_to_one = 'many_to_one' + one_to_many = 'one_to_many' + many_to_many = 'many_to_many' + + class Estimation(db.Model): id = db.Column(db.Integer(), primary_key=True) public_id = db.Column( @@ -42,12 +49,14 @@ class Estimation(db.Model): origin_addresses = db.Column(db.UnicodeText()) destination_addresses = db.Column(db.UnicodeText()) - # One slug per line (or blankchar?) + # One slug per line (or blank char?) models_slugs = db.Column(db.UnicodeText()) # Deprecated, we detect this scenario from the amount of locations. compute_optimal_destination = db.Column(db.Boolean()) + # Outputs + scenario = db.Column(db.Enum(ScenarioEnum), default=ScenarioEnum.many_to_many) output_yaml = db.Column(db.UnicodeText()) warnings = db.Column(db.UnicodeText()) errors = db.Column(db.UnicodeText()) @@ -60,10 +69,20 @@ class Estimation(db.Model): def get_output_dict(self): if self._output_dict is None: self._output_dict = yaml_load(self.output_yaml) - return self._output_dict + return self._output_dict + pass + + def is_one_to_one(self): + return self.scenario == ScenarioEnum.one_to_one + + def is_one_to_many(self): + return self.scenario == ScenarioEnum.one_to_many + + def is_many_to_one(self): + return self.scenario == ScenarioEnum.many_to_one - def has_many_to_many(self): - return 'cities' in self.get_output_dict() + def is_many_to_many(self): + return self.scenario == ScenarioEnum.many_to_many _models = None @@ -82,6 +101,7 @@ class EstimationView(ModelView): 'first_name', 'last_name', 'models_slugs', + 'scenario', 'origin_addresses', 'destination_addresses', 'warnings', diff --git a/flaskr/static/css/common/main.css b/flaskr/static/css/common/main.css index 83a44f7..32596a0 100755 --- a/flaskr/static/css/common/main.css +++ b/flaskr/static/css/common/main.css @@ -73,7 +73,7 @@ span.required-asterisk { /** LISTS *********************************************************************/ .numbered-list { - list-style: upper-roman; + list-style: decimal-leading-zero; } diff --git a/flaskr/templates/estimate.html b/flaskr/templates/estimate.html index c98b5dd..6d2c0c5 100644 --- a/flaskr/templates/estimate.html +++ b/flaskr/templates/estimate.html @@ -70,11 +70,11 @@
{{ render_field(form.first_name) }} - Fill these to say hello. + {{ content.estimate.help.first_name | safe }}
{{ render_field(form.last_name) }} - We will never share your data with anyone. + {{ content.estimate.help.last_name | safe }}
@@ -83,19 +83,13 @@
{{ render_field(form.origin_addresses) }} - Use en_US city and country names, without diacritics. -   - The comma matters. -
- These usually are the addresses of your participants. + {{ content.estimate.help.origin_addresses | safe }}
{{ render_field(form.destination_addresses) }} - Provide multiple destinations to compare them and compute optimum. -
- These usually are the possible locations for an event. + {{ content.estimate.help.destination_addresses | safe }}
{#
#} diff --git a/flaskr/templates/estimation.html b/flaskr/templates/estimation.html index ef3fe4d..8cbb185 100644 --- a/flaskr/templates/estimation.html +++ b/flaskr/templates/estimation.html @@ -79,21 +79,31 @@ {% if not estimation.has_failed() %} {#{% set estimation_output = estimation.get_output_dict() %}#} -{% if estimation.has_many_to_many() %} -
-

- For each destination city, the sum of the travels from all the origins. -

+
+{% if estimation.is_one_to_one() %} + {{ content.estimation.lolliplot.one_to_one | markdown | safe }} +{#

#} +{# For each destination city, the sum of the travels from all the origins.#} +{#

#} {{ render_cities(estimation_output.cities) }} -
-{% else %} -
-

- Carbon footprint for each city. -

+{% elif estimation.is_many_to_one() %} + {{ content.estimation.lolliplot.many_to_one | markdown | safe }} +{#

#} +{# For each destination city, the sum of the travels from all the origins.#} +{#

#} + {{ render_cities(estimation_output.cities) }} +{% elif estimation.is_one_to_many() %} + {{ content.estimation.lolliplot.one_to_many | markdown | safe }} + + {{ render_cities(estimation_output.cities) }} +{% elif estimation.is_many_to_many() %} + {{ content.estimation.lolliplot.many_to_many | markdown | safe }} +{#

#} +{# Carbon footprint for each city.#} +{#

#} {{ render_cities(estimation_output.cities) }} -
{% endif %} +
#} {#
#} -{% endif %} + +{% endif %}{# estimation.has_failed() #} {% endblock %} + +{#############################################################################} +{#############################################################################} + {% block js %} -- libgit2 0.21.2