From 88fef81582d7706d22525d0beefcba4149441f0a Mon Sep 17 00:00:00 2001 From: "K. Shankari" Date: Fri, 19 Apr 2019 07:28:06 -0700 Subject: [PATCH 1/2] Fix numpy encodings of return values After the switch to python3, numpy values are no longer serializable and have to be converted to floats before they are stored or retrieved. The metrics also return computed values, so we need convert here too. This fixes https://github.com/e-mission/e-mission-docs/issues/382 Tested by @PatGendre who also reported the issue --- emission/analysis/result/metrics/simple_metrics.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/emission/analysis/result/metrics/simple_metrics.py b/emission/analysis/result/metrics/simple_metrics.py index 6e8a33b34..53b8304d6 100644 --- a/emission/analysis/result/metrics/simple_metrics.py +++ b/emission/analysis/result/metrics/simple_metrics.py @@ -27,13 +27,13 @@ def get_count(mode_section_grouped_df): def get_distance(mode_section_grouped_df): ret_dict = {} for (mode, mode_section_df) in mode_section_grouped_df: - ret_dict[mode] = mode_section_df.distance.sum() + ret_dict[mode] = float(mode_section_df.distance.sum()) return ret_dict def get_duration(mode_section_grouped_df): ret_dict = {} for (mode, mode_section_df) in mode_section_grouped_df: - ret_dict[mode] = mode_section_df.duration.sum() + ret_dict[mode] = float(mode_section_df.duration.sum()) return ret_dict def get_median_speed(mode_section_grouped_df): @@ -45,5 +45,5 @@ def get_median_speed(mode_section_grouped_df): if np.isnan(mode_median): logging.debug("still found nan for mode %s, skipping") else: - ret_dict[mode] = mode_median + ret_dict[mode] = float(mode_median) return ret_dict From d7b54ea479769e13a391e91ee1d2d36cd14c7be2 Mon Sep 17 00:00:00 2001 From: "K. Shankari" Date: Fri, 19 Apr 2019 07:31:12 -0700 Subject: [PATCH 2/2] Add additional logging to the nominatim geocoder So that if it fails, we can get a better sense of why. This fixes https://github.com/e-mission/e-mission-docs/issues/337 for now --- emission/net/ext_service/geocoder/nominatim.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/emission/net/ext_service/geocoder/nominatim.py b/emission/net/ext_service/geocoder/nominatim.py index 901f321c5..30ef19ce3 100644 --- a/emission/net/ext_service/geocoder/nominatim.py +++ b/emission/net/ext_service/geocoder/nominatim.py @@ -40,6 +40,7 @@ def make_url_geo(cls, address): query_url = NOMINATIM_QUERY_URL + "/search?" encoded_params = urllib.parse.urlencode(params) url = query_url + encoded_params + logging.debug("For geocoding, using URL %s" % url) return url @classmethod @@ -72,6 +73,7 @@ def make_url_reverse(cls, lat, lon): query_url = NOMINATIM_QUERY_URL + "/reverse?" encoded_params = urllib.parse.urlencode(params) url = query_url + encoded_params + logging.debug("For reverse geocoding, using URL %s" % url) return url @classmethod