From ea2de8d494b530e68f73a78847de1645b7eefc32 Mon Sep 17 00:00:00 2001 From: Johnson Chetty Date: Wed, 15 Feb 2012 14:46:24 +0100 Subject: [PATCH] gtfs v 1 --- chaloBEST/gtfs/__init__.py | 0 chaloBEST/gtfs/fstops.json | 0 chaloBEST/gtfs/gtfs_export.py | 34 +++++++++++++++++++++++++++ chaloBEST/gtfs/routes.txt | 1 + chaloBEST/gtfs/stops.txt | 1 + chaloBEST/imports/data_mapper.py | 14 +++++++---- chaloBEST/imports/postload_cleanup.py | 29 +++++++++++++++++++++++ 7 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 chaloBEST/gtfs/__init__.py create mode 100644 chaloBEST/gtfs/fstops.json create mode 100644 chaloBEST/gtfs/gtfs_export.py create mode 100644 chaloBEST/gtfs/routes.txt create mode 100644 chaloBEST/gtfs/stops.txt diff --git a/chaloBEST/gtfs/__init__.py b/chaloBEST/gtfs/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/chaloBEST/gtfs/fstops.json b/chaloBEST/gtfs/fstops.json new file mode 100644 index 0000000..e69de29 diff --git a/chaloBEST/gtfs/gtfs_export.py b/chaloBEST/gtfs/gtfs_export.py new file mode 100644 index 0000000..b0ab62b --- /dev/null +++ b/chaloBEST/gtfs/gtfs_export.py @@ -0,0 +1,34 @@ + +from mumbai.models import * + + +routebeer = [] + + +def routeWithLocationData(route): + # get the route detail + routeDetails = RouteDetail.objects.filter(route_code=route.code).order_by('serial') + + for rd in routeDetails : + if rd.stop.point is None: + return False + else: + pass + return True + +def getRoutesHavingAllLocs(): + filteredroutes = [] + for route in Route.objects.all(): + if routeWithLocationData(route): + filteredroutes.append(route) + + return filteredroutes + + +def export_routes(): + pointstoplist = Stop.objects.filter(point__isnull=False) + + for rd in RouteDetail.objects.all(): + if rd.stop in pointstoplist : + routebeer.append(rd) + diff --git a/chaloBEST/gtfs/routes.txt b/chaloBEST/gtfs/routes.txt new file mode 100644 index 0000000..5942e22 --- /dev/null +++ b/chaloBEST/gtfs/routes.txt @@ -0,0 +1 @@ +route_id,route_short_name,route_long_name,route_type \ No newline at end of file diff --git a/chaloBEST/gtfs/stops.txt b/chaloBEST/gtfs/stops.txt new file mode 100644 index 0000000..2aa0487 --- /dev/null +++ b/chaloBEST/gtfs/stops.txt @@ -0,0 +1 @@ +s,t,o,p,_,i,d,",",s,t,o,p,_,n,a,m,e,",",s,t,o,p,_,l,a,t,",",s,t,o,p,_,l,o,n diff --git a/chaloBEST/imports/data_mapper.py b/chaloBEST/imports/data_mapper.py index f25b718..c5bdb9f 100644 --- a/chaloBEST/imports/data_mapper.py +++ b/chaloBEST/imports/data_mapper.py @@ -7,6 +7,7 @@ import datetime import sys from django.contrib.gis.geos import Point from imports.import_atlas import getFromToStopsForRoute, importUniqueRoutes +from imports import postload_cleanup as postclean globalerr = [] def RouteType_save(entry): @@ -173,7 +174,7 @@ def StopLocation_save(entry): -saveorder = ["Fare","Holiday","Area","Road","Depot","Stop", "StopMarathi","AreaMarathi","RouteDetail", "Route","RouteType","HardCodedRoute"] +saveorder = ["Fare","Holiday","Area","Road","Depot","Stop", "StopMarathi","AreaMarathi","RouteDetail", "Route","RouteType","HardCodedRoute","StopLocation" ] mappingtosave = { "Fare":Fare_save, @@ -196,7 +197,7 @@ mappingtosave = { def loadFKinRouteDetail(): err=[] good_saves = 0 - print "\n Loading foreign keys into Route Details ... " + print "\nLoading foreign keys into Route Details ... " for rd in RouteDetail.objects.all(): try: rd.route=Route.objects.get(code=rd.route_code) @@ -264,10 +265,13 @@ def fire_up(): CsvLoader(model) loadFKinRouteDetail() + # also - #importUniqueRoutes() - - + importUniqueRoutes() + print "loading UniqueRoute..." + postclean.copydefaultStopLocations() + postclean.copynames2display_name() + #---------------------------------------------------------- """ diff --git a/chaloBEST/imports/postload_cleanup.py b/chaloBEST/imports/postload_cleanup.py index 8c62d44..dc3df12 100644 --- a/chaloBEST/imports/postload_cleanup.py +++ b/chaloBEST/imports/postload_cleanup.py @@ -2,6 +2,7 @@ from mumbai.models import * #"Road, Area, Landmark, Stop" def copynames2display_name(): + print "Copying names to display_name field..." for obj in Stop.objects.all(): obj.display_name =obj.name obj.save() @@ -16,8 +17,36 @@ def copynames2display_name(): obj.save() def copydefaultStopLocations(): + print "Loading default locations for Stop.point field..." for stp in Stop.objects.all(): if stp.stoplocation_set.count()>0 : stp.point = stp.stoplocation_set.all()[0].point stp.save() +""" +def addStopstoRoutes(): + print "Getting stops linked to Routes..." + for r in Route.objects.all(): + try: + r.stop = Stop.objects.get(name=) +""" + +def routeWithLocationData(route): + # get the route detail + routeDetails = RouteDetail.objects.filter(route_code=route.code).order_by('serial') + + for rd in routeDetails : + if rd.stop.point is None: + return False + else: + pass + + return True + +def getRoutes_w_loc(): + filteredroutes = [] + for route in Route.objects.all(): + if routeWithLocationData(route): + filteredroutes.append(route) + + return filteredroutes