소스 검색

always load favourites

Martin 5 년 전
부모
커밋
7dac3b6830
2개의 변경된 파일과 19개의 추가작업 그리고 7개의 파일을 삭제
  1. 9 3
      properties.py
  2. 10 4
      visualize.py

+ 9 - 3
properties.py

@@ -5,8 +5,13 @@ import config
 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))
+        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 = {}
         for property_id, lat, lon, size, price, bedrooms, ber, bathrooms, property_type in rows:
@@ -34,6 +39,7 @@ def load_properties(require_active, require_update_since):
                 'price_history': [],
                 'ber': ber,
                 'type': property_type,
+                'favourite': property_id in favourites,
             }
 
         rows = conn.select('select time, property_id, price from search_results order by time asc')
@@ -41,7 +47,7 @@ def load_properties(require_active, require_update_since):
             if pid not in res:
                 continue
 
-            if time < ts:
+            if pid not in favourites and time < ts:
                 del res[pid]
                 continue
 

+ 10 - 4
visualize.py

@@ -34,6 +34,8 @@ def _write_styles(f):
             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-green"><IconStyle><color>ff00ff00</color></IconStyle></Style>\n')
+
 def _write_commutes(f, commutes):
     f.write('<Folder><name>Commutes</name><visibility>0</visibility>\n')
     max_duration = min(4000, max([x['duration'] for x in commutes.values()]))
@@ -60,9 +62,13 @@ def _write_properties(f, properties_dict, tmp_ids):
     min_max_delta = max_score - min_score
 
     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])
 
@@ -85,7 +91,7 @@ def _write_properties(f, properties_dict, tmp_ids):
 
         f.write('''<Placemark>
             <Point><coordinates>%f,%f</coordinates></Point>
-            <styleUrl>#color-%i</styleUrl>
+            <styleUrl>#color-%s</styleUrl>
             <name>%s</name>
             <description><![CDATA[ %s ]]></description>
         </Placemark>\n''' % (data['loc'][1], data['loc'][0], color, title, description))