diff options
-rw-r--r-- | fietsboek/util.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/fietsboek/util.py b/fietsboek/util.py index bab2074..aff41fe 100644 --- a/fietsboek/util.py +++ b/fietsboek/util.py @@ -27,6 +27,10 @@ ALLOWED_TAGS = (bleach.sanitizer.ALLOWED_TAGS + ALLOWED_ATTRIBUTES = dict(bleach.sanitizer.ALLOWED_ATTRIBUTES) ALLOWED_ATTRIBUTES['img'] = ['alt', 'src'] +# Arbitrarily chosen, just make sure they are representable +DEFAULT_START_TIME = datetime.datetime(1977, 5, 25, 8, 0) +DEFAULT_END_TIME = datetime.datetime(1985, 7, 3, 8, 0) + _filename_ascii_strip_re = re.compile(r"[^A-Za-z0-9_.-]") _windows_device_files = ( @@ -165,6 +169,10 @@ def tour_metadata(gpx_data): uphill, downhill = gpx.get_uphill_downhill() moving_data = gpx.get_moving_data() time_bounds = gpx.get_time_bounds() + try: + avg_speed = moving_data.moving_distance / moving_data.moving_time + except ZeroDivisionError: + avg_speed = 0.0 return { 'length': gpx.length_3d(), 'uphill': uphill, @@ -172,9 +180,9 @@ def tour_metadata(gpx_data): 'moving_time': moving_data.moving_time, 'stopped_time': moving_data.stopped_time, 'max_speed': moving_data.max_speed, - 'avg_speed': moving_data.moving_distance / moving_data.moving_time, - 'start_time': time_bounds.start_time.astimezone(timezone), - 'end_time': time_bounds.end_time.astimezone(timezone), + 'avg_speed': avg_speed, + 'start_time': (time_bounds.start_time or DEFAULT_START_TIME).astimezone(timezone), + 'end_time': (time_bounds.end_time or DEFAULT_END_TIME).astimezone(timezone), } |