Spaces:
Sleeping
Sleeping
Gordon Li
commited on
Commit
·
dd22c46
1
Parent(s):
ae72b3f
bug fix for no traffic discount
Browse files
constant/hkust_bnb_constant.py
CHANGED
@@ -61,6 +61,12 @@ DISCOUNT_INFO_TEMPLATE = """
|
|
61 |
</div>
|
62 |
"""
|
63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
TRAFFIC_SPOT_INFO_TEMPLATE = """
|
65 |
<div class='traffic-spot-info' style='margin: 10px 0; padding: 8px; background-color: #f0f8ff; border-radius: 4px; border-left: 4px solid #4285f4;'>
|
66 |
<p style='margin: 5px 0;'>
|
@@ -182,7 +188,7 @@ RELEVANCE_INFO_LISTING = """<p class="listing-info"> Relevance: {relevance_perc
|
|
182 |
|
183 |
TRAFFIC_DISCOUNT_DISPLAY = """
|
184 |
<div style='background-color: #e8f5e9; padding: 5px; margin: 5px 0; border-radius: 4px; border-left: 3px solid #4caf50;'>
|
185 |
-
<p style='margin: 2px 0; color:
|
186 |
<p style='margin: 2px 0; font-size: 0.9em;'>Avg. {avg_vehicle_count:.1f} vehicles across {observation_count} observations</p>
|
187 |
</div>
|
188 |
"""
|
|
|
61 |
</div>
|
62 |
"""
|
63 |
|
64 |
+
NO_DISCOUNT_INFO_TEMPLATE = """
|
65 |
+
<div style='background-color: #e8f5e9; padding: 8px; margin: 10px 0; border-radius: 4px; border-left: 4px solid #4caf50;'>
|
66 |
+
<p style='margin: 2px 0; font-size: 0.85em;'>Avg. {avg_vehicle_count:.1f} vehicles across {observation_count} observations</p>
|
67 |
+
</div>
|
68 |
+
"""
|
69 |
+
|
70 |
TRAFFIC_SPOT_INFO_TEMPLATE = """
|
71 |
<div class='traffic-spot-info' style='margin: 10px 0; padding: 8px; background-color: #f0f8ff; border-radius: 4px; border-left: 4px solid #4285f4;'>
|
72 |
<p style='margin: 5px 0;'>
|
|
|
188 |
|
189 |
TRAFFIC_DISCOUNT_DISPLAY = """
|
190 |
<div style='background-color: #e8f5e9; padding: 5px; margin: 5px 0; border-radius: 4px; border-left: 3px solid #4caf50;'>
|
191 |
+
<p style='margin: 2px 0; color: blue;'><strong>{discount_info}</strong></p>
|
192 |
<p style='margin: 2px 0; font-size: 0.9em;'>Avg. {avg_vehicle_count:.1f} vehicles across {observation_count} observations</p>
|
193 |
</div>
|
194 |
"""
|
visualiser/hkust_bnb_visualiser.py
CHANGED
@@ -30,7 +30,8 @@ from constant.hkust_bnb_constant import (
|
|
30 |
TRAFFIC_SPOT_INFO_TEMPLATE,
|
31 |
RELEVANCE_INFO_TEMPLATE,
|
32 |
POPUP_CONTENT_TEMPLATE,
|
33 |
-
MAP_SCRIPT
|
|
|
34 |
)
|
35 |
|
36 |
class HKUSTBNBVisualiser:
|
@@ -388,10 +389,16 @@ class HKUSTBNBVisualiser:
|
|
388 |
discount_info = ""
|
389 |
discounted_price = row['price']
|
390 |
|
|
|
391 |
if row['id'] in all_nearest_traffic_spots:
|
392 |
nearest_spot, distance = all_nearest_traffic_spots[row['id']]
|
393 |
discount_rate = nearest_spot.get_discount_rate()
|
394 |
|
|
|
|
|
|
|
|
|
|
|
395 |
if discount_rate > 0:
|
396 |
discounted_price = row['price'] * (1 - discount_rate)
|
397 |
discount_percentage = int(discount_rate * 100)
|
@@ -400,7 +407,12 @@ class HKUSTBNBVisualiser:
|
|
400 |
discount_percentage=discount_percentage,
|
401 |
original_price=row['price'],
|
402 |
discounted_price=discounted_price,
|
403 |
-
avg_vehicle_count=
|
|
|
|
|
|
|
|
|
|
|
404 |
observation_count=len(nearest_spot.dataset_rows)
|
405 |
)
|
406 |
|
|
|
30 |
TRAFFIC_SPOT_INFO_TEMPLATE,
|
31 |
RELEVANCE_INFO_TEMPLATE,
|
32 |
POPUP_CONTENT_TEMPLATE,
|
33 |
+
MAP_SCRIPT,
|
34 |
+
NO_DISCOUNT_INFO_TEMPLATE
|
35 |
)
|
36 |
|
37 |
class HKUSTBNBVisualiser:
|
|
|
389 |
discount_info = ""
|
390 |
discounted_price = row['price']
|
391 |
|
392 |
+
# Inside the create_map_and_data method
|
393 |
if row['id'] in all_nearest_traffic_spots:
|
394 |
nearest_spot, distance = all_nearest_traffic_spots[row['id']]
|
395 |
discount_rate = nearest_spot.get_discount_rate()
|
396 |
|
397 |
+
# Calculate average vehicle count safely
|
398 |
+
avg_vehicle_count = nearest_spot.avg_vehicle_count
|
399 |
+
if avg_vehicle_count is None:
|
400 |
+
avg_vehicle_count = "N/A" # Or calculate it directly here if needed
|
401 |
+
|
402 |
if discount_rate > 0:
|
403 |
discounted_price = row['price'] * (1 - discount_rate)
|
404 |
discount_percentage = int(discount_rate * 100)
|
|
|
407 |
discount_percentage=discount_percentage,
|
408 |
original_price=row['price'],
|
409 |
discounted_price=discounted_price,
|
410 |
+
avg_vehicle_count=avg_vehicle_count,
|
411 |
+
observation_count=len(nearest_spot.dataset_rows)
|
412 |
+
)
|
413 |
+
else:
|
414 |
+
discount_info = NO_DISCOUNT_INFO_TEMPLATE.format(
|
415 |
+
avg_vehicle_count=avg_vehicle_count,
|
416 |
observation_count=len(nearest_spot.dataset_rows)
|
417 |
)
|
418 |
|
visualiser/td_traffic_spot_visualiser.py
CHANGED
@@ -92,7 +92,7 @@ class TDTrafficSpot:
|
|
92 |
def get_discount_rate(self):
|
93 |
if self.avg_vehicle_count < 2:
|
94 |
return 0.20
|
95 |
-
elif self.avg_vehicle_count
|
96 |
return 0.10
|
97 |
else:
|
98 |
return 0.0
|
@@ -117,10 +117,7 @@ class TDTrafficSpot:
|
|
117 |
|
118 |
def create_popup_content(self):
|
119 |
discount_info = self.get_discount_info()
|
120 |
-
discount_display =
|
121 |
-
|
122 |
-
if "discount" in discount_info.lower() and "no" not in discount_info.lower():
|
123 |
-
discount_display = TRAFFIC_DISCOUNT_DISPLAY.format(
|
124 |
discount_info=discount_info,
|
125 |
avg_vehicle_count=self.avg_vehicle_count,
|
126 |
observation_count=len(self.dataset_rows)
|
|
|
92 |
def get_discount_rate(self):
|
93 |
if self.avg_vehicle_count < 2:
|
94 |
return 0.20
|
95 |
+
elif self.avg_vehicle_count <= 5:
|
96 |
return 0.10
|
97 |
else:
|
98 |
return 0.0
|
|
|
117 |
|
118 |
def create_popup_content(self):
|
119 |
discount_info = self.get_discount_info()
|
120 |
+
discount_display = TRAFFIC_DISCOUNT_DISPLAY.format(
|
|
|
|
|
|
|
121 |
discount_info=discount_info,
|
122 |
avg_vehicle_count=self.avg_vehicle_count,
|
123 |
observation_count=len(self.dataset_rows)
|