From 0eb3e2e259c1451eb7580014ca73a0d180fa2828 Mon Sep 17 00:00:00 2001 From: Remy Moll Date: Sun, 31 Oct 2021 07:03:44 +0100 Subject: [PATCH] better --- dummy_data.py | 42 +- models/event.py | 24 +- models/travel_route.py | 14 +- .../travelhistorymap_customer239842123.html | 404 +++++------------- templates/event_card.html | 2 +- 5 files changed, 160 insertions(+), 326 deletions(-) diff --git a/dummy_data.py b/dummy_data.py index eba5fe2..8244539 100644 --- a/dummy_data.py +++ b/dummy_data.py @@ -8,7 +8,9 @@ def populate_data(Users, Events): location_name = 'SPH Zentrum, Zürich', location_coordinates = [46.3667, 7.445683], date = datetime.date.today() - datetime.timedelta(days=100), - description = "Be part of Switzerland's most fun and personal hackathon experience!" + description = "Be part of Switzerland's most fun and personal hackathon experience!", + activity_duration = datetime.timedelta(hours=20), + image_path = "event_id1_image.jpg" ) Events.add_event( id = 2, @@ -16,7 +18,9 @@ def populate_data(Users, Events): location_name = 'Zürich', location_coordinates = [46.368, 7.445683], date = datetime.date.today() - datetime.timedelta(days=80), - description = "Explore Switzerland's rich cultural history in the unique collection of the Swiss National Museum." + description = "Explore Switzerland's rich cultural history in the unique collection of the Swiss National Museum.", + activity_duration = datetime.timedelta(hours=1), + image_path = "event_id2_image.jpg" ) Events.add_event( id = 3, @@ -24,7 +28,9 @@ def populate_data(Users, Events): location_name = 'Interlaken', location_coordinates = [46.68387, 7.86638], date = datetime.date.today() - datetime.timedelta(days=100), - description = "Fly high between the lakes in Interlaken." + description = "Fly high between the lakes in Interlaken.", + activity_duration = datetime.timedelta(hours=1), + image_path = "event_id3_image.jpg" ) Events.add_event( id = 4, @@ -32,7 +38,9 @@ def populate_data(Users, Events): location_name = 'Lugano', location_coordinates = [46.01008, 8.96004], date = datetime.date.today() - datetime.timedelta(days=100), - description = "Explore one of Ticino's gems in the deep south of Switzerland." + description = "Explore one of Ticino's gems in the deep south of Switzerland.", + activity_duration = datetime.timedelta(hours=1,minutes=30), + image_path = "event_id4_image.jpg" ) Events.add_event( id = 5, @@ -40,7 +48,9 @@ def populate_data(Users, Events): location_name = 'Lucerne', location_coordinates = [47.05048, 8.30635], date = datetime.date.today() - datetime.timedelta(days=20), - description = "See the iconic bridge of Lucerne and enjoy a boat tour on the Vierwaldstätter Lake." + description = "See the iconic bridge of Lucerne and enjoy a boat tour on the Vierwaldstätter Lake.", + activity_duration = datetime.timedelta(hours=1), + image_path = "event_id5_image.jpg" ) Events.add_event( id = 6, @@ -48,7 +58,9 @@ def populate_data(Users, Events): location_name = 'Oeschinen Lake', location_coordinates = [46.492331364, 7.722830442], date = datetime.date.today(), - description = "Take a hike around the beautiful scenery around the Oeschinen Lake." + description = "Take a hike around the beautiful scenery around the Oeschinen Lake.", + activity_duration = datetime.timedelta(hours=1), + image_path = "event_id6_image.jpg" ) Events.add_event( id = 7, @@ -56,7 +68,9 @@ def populate_data(Users, Events): location_name = 'Aletschglacier', location_coordinates = [46.438664912, 8.072999708], date = datetime.date.today(), - description = "Be adventurous by hiking the largest Glacier of the Alps." + description = "Be adventurous by hiking the largest Glacier of the Alps.", + activity_duration = datetime.timedelta(hours=4), + image_path = "event_id7_image.jpg" ) Events.add_event( id = 8, @@ -64,7 +78,9 @@ def populate_data(Users, Events): location_name = 'Engelberg', location_coordinates = [46.82107, 8.40133], date = datetime.date.today(), - description = "Enjoy a Ski weekend at the Engelberg Ski Resort." + description = "Enjoy a Ski weekend at the Engelberg Ski Resort.", + activity_duration = datetime.timedelta(hours=4), + image_path = "event_id8_image.jpg" ) Events.add_event( id = 9, @@ -72,7 +88,9 @@ def populate_data(Users, Events): location_name = 'Davos', location_coordinates = [46.80429, 9.83723], date = datetime.date.today(), - description = "See the winter wonderous municipality Davos in East Switzerland." + description = "See the winter wonderous municipality Davos in East Switzerland.", + activity_duration = datetime.timedelta(hours=2), + image_path = "event_id9_image.jpg" ) Events.add_event( id = 10, @@ -80,7 +98,9 @@ def populate_data(Users, Events): location_name = 'Zermatt', location_coordinates = [46.11654, 7.445683], date = datetime.date.today() - datetime.timedelta(days=10), - description = "Enjoy skiing with view on one of Switzerland's most iconic mountain peaks." + description = "Enjoy skiing with view on one of Switzerland's most iconic mountain peaks.", + activity_duration = datetime.timedelta(hours=2), + image_path = "event_id10_image.jpg" ) Users.add_user( @@ -95,6 +115,6 @@ def populate_data(Users, Events): ) u = Users.get_by_id(239842123) - for e in Events[2:5]: + for e in Events: e.add_review(text="Nice view, good weather. Would recommend.", rating=random.randint(0,5)) u.travel_history.append(e) \ No newline at end of file diff --git a/models/event.py b/models/event.py index c5358ce..dca2562 100644 --- a/models/event.py +++ b/models/event.py @@ -1,3 +1,4 @@ +from .travel_route import TravelRoute class Event: id = 0 @@ -10,9 +11,9 @@ class Event: weather_requirements = 0 date = "" image_path = "fallback.jpg" - duration = "" # datetime object - trip_to = "" # Trip object - trip_back = "" + activity_duration = "" # datetime object + trip_to = TravelRoute(0,0) + trip_back = TravelRoute(0,0) def __init__(self, **kwargs): self.id = kwargs.pop("id") @@ -21,6 +22,8 @@ class Event: self.location_coordinates = kwargs.pop("location_coordinates") self.date = kwargs.pop("date") self.description = kwargs.pop("description") + self.activity_duration = kwargs.pop("activity_duration") + self.image_path = kwargs.pop("image_path") def find_optimal_trip(self): @@ -36,10 +39,8 @@ class Event: @property def co2_savings(self): - try: - return self.trip_to.co2_savings + self.trip_back.co2_savings - except: - return 5 + return self.trip_to.co2_savings + self.trip_back.co2_savings + @property def rating(self): return int(sum([r.rating for r in self.reviews]) / len(self.reviews)) @@ -48,6 +49,15 @@ class Event: def nreviews(self): return len(self.reviews) + @property + def total_duration(self): + s = (self.activity_duration + self.trip_back.duration + self.trip_to.duration).seconds + hours, remainder = divmod(s, 3600) + minutes, seconds = divmod(remainder, 60) + return '{:02} h {:02}'.format(int(hours), int(minutes)) + + + class Review: text = "" diff --git a/models/travel_route.py b/models/travel_route.py index 8d3a696..86685d6 100644 --- a/models/travel_route.py +++ b/models/travel_route.py @@ -1,17 +1,21 @@ +# TBD API interaction + +import datetime class TravelRoute: - def __init__(self, start_coords, end_coords, ) -> None: + def __init__(self, start_coords, end_coords) -> None: pass @property def duration(self): - pass + return datetime.timedelta(hours=2) @property def wait_time(self): - pass + return datetime.timedelta(minutes=10) + @property - def eco_score(self): - pass \ No newline at end of file + def co2_savings(self): + return 15 \ No newline at end of file diff --git a/static/travelhistorymap_customer239842123.html b/static/travelhistorymap_customer239842123.html index 1c67e23..9e00f13 100644 --- a/static/travelhistorymap_customer239842123.html +++ b/static/travelhistorymap_customer239842123.html @@ -23,7 +23,7 @@