| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- # From http://www.berratings.com/wp-content/uploads/2013/11/BER_Cert_with_explaination-e1397729848491.jpg
- _BER_RANKINGS = {
- 'A1': (25 + 25) / 2.0,
- 'A2': (25 + 50) / 2.0,
- 'A3': (50 + 75) / 2.0,
- 'B1': (75 + 100) / 2.0,
- 'B2': (100 + 125) / 2.0,
- 'B3': (125 + 150) / 2.0,
- 'C1': (150 + 175) / 2.0,
- 'C2': (175 + 200) / 2.0,
- 'C3': (200 + 225) / 2.0,
- 'D1': (225 + 260) / 2.0,
- 'D2': (260 + 300) / 2.0,
- 'E1': (300 + 340) / 2.0,
- 'E2': (340 + 380) / 2.0,
- 'F': (380 + 450) / 2.0,
- 'G': (450 + 450) / 2.0,
- 'Exempt': (500 + 500) / 2.0,
- }
- _BER_CONF = [
- (25, 1),
- (60, 0.9),
- (140, 0.6),
- (300, 0.1),
- ]
- _SIZE_CONF = [
- (50, 0.3),
- (150, 1),
- (400, 1),
- ]
- _BEDROOMS_CONF = [
- (3, 0.6),
- (4, 1),
- (10, 1),
- ]
- # disabled
- _COMMUTE_CONF = [
- (0, 1),
- (60*70, 1),
- ]
- _PRICE_CONF = [
- (300, 1),
- (400, 0.7),
- (450, 0.3),
- ]
- def _linear(signal, configuration):
- if signal < configuration[0][0] or signal > configuration[-1][0]:
- return 0
- for i, (limit, value) in enumerate(configuration):
- next_limit, next_value = configuration[i+1]
- if signal <= next_limit:
- limit_diff = next_limit - limit
- signal_ratio = (signal - limit) / float(limit_diff)
- return value + (next_value - value) * signal_ratio
- def r_size(size):
- return _linear(size, _SIZE_CONF)
- def r_price(price):
- return _linear(price, _PRICE_CONF)
- def r_commute_duration(duration):
- return 1
- # return _linear(duration, _COMMUTE_CONF)
- def r_bedrooms(bedrooms):
- return _linear(bedrooms, _BEDROOMS_CONF)
- def r_ber(ber):
- ber = ber or 'Exempt'
- value = None
- if '-' in ber:
- a, b = ber.split('-')
- value = (_BER_RANKINGS[a] + _BER_RANKINGS[b]) / 20.
- else:
- value = _BER_RANKINGS[ber]
- return _linear(value, _BER_CONF)
- def _rank(data):
- res = 1.0
- res *= r_size(data['size'])
- res *= r_price(data['price'])
- res *= r_commute_duration(data['commute_duration'])
- res *= r_ber(data['ber'])
- res *= r_bedrooms(data['bedrooms'])
- return res
- def add_scores(properties_dict):
- for p in properties_dict.values():
- p['score'] = _rank(p)
|