gtfs files update v5

This commit is contained in:
Johnson Chetty 2012-02-21 11:35:39 +01:00
commit d0938783f1
4 changed files with 80 additions and 5 deletions

View File

@ -6,9 +6,15 @@ import csv
import sys import sys
def routeWithLocationData(route): def routeWithLocationData(route):
'''
tests a route if it has stop location data for each stop on the route.
'''
# get the route detail # get the route detail
routeDetails = RouteDetail.objects.filter(route_code=route.code).order_by('serial') routeDetails = RouteDetail.objects.filter(route_code=route.code).order_by('serial')
#unrlist = UniqueRoute.objects.filter('route'=route)
#for unr in unrlist:
for rd in routeDetails : for rd in routeDetails :
if rd.stop.point is None: if rd.stop.point is None:
return False return False
@ -17,6 +23,9 @@ def routeWithLocationData(route):
return True return True
def getRoutesHavingAllLocs(): def getRoutesHavingAllLocs():
'''
gets routes having stop location data for each stop on the route.
'''
filteredroutes = [] filteredroutes = []
for route in Route.objects.all(): for route in Route.objects.all():
if routeWithLocationData(route): if routeWithLocationData(route):
@ -25,6 +34,46 @@ def getRoutesHavingAllLocs():
return filteredroutes return filteredroutes
def routeWithSomeLocationData(route,limit):
'''
Gets stoplist for a route which has at most <limit> no of stops without location data.
'''
# Get the route details
routeDetails = RouteDetail.objects.filter(route_code=route.code).order_by('serial')
# check for routes having less than three errors in stops, and send stops back.
stoplist =[]
errs = 0
for rd in routeDetails:
if rd.stop.point is None:
# stop does not have point
errs+=1
if errs <= limit :
stoplist.append(rd.stop.code)
else:
pass
if errs <=limit:
return dict({'route':route, 'neededstops':stoplist, })
else:
return None
def getRoutesHavingSomeLocs(limit):
'''
Gets those routes which have at most <limit> no of stops without location data.
'''
filteredroutes = []
no_of_routes = 0
for route in Route.objects.all():
data= routeWithSomeLocationData(route, limit)
if data:
no_of_routes+=1
filteredroutes.append(data)
print "No of routes::",no_of_routes
return filteredroutes
def export_routes(routebeer): def export_routes(routebeer):
#routebeer = getRoutesHavingAllLocs() #routebeer = getRoutesHavingAllLocs()
filedude = csv.writer(open(join(PROJECT_ROOT, "gtfs/routes.txt"), "w"), delimiter=",") filedude = csv.writer(open(join(PROJECT_ROOT, "gtfs/routes.txt"), "w"), delimiter=",")
@ -126,7 +175,7 @@ def export_trips():
# we need to get UniqueRoutes for each route, that is one trip, since it is based on service_id which shows days_of_run. # we need to get UniqueRoutes for each route, that is one trip, since it is based on service_id which shows days_of_run.
# we need to be careful here because a filter queryset for UniqueRoutes can differ in order and a naming based on this order # we need to be careful here because a filter queryset for UniqueRoutes can differ in order and a naming based on this order
# will not be consistent. Its good to use a uniqueroute-serial number. # will not be consistent. Its good to use a uniqueroute-serial number.
for r in routelist: #for r in routelist:
""" """
try: try:
# data checks here # data checks here

View File

@ -0,0 +1 @@
"[{'route': <Route: 248>, 'neededstops': [<Stop: ANDHERI BUS STN.(W)>, <Stop: GEETANJALI>]}, {'route': <Route: 264>, 'neededstops': [<Stop: GANDBHIR VIDYALAYA>, <Stop: THAKUR NGR.(CAVES RD.)>]}, {'route': <Route: 282>, 'neededstops': []}, {'route': <Route: 289RING>, 'neededstops': []}, {'route': <Route: 338>, 'neededstops': [<Stop: GARWARE CHK./ KOLDONGRI NO.2>, <Stop: SAHAR P.& T.CLY.NO 2>, <Stop: SAHAR CARGO COMPLEX>]}, {'route': <Route: 378>, 'neededstops': [<Stop: TROMBAY>, <Stop: DHOBI GHAT(TROMBAY)>, <Stop: MANKHURD STN.(SOUTH)>]}, {'route': <Route: 413>, 'neededstops': [<Stop: KUNCHI KURVE NGR.>, <Stop: ST.PIUS SCHOOL>, <Stop: KALINA MARKET>]}, {'route': <Route: 443>, 'neededstops': [<Stop: ASHOK NGR.>]}, {'route': <Route: 601>, 'neededstops': [<Stop: MALAD STN-E(PODDAR PARK)>, <Stop: TAPOVAN ( PATHANWADI)>, <Stop: VADARPADA>]}, {'route': <Route: 611>, 'neededstops': [<Stop: MALAD STN-E(PODDAR PARK)>, <Stop: TAPOVAN ( PATHANWADI)>, <Stop: SANJAY NGR.>]}, {'route': <Route: 618RING>, 'neededstops': [<Stop: MUNICIPAL DISP.>]}, {'route': <Route: 624>, 'neededstops': [<Stop: MALAD STN-E(PODDAR PARK)>, <Stop: OLD PUSHPA PARK>]}, {'route': <Route: 631>, 'neededstops': [<Stop: MEHTAB LANE(KURLA MARKET)>, <Stop: RAHAT APT.S>, <Stop: MASRANI EST.>]}, {'route': <Route: 8126>, 'neededstops': [<Stop: CHH. SHIVAJI TERMINUS>, <Stop: CHH. SHIVAJI TERMINUS>]}, {'route': <Route: 8136>, 'neededstops': [<Stop: CHH. SHIVAJI TERMINUS>, <Stop: CHH. SHIVAJI TERMINUS>]}]"

View File

@ -160,17 +160,39 @@ def AreaMarathi_save(entry):
obj.save() obj.save()
#print obj.__dict__ #print obj.__dict__
loc1s = 0
loc2s = 0
class NoPointsFoundError(Exception):
pass
def StopLocation_save(entry): def StopLocation_save(entry):
this_stop = Stop.objects.get(code=int(entry[4])) this_stop = Stop.objects.get(code=int(entry[4]))
#hits = {'one':[],'two':[],'three':[],'four':[]}
flagerr = 0
if entry[0] and entry[1]: if entry[0] and entry[1]:
loc1 = StopLocation(stop=this_stop, point=Point(float(entry[1]), float(entry[0])),direction='U' ) loc1 = StopLocation(stop=this_stop, point=Point(float(entry[1]), float(entry[0])),direction='U' )
loc1.save() loc1.save()
#loc1s+=1
else:
flagerr=1
if entry[2] and entry[3]: if entry[2] and entry[3]:
loc2 = StopLocation(stop=this_stop, point=Point(float(entry[3]), float(entry[2])),direction='D' ) loc2 = StopLocation(stop=this_stop, point=Point(float(entry[3]), float(entry[2])),direction='D' )
loc2.save() loc2.save()
#loc2s+=1
else:
flagerr+=1
if flagerr == 2:
flagerr = 0
raise NoPointsFoundError
#print "Loc1s found : ", loc1s
#print "Loc2s found : ", loc2s

View File

@ -19,7 +19,10 @@ def csvToJSON():
routeNo = a[1].strip() routeNo = a[1].strip()
# print a # print a
if routeNo != '': if routeNo != '':
atlasDict[routeNo] = [a] if atlasDict.has_key(routeNo):
atlasDist[routeNo].append(a)
else:
atlasDict[routeNo] = [a]
previousRoute = routeNo previousRoute = routeNo
else: else:
atlasDict[previousRoute].append(a) atlasDict[previousRoute].append(a)
@ -58,7 +61,7 @@ def processJSON():
row[i] = previousRow[i] row[i] = previousRow[i]
try: try:
if row[-5].strip() == '': if row[-5].strip() == '':
row[-5] = previousRow[-5] row[-5] = previousRow[-5] #What is -5 ?
except: except:
pdb.set_trace() pdb.set_trace()
previousRow = row previousRow = row
@ -238,8 +241,8 @@ def noneInt(val):
''' '''
Passed a route code, it gets stop codes for the first and last stop Passed a route code, it gets stop codes for the first and last stop
''' '''
def getFromToStopsForRoute(routeId): def getFromToStopsForRoute(route):
routeDetails = RouteDetail.objects.filter(route_code=routeId).order_by('serial') routeDetails = RouteDetail.objects.filter(route=route).order_by('serial')
if routeDetails.count() == 0: if routeDetails.count() == 0:
return None return None
fromStop = routeDetails[0].stop fromStop = routeDetails[0].stop