From b48f2ddb3d200d43d64e9c1a5e7e49b8669ab93c Mon Sep 17 00:00:00 2001 From: Sanj Date: Fri, 30 Mar 2012 17:22:25 +0530 Subject: [PATCH] fix_missing, stopedits tweak + models --- chaloBEST/imports/fix_missing_atlas_data.py | 15 +++++++++------ chaloBEST/imports/import_atlas.py | 9 +++------ chaloBEST/mumbai/models.py | 9 ++++----- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/chaloBEST/imports/fix_missing_atlas_data.py b/chaloBEST/imports/fix_missing_atlas_data.py index 524c9df..3d21804 100644 --- a/chaloBEST/imports/fix_missing_atlas_data.py +++ b/chaloBEST/imports/fix_missing_atlas_data.py @@ -1,5 +1,5 @@ from mumbai.models import * - +import pdb # FIXME: UniqueRoute stringification, routes 314 and 9 def fix_distances(): @@ -32,13 +32,15 @@ def fix_distances(): last_stop_passed = True # is a stage - if record and detail.km: + if record: if not last_stop_passed: # add it - distance += float(detail.km) + if detail.km: + distance += float(detail.km) else: # 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 last_stop_passed = True break @@ -53,9 +55,10 @@ def fix_distances(): if detail.stop.id == from_stop: record = True 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: - 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): unique_route.distance = distance unique_route.save() diff --git a/chaloBEST/imports/import_atlas.py b/chaloBEST/imports/import_atlas.py index 43adee3..3590d23 100644 --- a/chaloBEST/imports/import_atlas.py +++ b/chaloBEST/imports/import_atlas.py @@ -53,17 +53,14 @@ def processJSON(): outDict[key] = [] for row in thisRoute: # pdb.set_trace() - if len(row) < 7: - routeErrors['others'].append({key: row}) - break - for i in range(2,5): + for i in range(2,5): # AM, N, PM if row[i].strip() == '': row[i] = previousRow[i] - for i in [7,10]: + for i in [7,10]: # From, To if row[i].strip() == '': row[i] = previousRow[i] try: - if row[-5].strip() == '': + if row[-5].strip() == '': #FIXME: change this to a positive index row[-5] = previousRow[-5] #-5 is Schedule Type except: pdb.set_trace() diff --git a/chaloBEST/mumbai/models.py b/chaloBEST/mumbai/models.py index 9f9f4cd..36a325b 100644 --- a/chaloBEST/mumbai/models.py +++ b/chaloBEST/mumbai/models.py @@ -138,8 +138,7 @@ class Stop(models.Model): road = models.ForeignKey(Road, 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) - 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) alt_names = generic.GenericRelation("AlternativeName") @@ -180,7 +179,9 @@ class Stop(models.Model): def from_geojson(self, geojson, srid=4326): geom = geojson['geometry']['coordinates'] 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.name_mr = data['name_mr'] 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.save() self.alt_names.add(alt_name) - - #FIXME: add alt names logic self.save() return self.get_geojson(srid=srid)