ranking.py 668 B

1234567891011121314151617181920212223242526272829
  1. def _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 _price(price):
  9. if price < 200 or price > 400:
  10. return 0
  11. else:
  12. return (price-200.0)/200.0
  13. def _commute_duration(duration):
  14. return max(0, 1 - (duration / float(70*60)))
  15. def _rank(price, size, commute_duration):
  16. res = 1.0
  17. res *= _size(size)
  18. res *= _price(price)
  19. res *= _commute_duration(commute_duration)
  20. return res
  21. def add_scores(properties_dict):
  22. for p in properties_dict.values():
  23. p['score'] = _rank(p['price'], p['size'], p['commute_duration'])