From 07e1c7a1dcc68d21dbc2d8c3a49a7816a05ea647 Mon Sep 17 00:00:00 2001 From: Johnson Chetty Date: Tue, 14 Feb 2012 13:43:52 +0100 Subject: [PATCH] minor edits to data_mapper and postload --- chaloBEST/imports/data_mapper.py | 33 +++++++-------------------- chaloBEST/imports/postload_cleanup.py | 11 ++++----- 2 files changed, 13 insertions(+), 31 deletions(-) diff --git a/chaloBEST/imports/data_mapper.py b/chaloBEST/imports/data_mapper.py index 95ff606..f25b718 100644 --- a/chaloBEST/imports/data_mapper.py +++ b/chaloBEST/imports/data_mapper.py @@ -6,7 +6,7 @@ import json import datetime import sys from django.contrib.gis.geos import Point -from imports.import_atlas import getFromToStopsForRoute +from imports.import_atlas import getFromToStopsForRoute, importUniqueRoutes globalerr = [] def RouteType_save(entry): @@ -14,27 +14,6 @@ def RouteType_save(entry): obj.save() #print obj.__dict__ -def importRouteMaster(): - CsvFile = csv.reader(open(join(PROJECT_ROOT, "../db_csv_files/RouteMaster.csv"), "r"), delimiter=',') - test = CsvFile.next() - stop_errors = [] - print test - for row in CsvFile: - if len(row) < 1: - continue - from_to = getFromToStopsForRoute(row[0]) - if from_to is None: - stop_errors.append(row[0]) - continue - print row[0] - obj = Route(code=row[0], alias=row[1], from_stop_txt=row[2], to_stop_txt=row[3], from_stop=from_to[0], to_stop=from_to[1], distance=row[4], stages=int(row[5])) - obj.save() - errors = open(join(PROJECT_ROOT, "../errors/routeStopErrors.json"), "w") - errors.write(json.dumps(stop_errors, indent=2)) - errors.close() - - - def Route_save(entry): """ try: @@ -227,7 +206,7 @@ def loadFKinRouteDetail(): rd.route=None err.append({"data":rd.route_code, "error":["Route Not Found in Route"]}) - errors = open(join(PROJECT_ROOT, "../errors/RouteNotFoundErrors.json"), "w") + #errors = open(join(PROJECT_ROOT, "../errors/RouteNotFoundErrors.json"), "w") size = len(err) print "No. of Routes in RouteDetail mapped to Route: " , str(good_saves) print "No. of Routes in RouteDetail not mapped to Route: " , str(size) @@ -235,8 +214,9 @@ def loadFKinRouteDetail(): if (size != 0) : print "See /errors/RouteNotFoundErrors.json for details" - errors.write(json.dumps(err, indent=2)) - errors.close() + #errors.write(json.dumps(err, indent=2)) + #errors.close() + return err @@ -284,6 +264,9 @@ def fire_up(): CsvLoader(model) loadFKinRouteDetail() + # also + #importUniqueRoutes() + #---------------------------------------------------------- diff --git a/chaloBEST/imports/postload_cleanup.py b/chaloBEST/imports/postload_cleanup.py index c183648..8c62d44 100644 --- a/chaloBEST/imports/postload_cleanup.py +++ b/chaloBEST/imports/postload_cleanup.py @@ -1,8 +1,6 @@ from mumbai.models import * - -"Road, Area, Landmark, Stop" - +#"Road, Area, Landmark, Stop" def copynames2display_name(): for obj in Stop.objects.all(): obj.display_name =obj.name @@ -18,7 +16,8 @@ def copynames2display_name(): obj.save() def copydefaultStopLocations(): - for stop in Stop.objects.all(): - stop.stop = stop.stoplocation_set.all()[0] - + for stp in Stop.objects.all(): + if stp.stoplocation_set.count()>0 : + stp.point = stp.stoplocation_set.all()[0].point + stp.save()