fix_missing, stopedits tweak + models

This commit is contained in:
Sanj 2012-03-30 17:22:25 +05:30
parent 93aa6eab81
commit b48f2ddb3d
3 changed files with 16 additions and 17 deletions

View File

@ -1,5 +1,5 @@
from mumbai.models import * from mumbai.models import *
import pdb
# FIXME: UniqueRoute stringification, routes 314 and 9 # FIXME: UniqueRoute stringification, routes 314 and 9
def fix_distances(): def fix_distances():
@ -32,13 +32,15 @@ def fix_distances():
last_stop_passed = True last_stop_passed = True
# is a stage # is a stage
if record and detail.km: if record:
if not last_stop_passed: if not last_stop_passed:
# add it # add it
distance += float(detail.km) if detail.km:
distance += float(detail.km)
else: else:
# if stage having km info reached after last stop, then add and exit loop # if stage having km info reached after last stop, then add and exit loop
distance += float(detail.km) if detail.km:
distance += float(detail.km)
record=False record=False
last_stop_passed = True last_stop_passed = True
break break
@ -53,9 +55,10 @@ def fix_distances():
if detail.stop.id == from_stop: record = True if detail.stop.id == from_stop: record = True
if record: if record:
print Exception("UniqueRoute %s from %s to %s ran off the end while measuring distance!" %(unique_route, unique_route.from_stop.code, unique_route.to_stop.code)) #pdb.set_trace()
print Exception("UniqueRoute %d: %s from %s to %s ran off the end while measuring distance!" %(unique_route.id, unique_route, unique_route.from_stop.code, unique_route.to_stop.code))
if not distance: if not distance:
print Exception("UniqueRoute %s from %s to %s still has no distance!" % (unique_route, unique_route.from_stop.code, unique_route.to_stop.code)) print Exception("UniqueRoute %d: %s from %s to %s still has no distance!" % (unique_route.id, unique_route, unique_route.from_stop.code, unique_route.to_stop.code))
if distance > float(unique_route.distance): if distance > float(unique_route.distance):
unique_route.distance = distance unique_route.distance = distance
unique_route.save() unique_route.save()

View File

@ -53,17 +53,14 @@ def processJSON():
outDict[key] = [] outDict[key] = []
for row in thisRoute: for row in thisRoute:
# pdb.set_trace() # pdb.set_trace()
if len(row) < 7: for i in range(2,5): # AM, N, PM
routeErrors['others'].append({key: row})
break
for i in range(2,5):
if row[i].strip() == '': if row[i].strip() == '':
row[i] = previousRow[i] row[i] = previousRow[i]
for i in [7,10]: for i in [7,10]: # From, To
if row[i].strip() == '': if row[i].strip() == '':
row[i] = previousRow[i] row[i] = previousRow[i]
try: try:
if row[-5].strip() == '': if row[-5].strip() == '': #FIXME: change this to a positive index
row[-5] = previousRow[-5] #-5 is Schedule Type row[-5] = previousRow[-5] #-5 is Schedule Type
except: except:
pdb.set_trace() pdb.set_trace()

View File

@ -138,8 +138,7 @@ class Stop(models.Model):
road = models.ForeignKey(Road, default=None, null=True, blank=True) road = models.ForeignKey(Road, default=None, null=True, blank=True)
area = models.ForeignKey(Area, default=None, null=True, blank=True) area = models.ForeignKey(Area, default=None, null=True, blank=True)
depot = models.ForeignKey("Depot", default=None, null=True, blank=True, related_name="is_depot_for") #models.CharField(null=True, blank=True, max_length=5) depot = models.ForeignKey("Depot", default=None, null=True, blank=True, related_name="is_depot_for") #models.CharField(null=True, blank=True, max_length=5)
name_mr= models.TextField(null=True, blank=True, max_length=512)#null=True, name_mr= models.TextField(null=True, blank=True, max_length=512)#null=True
point = models.PointField(null=True) point = models.PointField(null=True)
alt_names = generic.GenericRelation("AlternativeName") alt_names = generic.GenericRelation("AlternativeName")
@ -180,7 +179,9 @@ class Stop(models.Model):
def from_geojson(self, geojson, srid=4326): def from_geojson(self, geojson, srid=4326):
geom = geojson['geometry']['coordinates'] geom = geojson['geometry']['coordinates']
data = geojson['properties'] data = geojson['properties']
self.point = Point(geom[0], geom[1], srid=srid).transform(4326, True) #FIXME: srid should be passed as param point = Point(geom[0], geom[1], srid=srid).transform(4326, True)
if point:
self.point = point
self.display_name = data['display_name'] self.display_name = data['display_name']
self.name_mr = data['name_mr'] self.name_mr = data['name_mr']
if data.has_key('alternative_names') and data['alternative_names'].strip() != '': if data.has_key('alternative_names') and data['alternative_names'].strip() != '':
@ -193,8 +194,6 @@ class Stop(models.Model):
alt_name.content_object = self alt_name.content_object = self
alt_name.save() alt_name.save()
self.alt_names.add(alt_name) self.alt_names.add(alt_name)
#FIXME: add alt names logic
self.save() self.save()
return self.get_geojson(srid=srid) return self.get_geojson(srid=srid)