ranking.py 719 B

1234567891011121314151617181920212223242526272829303132
  1. def r_size(size):
  2. if size < 30 or size > 400:
  3. return 0.0
  4. elif size > 200:
  5. return 1.0
  6. else:
  7. return (size - 30) / 200.0
  8. def r_price(price):
  9. if price < 250 or price > 450:
  10. return 0
  11. else:
  12. return 1-((price-200.0)/200.0)
  13. def r_commute_duration(duration):
  14. return max(0, 1 - (duration / float(70*60)))
  15. def _rank(price, size, commute_duration):
  16. # return commute_duration / 3600.0
  17. res = 1.0
  18. res *= r_size(size)
  19. res *= r_price(price)
  20. res *= r_commute_duration(commute_duration)
  21. return res
  22. def add_scores(properties_dict):
  23. for p in properties_dict.values():
  24. p['score'] = _rank(p['price'], p['size'], p['commute_duration'])