gtfs files update v5
This commit is contained in:
commit
d0938783f1
|
@ -6,9 +6,15 @@ import csv
|
|||
import sys
|
||||
|
||||
def routeWithLocationData(route):
|
||||
'''
|
||||
tests a route if it has stop location data for each stop on the route.
|
||||
'''
|
||||
# get the route detail
|
||||
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 :
|
||||
if rd.stop.point is None:
|
||||
return False
|
||||
|
@ -17,6 +23,9 @@ def routeWithLocationData(route):
|
|||
return True
|
||||
|
||||
def getRoutesHavingAllLocs():
|
||||
'''
|
||||
gets routes having stop location data for each stop on the route.
|
||||
'''
|
||||
filteredroutes = []
|
||||
for route in Route.objects.all():
|
||||
if routeWithLocationData(route):
|
||||
|
@ -25,6 +34,46 @@ def getRoutesHavingAllLocs():
|
|||
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):
|
||||
#routebeer = getRoutesHavingAllLocs()
|
||||
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 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.
|
||||
for r in routelist:
|
||||
#for r in routelist:
|
||||
"""
|
||||
try:
|
||||
# data checks here
|
||||
|
|
1
chaloBEST/gtfs/neededStopLocations.json
Normal file
1
chaloBEST/gtfs/neededStopLocations.json
Normal 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>]}]"
|
|
@ -160,17 +160,39 @@ def AreaMarathi_save(entry):
|
|||
obj.save()
|
||||
#print obj.__dict__
|
||||
|
||||
loc1s = 0
|
||||
loc2s = 0
|
||||
|
||||
class NoPointsFoundError(Exception):
|
||||
pass
|
||||
|
||||
def StopLocation_save(entry):
|
||||
this_stop = Stop.objects.get(code=int(entry[4]))
|
||||
|
||||
#hits = {'one':[],'two':[],'three':[],'four':[]}
|
||||
|
||||
flagerr = 0
|
||||
|
||||
if entry[0] and entry[1]:
|
||||
loc1 = StopLocation(stop=this_stop, point=Point(float(entry[1]), float(entry[0])),direction='U' )
|
||||
loc1.save()
|
||||
#loc1s+=1
|
||||
else:
|
||||
flagerr=1
|
||||
|
||||
if entry[2] and entry[3]:
|
||||
loc2 = StopLocation(stop=this_stop, point=Point(float(entry[3]), float(entry[2])),direction='D' )
|
||||
loc2.save()
|
||||
#loc2s+=1
|
||||
else:
|
||||
flagerr+=1
|
||||
|
||||
if flagerr == 2:
|
||||
flagerr = 0
|
||||
raise NoPointsFoundError
|
||||
|
||||
#print "Loc1s found : ", loc1s
|
||||
#print "Loc2s found : ", loc2s
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -19,6 +19,9 @@ def csvToJSON():
|
|||
routeNo = a[1].strip()
|
||||
# print a
|
||||
if routeNo != '':
|
||||
if atlasDict.has_key(routeNo):
|
||||
atlasDist[routeNo].append(a)
|
||||
else:
|
||||
atlasDict[routeNo] = [a]
|
||||
previousRoute = routeNo
|
||||
else:
|
||||
|
@ -58,7 +61,7 @@ def processJSON():
|
|||
row[i] = previousRow[i]
|
||||
try:
|
||||
if row[-5].strip() == '':
|
||||
row[-5] = previousRow[-5]
|
||||
row[-5] = previousRow[-5] #What is -5 ?
|
||||
except:
|
||||
pdb.set_trace()
|
||||
previousRow = row
|
||||
|
@ -238,8 +241,8 @@ def noneInt(val):
|
|||
'''
|
||||
Passed a route code, it gets stop codes for the first and last stop
|
||||
'''
|
||||
def getFromToStopsForRoute(routeId):
|
||||
routeDetails = RouteDetail.objects.filter(route_code=routeId).order_by('serial')
|
||||
def getFromToStopsForRoute(route):
|
||||
routeDetails = RouteDetail.objects.filter(route=route).order_by('serial')
|
||||
if routeDetails.count() == 0:
|
||||
return None
|
||||
fromStop = routeDetails[0].stop
|
||||
|
|
Loading…
Reference in New Issue
Block a user