Gordon Li commited on
Commit
d6d464a
Β·
1 Parent(s): be259ac

DIscount Price Calculation and tune the similarity

Browse files
Files changed (3) hide show
  1. AirbnbMapVisualiser.py +4 -10
  2. app.py +30 -4
  3. style.css +19 -0
AirbnbMapVisualiser.py CHANGED
@@ -345,22 +345,16 @@ class AirbnbMapVisualiser:
345
  review_similarity = self.compute_similarity(query_embedding, review_embedding)
346
 
347
  # Determine which source matched better
348
- if title_similarity > 0.7 and review_similarity > 0.7:
349
  return "Strong match in title and reviews"
350
- elif title_similarity > 0.7:
351
  return "Strong match in listing title"
352
- elif review_similarity > 0.7:
353
  return "Strong match in reviews"
354
- elif title_similarity > review_similarity:
355
- return "Better match in listing title"
356
- elif review_similarity > title_similarity:
357
- return "Better match in reviews"
358
- else:
359
- return "Moderate semantic match"
360
 
361
  # Only calculate match source if score is above threshold
362
  df['matching_features'] = df.apply(
363
- lambda row: get_match_source(row) if row['relevance_score'] > 0.3 else "Low semantic match",
364
  axis=1
365
  )
366
 
 
345
  review_similarity = self.compute_similarity(query_embedding, review_embedding)
346
 
347
  # Determine which source matched better
348
+ if title_similarity > 0.2 and review_similarity > 0.2:
349
  return "Strong match in title and reviews"
350
+ elif title_similarity > 0.2:
351
  return "Strong match in listing title"
352
+ elif review_similarity > 0.2:
353
  return "Strong match in reviews"
 
 
 
 
 
 
354
 
355
  # Only calculate match source if score is above threshold
356
  df['matching_features'] = df.apply(
357
+ lambda row: get_match_source(row) if row['relevance_score'] > 0.2 else "Low semantic match",
358
  axis=1
359
  )
360
 
app.py CHANGED
@@ -7,6 +7,7 @@ import math
7
  from AirbnbMapVisualiser import AirbnbMapVisualiser
8
  from huggingface_hub import login
9
 
 
10
  def load_css(css_file):
11
  with open(css_file) as f:
12
  st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)
@@ -131,9 +132,9 @@ def main():
131
 
132
  * **Purple Camera Icons**: Areas with heavier traffic (more than 5 vehicles)
133
  * Standard rates apply for these properties
134
-
135
  Look for the blue connecting lines on the map to see which traffic spot affects each property!
136
-
137
  Remark : Currently only few traffic spot avaliable, in the future will provide more.
138
  """)
139
  if st.button("Close", key="close_traffic_btn"):
@@ -262,6 +263,31 @@ def main():
262
  row = df.iloc[idx]
263
  background_color = "#E3F2FD" if st.session_state.selected_id == row['id'] else "white"
264
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
265
  relevance_info = ""
266
  if st.session_state.search_query and 'relevance_percentage' in row:
267
  relevance_info = f"""<p class="listing-info"> 🎯 Relevance: {row['relevance_percentage']:.0f}% </p>"""
@@ -273,7 +299,7 @@ def main():
273
  st.markdown(f"""
274
  <div class="listing-card" style="background-color: {background_color}">
275
  <h4 class="listing-title">{escape(str(row['name']))}</h4>
276
- <p class="listing-info">πŸ’° ${row['price']:.0f}</p>
277
  <p class="listing-info">🏠 {escape(str(row['room_type']))}</p>
278
  <p class="listing-info">⭐ Reviews: {row['number_of_reviews']:.0f}</p>
279
  {relevance_info}</div>
@@ -354,4 +380,4 @@ if __name__ == "__main__":
354
  login(token=token)
355
  main()
356
  else:
357
- main()
 
7
  from AirbnbMapVisualiser import AirbnbMapVisualiser
8
  from huggingface_hub import login
9
 
10
+
11
  def load_css(css_file):
12
  with open(css_file) as f:
13
  st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)
 
132
 
133
  * **Purple Camera Icons**: Areas with heavier traffic (more than 5 vehicles)
134
  * Standard rates apply for these properties
135
+
136
  Look for the blue connecting lines on the map to see which traffic spot affects each property!
137
+
138
  Remark : Currently only few traffic spot avaliable, in the future will provide more.
139
  """)
140
  if st.button("Close", key="close_traffic_btn"):
 
263
  row = df.iloc[idx]
264
  background_color = "#E3F2FD" if st.session_state.selected_id == row['id'] else "white"
265
 
266
+ # Calculate discount based on nearest traffic spot
267
+ discounted_price = row['price']
268
+ discount_tag = ""
269
+
270
+ # Find nearest traffic spot for this listing
271
+ listing_lat = row['latitude']
272
+ listing_lng = row['longitude']
273
+
274
+ # Use the visualizer's method to find the nearest traffic spot
275
+ nearest_spot, distance = visualizer.find_nearest_traffic_spot(listing_lat, listing_lng)
276
+
277
+ # Apply discount if there's a nearest spot
278
+ if nearest_spot:
279
+ discount_rate = nearest_spot.get_discount_rate()
280
+ if discount_rate > 0:
281
+ discounted_price = row['price'] * (1 - discount_rate)
282
+ discount_percentage = int(discount_rate * 100)
283
+ discount_tag = f"""<span class="discount-tag">-{discount_percentage}%</span>"""
284
+
285
+ # Price display logic
286
+ if discount_tag:
287
+ price_display = f"""<p class="listing-info">πŸ’° <span class="original-price">${row['price']:.0f}</span> <span class="discounted-price">${discounted_price:.0f}</span> {discount_tag}</p>"""
288
+ else:
289
+ price_display = f"""<p class="listing-info">πŸ’° ${row['price']:.0f}</p>"""
290
+
291
  relevance_info = ""
292
  if st.session_state.search_query and 'relevance_percentage' in row:
293
  relevance_info = f"""<p class="listing-info"> 🎯 Relevance: {row['relevance_percentage']:.0f}% </p>"""
 
299
  st.markdown(f"""
300
  <div class="listing-card" style="background-color: {background_color}">
301
  <h4 class="listing-title">{escape(str(row['name']))}</h4>
302
+ {price_display}
303
  <p class="listing-info">🏠 {escape(str(row['room_type']))}</p>
304
  <p class="listing-info">⭐ Reviews: {row['number_of_reviews']:.0f}</p>
305
  {relevance_info}</div>
 
380
  login(token=token)
381
  main()
382
  else:
383
+ main()
style.css CHANGED
@@ -418,3 +418,22 @@
418
  border-radius: 2px;
419
  font-weight: bold;
420
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
418
  border-radius: 2px;
419
  font-weight: bold;
420
  }
421
+ .original-price {
422
+ text-decoration: line-through;
423
+ color: #999;
424
+ margin-right: 5px;
425
+ }
426
+
427
+ .discounted-price {
428
+ font-weight: bold;
429
+ color: #2e7d32;
430
+ }
431
+
432
+ .discount-tag {
433
+ background-color: #4caf50;
434
+ color: white;
435
+ padding: 2px 5px;
436
+ border-radius: 3px;
437
+ font-size: 0.8em;
438
+ margin-left: 5px;
439
+ }