Jelajahi Sumber

minor improvements

Martin 6 tahun lalu
induk
melakukan
a38abadcea
4 mengubah file dengan 22 tambahan dan 14 penghapusan
  1. 2 1
      create_htmls.py
  2. 8 5
      properties.py
  3. 9 6
      ranking.py
  4. 3 2
      visualize.py

+ 2 - 1
create_htmls.py

@@ -136,9 +136,10 @@ def run(conn, retry_bad_pids=True):
         for pid, ts, price in rows:
             row = run_single(conn, pid)
             size, ber, address, main_photo, bedrooms, bathrooms, price = row
+            price = ('%sk' % int(int(price)/1000)) if price != 'GONE' else price
 
             f.write('<a href="%i.html"><h2>%s</h2></a>' % (pid, address))
-            f.write('<h2>%sk, %s m<sup>2</sup>, %s br / %s b, %s</h2>\n' %  (int(int(price)/1000), size, bedrooms, bathrooms, ber))
+            f.write('<h2>%s, %s m<sup>2</sup>, %s br / %s b, %s</h2>\n' %  (price, size, bedrooms, bathrooms, ber))
             if main_photo:
                 f.write('<a href="%i.html"><img src="%s"></a>' % (pid, main_photo))
                 if not _test_url(main_photo):

+ 8 - 5
properties.py

@@ -1,10 +1,9 @@
-import datetime
 import db
 import geo_util
 import config
 
-def load_properties(require_active=True):
-    ts = db.datetime_to_str(datetime.datetime.now() - datetime.timedelta(days=90))
+def load_properties(require_active, require_update_since):
+    ts = db.datetime_to_str(require_update_since)
     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))
@@ -34,11 +33,15 @@ def load_properties(require_active=True):
                 'type': property_type,
             }
 
-        rows = conn.select('select property_id, price from search_results order by time asc')
-        for pid, price in rows:
+        rows = conn.select('select time, property_id, price from search_results order by time asc')
+        for time, pid, price in rows:
             if pid not in res:
                 continue
 
+            if time < ts:
+                del res[pid]
+                continue
+
             if price.isdigit():
                 price = int(price)
                 res[pid]['price'] = price/1000

+ 9 - 6
ranking.py

@@ -24,9 +24,12 @@ _TYPE_CONF = {
 }
 
 _BER_CONF = {
-    25: 1,
-    70: 0.9,
-    260: 0.5,
+    25: 1, # A1
+    70: 0.7, # A3
+    140: 0.2, # B2
+    # 260: 0.5, # #D1
+    # 300: 1, # E1
+    # 450: 1, # G
 }
 
 _SIZE_CONF = {
@@ -48,7 +51,7 @@ _BATHROOMS_CONF = {
     None: 0.7,
     1: 0.5,
     2: 1,
-    5: 1,
+    4: 1,
 }
 
 # disabled
@@ -58,8 +61,8 @@ _COMMUTE_CONF = {
 }
 
 _PRICE_CONF = {
-    400: 1,
-    800: 0.6,
+    300: 1,
+    900: 0.6,
 }
 
 _RERANKING_CONF = {

+ 3 - 2
visualize.py

@@ -5,6 +5,7 @@ import geo_util
 import properties
 import ranking
 import util
+import datetime
 
 def _write_bboxes(f):
     f.write('''
@@ -51,7 +52,6 @@ def _write_properties(f, properties_dict, tmp_ids):
 
     properties_list = list(properties_dict.items())
     properties_list.sort(key=lambda x: x[1]['score'], reverse=True)
-    # properties_list = properties_list[:1000]
 
     min_score = max(0, min(x['score'] for x in properties_dict.values()))
     max_score = max(x['score'] for x in properties_dict.values())
@@ -127,7 +127,8 @@ def _set_tmp_ids(properties_dict):
     return res
 
 def run():
-    properties_dict = properties.load_properties()
+    load_since = datetime.datetime.now() - datetime.timedelta(days=180)
+    properties_dict = properties.load_properties(True, load_since)
     print('Loaded %i properties' % len(properties_dict))
 
     commutes = None