Skip to content

Commit

Permalink
Fixed IE by limiting results.
Browse files Browse the repository at this point in the history
  • Loading branch information
roi committed Aug 18, 2011
1 parent 374623c commit e130f90
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 15 deletions.
28 changes: 18 additions & 10 deletions backend/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,10 @@ class RentReport(models.Model):
lng = models.FloatField( null = True )
lat = models.FloatField( null = True )


class MobileFullReport(models.Model):
address = models.CharField(max_length=100,blank=False,null=False)
number = models.IntegerField()
lon = models.FloatField()
lat = models.FloatField()
real_loc = models.BooleanField(default=True)

class SingleRank(models.Model):
is_boolean=models.BooleanField(default=False)
owner_report = models.ForeignKey(MobileFullReport)
id = models.IntegerField(default=0)
owner_report = models.ForeignKey('MobileFullReport')
rid = models.IntegerField(default=0)
ranks_sum = models.IntegerField(default=0)
num_of_ranks = models.IntegerField(default=0)

Expand All @@ -41,6 +33,22 @@ def getRank(self):
else:
return self.ranks_sum / self.num_of_ranks

class MobileFullReport(models.Model):
address = models.CharField(max_length=100,blank=False,null=False)
number = models.IntegerField()
lon = models.FloatField()
lat = models.FloatField()
real_loc = models.BooleanField(default=True)

def getSimpleObject(self):
ranks=[ (i.rid, i.getRank() ) for i in list(SingleRank.objects.filter(owner_report=self) ) ]
self.ranks=ranks
return self








Expand Down
10 changes: 10 additions & 0 deletions backend/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from math import sqrt
from django.http import HttpResponse
from models import RentReport
from google.appengine.api.urlfetch import Fetch
import settings
import logging
from models import MobileFullReport
import urllib
try:
import json
Expand Down Expand Up @@ -96,6 +98,14 @@ def makeQuery(request):
resp=resp+" -1"
return HttpResponse(resp)

def getNearBy(request):
lon=request.POST.get('lon')
lat=request.POST.get('lat')
report_list=[ (i.getSimpleObject() ) for i in list( MobileFullReport.objects.all() ) ]
report_list=sorted( report_list, key=lambda report: sqrt( pow(report.lon - lon , 2) + pow(report.lat - lat , 2) ) )
report_list=report_list[:settings.MAX_NEAR_ITEMS]
return HttpResponse(json.dumps(report_list))

def update_mobile(request):
logging.info("POST:"+str(request.POST))
return HttpResponse('ok')
Expand Down
8 changes: 4 additions & 4 deletions frontend/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ <h1>בעל הבית השתגע?</h1>
<br>
<br>
<div class="error" style="color:RED;"></div>
<img src="img/submit_button.png" class="pointer center" onclick="submit_new_rent()"/>
<img src="img/submit_button.png" class="pointer center" onclick="submit_new_up_rent()"/>
</div>

<div id='rent_down_dialog'>
Expand Down Expand Up @@ -247,7 +247,7 @@ <h1>בעל הבית השתגע?</h1>
<br>
<br>
<div class="error" style="color:RED; width:120px" ></div>
<img src="img/submit_button.png" class="pointer center" onclick="submit_new_rent()"/>
<img src="img/submit_button.png" class="pointer center" onclick="submit_new_low_rent()"/>
</div>

<div id='check_dialog'>
Expand Down Expand Up @@ -359,7 +359,7 @@ <h1>בעל הבית השתגע?</h1>

{% block js %}
<script type="text/javascript">
function submit_new_rent(id){
function submit_new_up_rent(id){
var city=$('#up_city_in').val();
var street=$('#up_street_in').val();
var apr=$('#up_apr_in').val();
Expand Down Expand Up @@ -506,7 +506,7 @@ <h1>בעל הבית השתגע?</h1>
});
{% for r in BAD_LIST%}

addMarker( {{r.lng}} , {{r.lat}} ,'{{r.street}}','{{r.address}}', '{{r.old_price}}' ,'{{r.new_price}}',{{ r.apartment }},{{ r.num_of_rooms }});
addMarker( {{r.lng}} , {{r.lat}} ,'{{r.street}}','{{r.address}}', '{{r.old_price}}' ,'{{r.new_price}}','{{ r.apartment }}',{{ r.num_of_rooms }});

{%endfor%}

Expand Down
3 changes: 3 additions & 0 deletions frontend/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.shortcuts import render_to_response,redirect
from backend.models import RentReport
import settings

def getMapArgs():
good=[] #list(RentReport.objects.filter(price_up=False))
Expand All @@ -14,6 +15,8 @@ def getMapArgs():
for r in bad:
if r.lat and r.lng:
bad_list.append(r)
bad_list=sorted(bad_list,key=lambda report: report.new_price-report.old_price,reverse=True)
bad_list=bad_list[:settings.MAX_MARKERS]
args={
'GOOD_LIST':good_list,
'BAD_LIST':bad_list
Expand Down
5 changes: 4 additions & 1 deletion settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,7 @@
( 'Q2' , 'Does it have a roof?' , True) ,
( 'Q3' , 'Can you see the moon on a bright night?', True) ,
( 'Q4' , 'How good is it?' , False )
]
]

MAX_MARKERS=300
MAX_NEAR_ITEMS = 150

0 comments on commit e130f90

Please sign in to comment.