Commit 1d48272e83607f7c2f8c93637171f4ffad5e59f3
1 parent
fa3d2b43
Exists in
master
Compute the mean footprint and fix a small bug.
Also, going to sleep. /spend 5h
Showing
1 changed file
with
25 additions
and
7 deletions
Show diff stats
flaskr/controllers/main_controller.py
@@ -64,7 +64,7 @@ def compute(): # process the queue of estimation requests | @@ -64,7 +64,7 @@ def compute(): # process the queue of estimation requests | ||
64 | try: | 64 | try: |
65 | estimation = Estimation.query \ | 65 | estimation = Estimation.query \ |
66 | .filter_by(status=StatusEnum.pending) \ | 66 | .filter_by(status=StatusEnum.pending) \ |
67 | - .order_by(Estimation.id.desc()) \ | 67 | + .order_by(Estimation.id.asc()) \ |
68 | .first() | 68 | .first() |
69 | except sqlalchemy.orm.exc.NoResultFound: | 69 | except sqlalchemy.orm.exc.NoResultFound: |
70 | return _respond("No estimation in the queue.") | 70 | return _respond("No estimation in the queue.") |
@@ -121,14 +121,14 @@ def compute(): # process the queue of estimation requests | @@ -121,14 +121,14 @@ def compute(): # process the queue of estimation requests | ||
121 | try: | 121 | try: |
122 | destination = geocoder.geocode(destination_address) | 122 | destination = geocoder.geocode(destination_address) |
123 | except geopy.exc.GeopyError as e: | 123 | except geopy.exc.GeopyError as e: |
124 | - response += u"Failed to geolocalize destination `%s`.\n%s" % ( | 124 | + response += u"Failed to geocode destination `%s`.\n%s" % ( |
125 | destination_address, e, | 125 | destination_address, e, |
126 | ) | 126 | ) |
127 | _handle_failure(estimation, response) | 127 | _handle_failure(estimation, response) |
128 | return _respond(response) | 128 | return _respond(response) |
129 | 129 | ||
130 | if destination is None: | 130 | if destination is None: |
131 | - response += u"Failed to geolocalize destination `%s`." % ( | 131 | + response += u"Failed to geocode destination `%s`." % ( |
132 | destination_address, | 132 | destination_address, |
133 | ) | 133 | ) |
134 | _handle_failure(estimation, response) | 134 | _handle_failure(estimation, response) |
@@ -177,11 +177,11 @@ def compute(): # process the queue of estimation requests | @@ -177,11 +177,11 @@ def compute(): # process the queue of estimation requests | ||
177 | # In this scenario, we compute the sum of each of the travels' footprint, | 177 | # In this scenario, we compute the sum of each of the travels' footprint, |
178 | # for each of the Emission Models, and present a mean of all Models. | 178 | # for each of the Emission Models, and present a mean of all Models. |
179 | # | 179 | # |
180 | - | ||
181 | if 1 == len(origins): | 180 | if 1 == len(origins): |
182 | 181 | ||
183 | footprints = {} | 182 | footprints = {} |
184 | 183 | ||
184 | + cities_sum = {} | ||
185 | for model in emission_models: | 185 | for model in emission_models: |
186 | cities = {} | 186 | cities = {} |
187 | for destination in destinations: | 187 | for destination in destinations: |
@@ -189,23 +189,41 @@ def compute(): # process the queue of estimation requests | @@ -189,23 +189,41 @@ def compute(): # process the queue of estimation requests | ||
189 | origin.latitude, origin.longitude, | 189 | origin.latitude, origin.longitude, |
190 | destination.latitude, destination.longitude, | 190 | destination.latitude, destination.longitude, |
191 | ) | 191 | ) |
192 | - cities[destination.address] = footprint | 192 | + cities[destination.address] += footprint |
193 | + if destination.address not in cities: | ||
194 | + cities[destination.address] = 0.0 | ||
195 | + if destination.address not in cities_sum: | ||
196 | + cities_sum[destination.address] = 0.0 | ||
197 | + cities_sum[destination.address] += footprint | ||
198 | + | ||
193 | footprints[model.config.name] = { | 199 | footprints[model.config.name] = { |
194 | 'cities': cities, | 200 | 'cities': cities, |
195 | } | 201 | } |
196 | 202 | ||
197 | - response += repr(footprints) | ||
198 | - | ||
199 | results['footprints'] = footprints | 203 | results['footprints'] = footprints |
200 | 204 | ||
205 | + cities_mean = {} | ||
206 | + for city in cities_sum.keys(): | ||
207 | + cities_mean[city] = 1.0 * cities_sum[city] / len(emission_models) | ||
208 | + | ||
209 | + results['mean_footprint'] = { | ||
210 | + 'cities': cities_mean | ||
211 | + } | ||
212 | + | ||
201 | # SCENARIO B : At Least One Origin, One Destination ####################### | 213 | # SCENARIO B : At Least One Origin, One Destination ####################### |
202 | # | 214 | # |
203 | # Same as A for now. | 215 | # Same as A for now. |
204 | # | 216 | # |
217 | + elif 1 == len(destinations): | ||
218 | + pass | ||
205 | 219 | ||
206 | # SCENARIO C : At Least One Origin, At Least One Destination ############## | 220 | # SCENARIO C : At Least One Origin, At Least One Destination ############## |
207 | # | 221 | # |
208 | # Run Scenario A for each Destination, and expose optimum Destination. | 222 | # Run Scenario A for each Destination, and expose optimum Destination. |
209 | # | 223 | # |
224 | + else: | ||
225 | + pass | ||
226 | + | ||
227 | + response += repr(results) + "\n" | ||
210 | 228 | ||
211 | return _respond(response) | 229 | return _respond(response) |