3 İşlemeler 86087a00ee ... 7dac3b6830

Yazar SHA1 Mesaj Tarih
  Martin 7dac3b6830 always load favourites 5 yıl önce
  Martin 83e6124a94 allow properties without size 5 yıl önce
  Martin ad2f8f1acc ranking signals update 5 yıl önce
4 değiştirilmiş dosya ile 55 ekleme ve 21 silme
  1. 2 0
      config.py
  2. 13 4
      properties.py
  3. 27 12
      ranking.py
  4. 13 5
      visualize.py

+ 2 - 0
config.py

@@ -17,6 +17,7 @@ MONITORED_LOCALITIES = [
     2712, # Co Meath
     2712, # Co Meath
 ]
 ]
 
 
+# (SW, NE)
 MONITORED_BBOXES = {
 MONITORED_BBOXES = {
     '1 Overall': ((53, -6.9), (53.85, -5.9)),
     '1 Overall': ((53, -6.9), (53.85, -5.9)),
     '2 Clontarf': ((53.360213,-6.209679), (53.386021,-6.138611)),
     '2 Clontarf': ((53.360213,-6.209679), (53.386021,-6.138611)),
@@ -24,6 +25,7 @@ MONITORED_BBOXES = {
     '4 Malahide estuary': ((53.450280,-6.190388), (53.456924,-6.158301)),
     '4 Malahide estuary': ((53.450280,-6.190388), (53.456924,-6.158301)),
     '5 Skerries': ((53.562193,-6.157150), (53.588490,-6.088829)),
     '5 Skerries': ((53.562193,-6.157150), (53.588490,-6.088829)),
     '6 Dalkey, Killiney': ((53.265768,-6.127407), (53.290505,-6.081422)),
     '6 Dalkey, Killiney': ((53.265768,-6.127407), (53.290505,-6.081422)),
+    '7 Sutton': ((53.385008,-6.128441), (53.394119,-6.088246)),
 }
 }
 VISUALIZED_BBOXES = {k: v for k, v in MONITORED_BBOXES.items() if k != 'Overallx'}
 VISUALIZED_BBOXES = {k: v for k, v in MONITORED_BBOXES.items() if k != 'Overallx'}
 
 

+ 13 - 4
properties.py

@@ -5,14 +5,22 @@ import config
 def load_properties(require_active, require_update_since):
 def load_properties(require_active, require_update_since):
     ts = db.datetime_to_str(require_update_since)
     ts = db.datetime_to_str(require_update_since)
     with db.connect() as conn:
     with db.connect() as conn:
-        rows = conn.select('select id, lat, lon, size, price, bedrooms, ber, bathrooms, property_type from properties '
-                           'where price<%i and last_update > "%s"' % (config.MAX_PRICE, ts))
+        favourites = set(conn.select('select id from annotations where favourited=1'))
+        favourites_str = ','.join([str(x) for x in favourites])
+
+        rows = conn.select(
+            'select id, lat, lon, size, price, bedrooms, ber, bathrooms, property_type from properties '
+            'where (price<%i and last_update > "%s") or (id in (%s))' % (config.MAX_PRICE, ts, favourites_str)
+        )
 
 
         res = {}
         res = {}
         for property_id, lat, lon, size, price, bedrooms, ber, bathrooms, property_type in rows:
         for property_id, lat, lon, size, price, bedrooms, ber, bathrooms, property_type in rows:
-            if not price or not size or not lat or not lon:
+            if not price or not lat or not lon:
                 continue
                 continue
 
 
+            if not size:
+                size = 0
+
             if not any(geo_util.inside((lat, lon), bbox) for bbox in config.MONITORED_BBOXES.values()):
             if not any(geo_util.inside((lat, lon), bbox) for bbox in config.MONITORED_BBOXES.values()):
                 continue
                 continue
 
 
@@ -31,6 +39,7 @@ def load_properties(require_active, require_update_since):
                 'price_history': [],
                 'price_history': [],
                 'ber': ber,
                 'ber': ber,
                 'type': property_type,
                 'type': property_type,
+                'favourite': property_id in favourites,
             }
             }
 
 
         rows = conn.select('select time, property_id, price from search_results order by time asc')
         rows = conn.select('select time, property_id, price from search_results order by time asc')
@@ -38,7 +47,7 @@ def load_properties(require_active, require_update_since):
             if pid not in res:
             if pid not in res:
                 continue
                 continue
 
 
-            if time < ts:
+            if pid not in favourites and time < ts:
                 del res[pid]
                 del res[pid]
                 continue
                 continue
 
 

+ 27 - 12
ranking.py

@@ -25,18 +25,26 @@ _TYPE_CONF = {
 
 
 _BER_CONF = {
 _BER_CONF = {
     25: 1, # A1
     25: 1, # A1
-    70: 0.7, # A3
-    140: 0.2, # B2
-    # 260: 0.5, # #D1
-    # 300: 1, # E1
-    # 450: 1, # G
+    70: 1, # A3
+    # 100: 0.5, # B1
+    # 140: 0.2, # B2
+    150: 0.6, # # B3
+    # 300: 0.2, # E1
+    # 400: 0.4,
+    450: 0.2, # G
+    # 400: 0.4
 }
 }
 
 
+# _BER_CONF = {
+#     210: 1,
+#     440: 0.6,
+# }
+
 _SIZE_CONF = {
 _SIZE_CONF = {
-    90: 0,
-    100: 0.5,
-    180: 1,
-    400: 1,
+    None: 0.5,
+    80: 0.5,
+    150: 1,
+    200: 1,
 }
 }
 
 
 _BEDROOMS_CONF = {
 _BEDROOMS_CONF = {
@@ -44,14 +52,16 @@ _BEDROOMS_CONF = {
     2: 0.4,
     2: 0.4,
     3: 0.8,
     3: 0.8,
     4: 1,
     4: 1,
-    10: 1,
+    5: 1,
+    6: 0.2,
 }
 }
 
 
 _BATHROOMS_CONF = {
 _BATHROOMS_CONF = {
     None: 0.7,
     None: 0.7,
     1: 0.5,
     1: 0.5,
     2: 1,
     2: 1,
-    4: 1,
+    3: 1,
+    4: 0.8,
 }
 }
 
 
 # disabled
 # disabled
@@ -61,7 +71,7 @@ _COMMUTE_CONF = {
 }
 }
 
 
 _PRICE_CONF = {
 _PRICE_CONF = {
-    300: 1,
+    400: 1,
     900: 0.6,
     900: 0.6,
 }
 }
 
 
@@ -73,7 +83,12 @@ _RERANKING_CONF = {
 def _linear(signal, configuration):
 def _linear(signal, configuration):
     if signal in configuration:
     if signal in configuration:
         return configuration[signal]
         return configuration[signal]
+    if not signal and configuration.get(None):
+        return configuration[None]
     
     
+    if signal is None:
+        return 0
+
     configuration = sorted([(k, v) for k, v in configuration.items() if k is not None])
     configuration = sorted([(k, v) for k, v in configuration.items() if k is not None])
 
 
     if signal < configuration[0][0] or signal > configuration[-1][0]:
     if signal < configuration[0][0] or signal > configuration[-1][0]:

+ 13 - 5
visualize.py

@@ -1,3 +1,4 @@
+import sys
 import commute
 import commute
 import config
 import config
 import db
 import db
@@ -33,6 +34,8 @@ def _write_styles(f):
             hexvalue = '0' + hexvalue
             hexvalue = '0' + hexvalue
         f.write('<Style id="color-%i"><IconStyle><color>ff%s%sff</color></IconStyle></Style>\n' % (i, hexvalue, hexvalue))
         f.write('<Style id="color-%i"><IconStyle><color>ff%s%sff</color></IconStyle></Style>\n' % (i, hexvalue, hexvalue))
 
 
+    f.write('<Style id="color-green"><IconStyle><color>ff00ff00</color></IconStyle></Style>\n')
+
 def _write_commutes(f, commutes):
 def _write_commutes(f, commutes):
     f.write('<Folder><name>Commutes</name><visibility>0</visibility>\n')
     f.write('<Folder><name>Commutes</name><visibility>0</visibility>\n')
     max_duration = min(4000, max([x['duration'] for x in commutes.values()]))
     max_duration = min(4000, max([x['duration'] for x in commutes.values()]))
@@ -59,9 +62,13 @@ def _write_properties(f, properties_dict, tmp_ids):
     min_max_delta = max_score - min_score
     min_max_delta = max_score - min_score
 
 
     for pid, data in properties_list:
     for pid, data in properties_list:
-        value = ((data['score'] - min_score) / min_max_delta) if min_max_delta else 1
-        value = min(1, value)
-        color = 20 + value * 235
+        color = None
+        if data['favourite']:
+            color = 'green'
+        else:
+            value = ((data['score'] - min_score) / min_max_delta) if min_max_delta else 1
+            value = min(1, value)
+            color = int(20 + value * 235)
 
 
         title = '%.0f-%.0f-%s-%i' % (data['price'], data['size'], data.get('ber', ''), tmp_ids[pid])
         title = '%.0f-%.0f-%s-%i' % (data['price'], data['size'], data.get('ber', ''), tmp_ids[pid])
 
 
@@ -84,7 +91,7 @@ def _write_properties(f, properties_dict, tmp_ids):
 
 
         f.write('''<Placemark>
         f.write('''<Placemark>
             <Point><coordinates>%f,%f</coordinates></Point>
             <Point><coordinates>%f,%f</coordinates></Point>
-            <styleUrl>#color-%i</styleUrl>
+            <styleUrl>#color-%s</styleUrl>
             <name>%s</name>
             <name>%s</name>
             <description><![CDATA[ %s ]]></description>
             <description><![CDATA[ %s ]]></description>
         </Placemark>\n''' % (data['loc'][1], data['loc'][0], color, title, description))
         </Placemark>\n''' % (data['loc'][1], data['loc'][0], color, title, description))
@@ -128,7 +135,8 @@ def _set_tmp_ids(properties_dict):
     return res
     return res
 
 
 def run():
 def run():
-    load_since = datetime.datetime.now() - datetime.timedelta(days=365)
+    days = int(sys.argv[1]) if len(sys.argv) > 1 else 31
+    load_since = datetime.datetime.now() - datetime.timedelta(days=days)
     properties_dict = properties.load_properties(True, load_since)
     properties_dict = properties.load_properties(True, load_since)
     print('Loaded %i properties' % len(properties_dict))
     print('Loaded %i properties' % len(properties_dict))