merge..
This commit is contained in:
commit
229048aa23
|
@ -4,6 +4,7 @@ from settings import *
|
||||||
from os.path import join
|
from os.path import join
|
||||||
import csv
|
import csv
|
||||||
import sys
|
import sys
|
||||||
|
import datetime
|
||||||
|
|
||||||
def routeWithLocationData(route):
|
def routeWithLocationData(route):
|
||||||
'''
|
'''
|
||||||
|
@ -11,7 +12,6 @@ def routeWithLocationData(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)
|
#unrlist = UniqueRoute.objects.filter('route'=route)
|
||||||
#for unr in unrlist:
|
#for unr in unrlist:
|
||||||
|
|
||||||
|
@ -33,6 +33,15 @@ def getRoutesHavingAllLocs():
|
||||||
|
|
||||||
return filteredroutes
|
return filteredroutes
|
||||||
|
|
||||||
|
def getCompleteRoutes():
|
||||||
|
#rs = getRoutesHavingAllLocs()
|
||||||
|
filteredroutes = []
|
||||||
|
for route in rs:
|
||||||
|
sselected_related():
|
||||||
|
if routeWithLocationData(route):
|
||||||
|
filteredroutes.append(route)
|
||||||
|
|
||||||
|
return filteredroutes
|
||||||
|
|
||||||
|
|
||||||
def routeWithSomeLocationData(route,limit):
|
def routeWithSomeLocationData(route,limit):
|
||||||
|
@ -75,9 +84,11 @@ def getRoutesHavingSomeLocs(limit):
|
||||||
|
|
||||||
|
|
||||||
def export_routes(routebeer):
|
def export_routes(routebeer):
|
||||||
#routebeer = getRoutesHavingAllLocs()
|
#routebeer = getRoutesHavingAlLocs()
|
||||||
|
|
||||||
f = make_csv_writer("routes.txt")
|
f = make_csv_writer("routes.txt")
|
||||||
f.writerow(["route_id" ,"route_short_name","route_long_name","route_type"])
|
f.writerow(["route_id" ,"route_short_name","route_long_name","route_type"])
|
||||||
|
|
||||||
for route in routebeer:
|
for route in routebeer:
|
||||||
try:
|
try:
|
||||||
# data checks here
|
# data checks here
|
||||||
|
@ -86,7 +97,7 @@ def export_routes(routebeer):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def make_csv_writer(filename):
|
def make_csv_writer(filename):
|
||||||
return csv.writer(open(join(PROJECT_ROOT, "gtfs", filename), "w"), delimiter=",", quotechar='"', quoting=csv.QUOTE_MINIMAL)
|
return csv.writer(open(join(PROJECT_ROOT, "gtfs", "gtfs_mumbai_bus", filename), "w"), delimiter=",", quotechar='"', quoting=csv.QUOTE_MINIMAL)
|
||||||
|
|
||||||
def export_stops(routelist):
|
def export_stops(routelist):
|
||||||
stoplist = []
|
stoplist = []
|
||||||
|
@ -102,7 +113,7 @@ def export_stops(routelist):
|
||||||
# data checks here
|
# data checks here
|
||||||
# stop_code is used for stop_id as its BEST specfic..
|
# stop_code is used for stop_id as its BEST specfic..
|
||||||
#
|
#
|
||||||
f.writerow([stop.id,stop.name,stop.point.coords[1],stop.point.coords[0]])
|
f.writerow([stop.code,stop.name,stop.point.coords[1],stop.point.coords[0]])
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -111,7 +122,7 @@ def export_agency():
|
||||||
|
|
||||||
# also
|
# also
|
||||||
f.writerow(["agency_id", "agency_name","agency_url","agency_timezone","agency_lang"])
|
f.writerow(["agency_id", "agency_name","agency_url","agency_timezone","agency_lang"])
|
||||||
f.writerow(["BEST","BrihanMumbai Electric Supply & Transport","http://www.bestundertaking.com/","Asia/Kolkata","en"])
|
f.writerow(["BEST","BrihanMumbai Electric Supply & Transport Undertaking","http://www.bestundertaking.com/","Asia/Kolkata","en"])
|
||||||
|
|
||||||
#f.writerow(["agency_id" ,"agency_name","agency_url","agency_timezone"])
|
#f.writerow(["agency_id" ,"agency_name","agency_url","agency_timezone"])
|
||||||
#f.writerow([1 ,"BEST","www.chalobest.in","Asia/Kolkata"])
|
#f.writerow([1 ,"BEST","www.chalobest.in","Asia/Kolkata"])
|
||||||
|
@ -136,9 +147,12 @@ SERVICE_SCHEDULE = [
|
||||||
{'id':13,'code':'SAT&SH','days':[6,7,8]},
|
{'id':13,'code':'SAT&SH','days':[6,7,8]},
|
||||||
{'id':14,'code':'SAT/SUND&HOL','days':[6,7,8]},
|
{'id':14,'code':'SAT/SUND&HOL','days':[6,7,8]},
|
||||||
{'id':15,'code':'S/H','days':[7,8]},
|
{'id':15,'code':'S/H','days':[7,8]},
|
||||||
{'id':16,'code':'SAT,SUN&HOL','days':[6,7,8]}
|
{'id':16,'code':'SAT,SUN&HOL','days':[6,7,8]},
|
||||||
|
{'id':17,'code':'FH','days':[6,8]}
|
||||||
]
|
]
|
||||||
|
# FH indicates what? full week + holidays??
|
||||||
|
# HOL holidays means only the exceptions as defined in calendar_dates.txt. this needs to be converted separately.
|
||||||
|
# done here only to get the other components of gtfs up.
|
||||||
|
|
||||||
def export_calendar():
|
def export_calendar():
|
||||||
f = make_csv_writer("calendar.txt")
|
f = make_csv_writer("calendar.txt")
|
||||||
|
@ -157,18 +171,47 @@ def export_calendar():
|
||||||
f.writerow([ss['code']] + running + [start_date,end_date])
|
f.writerow([ss['code']] + running + [start_date,end_date])
|
||||||
except:
|
except:
|
||||||
print "Error:", str(ss) + '\t' + str(sys.exc_info()[0]) + '\n'
|
print "Error:", str(ss) + '\t' + str(sys.exc_info()[0]) + '\n'
|
||||||
|
|
||||||
|
|
||||||
|
def uniquify_list_of_lists(sequence):
|
||||||
|
seen = set()
|
||||||
|
return [ x for x in sequence if str( x ) not in seen and not seen.add( str( x ) )]
|
||||||
|
|
||||||
def generate_trips(n=None):
|
def generate_trips(n=None):
|
||||||
schedules = RouteSchedule.objects.all()
|
schedules = RouteSchedule.objects.all()
|
||||||
if n is not None: schedules = schedules[:n]
|
if n is not None: schedules = schedules[:n]
|
||||||
|
#triplist = []
|
||||||
for schedule in schedules:
|
for schedule in schedules:
|
||||||
route = schedule.unique_route.route
|
route = schedule.unique_route.route
|
||||||
|
unr = schedule.unique_route
|
||||||
days = schedule.schedule_type
|
days = schedule.schedule_type
|
||||||
|
|
||||||
for direction in ("UP","DOWN"):
|
for direction in ("UP","DOWN"):
|
||||||
trip_id = "%s_%s_%s" %(route.code, days, direction)
|
trip_id = "%s_%s_%s_%s" %(route.code,unr.id,days, direction)
|
||||||
|
#triplist.append([schedule, route, direction, trip_id])
|
||||||
yield schedule, route, direction, trip_id
|
yield schedule, route, direction, trip_id
|
||||||
|
#return uniquify_list_of_lists(triplist)
|
||||||
|
|
||||||
|
|
||||||
|
def generate_trips_unr(n=None):
|
||||||
|
schedules = RouteSchedule.objects.all()
|
||||||
|
if n is not None: schedules = schedules[:n]
|
||||||
|
#triplist = []
|
||||||
|
for schedule in schedules:
|
||||||
|
route = schedule.unique_route.route
|
||||||
|
unr = schedule.unique_route
|
||||||
|
days = schedule.schedule_type
|
||||||
|
|
||||||
|
for direction in ("UP","DOWN"):
|
||||||
|
trip_id = "%s_%s_%s_%s" %(route.code,unr.id,days, direction)
|
||||||
|
#triplist.append([schedule, route, direction, trip_id])
|
||||||
|
yield schedule, unr, route, direction, trip_id
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def export_trips(routelist):
|
def export_trips(routelist):
|
||||||
f = make_csv_writer("trips.txt")
|
f = make_csv_writer("trips.txt")
|
||||||
|
f.writerow(["route_id","service_id","trip_id"])
|
||||||
for schedule, route, direction, trip_id in generate_trips():
|
for schedule, route, direction, trip_id in generate_trips():
|
||||||
if route not in routelist: continue
|
if route not in routelist: continue
|
||||||
f.writerow([route.code, schedule.schedule_type, trip_id])
|
f.writerow([route.code, schedule.schedule_type, trip_id])
|
||||||
|
@ -200,12 +243,20 @@ def getserial(rdlist,stop):
|
||||||
#check if rdlist is of a ring route..
|
#check if rdlist is of a ring route..
|
||||||
if rdlist[0].route.code[3]== 'R' or '4' :
|
if rdlist[0].route.code[3]== 'R' or '4' :
|
||||||
# write ring specific code here. rings have multiple occuring stops, which one to choose??
|
# write ring specific code here. rings have multiple occuring stops, which one to choose??
|
||||||
return None
|
pass
|
||||||
|
#return None
|
||||||
for rd in rdlist:
|
for rd in rdlist:
|
||||||
if(rd.stop==stop):
|
if(rd.stop==stop):
|
||||||
return rdlist.index(rd)
|
return rdlist.index(rd)
|
||||||
|
|
||||||
|
def get_routedetail_subset(unr):
|
||||||
|
route = unr.route
|
||||||
|
from_stop = unr.from_stop
|
||||||
|
to_stop = unr.to_stop
|
||||||
|
rd_subset = rdlist[getserial(rdlist,from_stop):getserial(rdlist,to_stop)]
|
||||||
|
|
||||||
|
return rd_subset
|
||||||
|
|
||||||
def runtime_in_minutes(schedule):
|
def runtime_in_minutes(schedule):
|
||||||
runtime = schedule.runtime1 or schedule.runtime2 or schedule.runtime3 or schedule.runtime4
|
runtime = schedule.runtime1 or schedule.runtime2 or schedule.runtime3 or schedule.runtime4
|
||||||
if runtime: return runtime
|
if runtime: return runtime
|
||||||
|
@ -215,34 +266,87 @@ def runtime_in_minutes(schedule):
|
||||||
return abs(t_from.hour * 60 + t_from.minute -
|
return abs(t_from.hour * 60 + t_from.minute -
|
||||||
(t_to.hour * 60 + t_to.minute))
|
(t_to.hour * 60 + t_to.minute))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def export_stop_times(routelist):
|
def export_stop_times(routelist):
|
||||||
f = make_csv_writer("stop_times.txt")
|
f = make_csv_writer("stop_times.txt")
|
||||||
f.writerow(["trip_id","arrival_time","departure_time","stop_id","stop_sequence"])
|
f.writerow(["trip_id","arrival_time","departure_time","stop_id","stop_sequence"])
|
||||||
for schedule, route, direction, trip_id in generate_trips():
|
|
||||||
|
# get trips and route details
|
||||||
|
|
||||||
|
for schedule, unr, route, direction, trip_id in generate_trips_unr():
|
||||||
|
|
||||||
if route not in routelist: continue
|
if route not in routelist: continue
|
||||||
|
|
||||||
|
# get route in sort_order based on UP or DOWN route
|
||||||
order = "" if direction == "UP" else "-"
|
order = "" if direction == "UP" else "-"
|
||||||
details = list(RouteDetail.objects.filter(route=route).order_by(order+"serial"))
|
rdlist = list(RouteDetail.objects.filter(route=route).order_by(order+"serial"))
|
||||||
|
|
||||||
|
#details = get_routedetail_subset(unr)
|
||||||
|
|
||||||
|
details = rdlist[getserial(rdlist,unr.from_stop):getserial(rdlist,unr.to_stop)]
|
||||||
|
|
||||||
|
# trip specific code
|
||||||
|
dist = unr.distance
|
||||||
|
runtime = runtime_in_minutes(schedule)
|
||||||
|
#if dist == 0.0 or runtime == 0
|
||||||
|
avgspeed = 0.0
|
||||||
|
if not runtime == 0.0:
|
||||||
|
avgspeed = dist/runtime # in km/min
|
||||||
|
else:
|
||||||
|
avgspeed = 0.0
|
||||||
|
|
||||||
initial_time = departure_time = schedule.first_to if direction == "UP" else schedule.first_from
|
initial_time = departure_time = schedule.first_to if direction == "UP" else schedule.first_from
|
||||||
arrival_time = ""
|
if initial_time is None:
|
||||||
|
initial_time = time_of("05:00:00")
|
||||||
|
|
||||||
|
arrival_time = initial_time
|
||||||
|
cumulative_dist = 0.0
|
||||||
|
timedelta = 0
|
||||||
|
today = datetime.date.today()
|
||||||
|
|
||||||
for sequence, detail in enumerate(details):
|
for sequence, detail in enumerate(details):
|
||||||
|
if detail.km:
|
||||||
|
cumulative_dist+=float(detail.km)
|
||||||
|
if avgspeed != 0.0:
|
||||||
|
offsettime = cumulative_dist/avgspeed
|
||||||
|
dt = datetime.datetime.combine(today, initial_time) + datetime.timedelta(seconds=offsettime*60)
|
||||||
|
arrival_time = dt.time()
|
||||||
|
# arrival_time.resolution(datetime.timedelta(0,0,1))
|
||||||
|
dt = datetime.datetime.combine(today, arrival_time) + datetime.timedelta(seconds=10)
|
||||||
|
departure_time = dt.time()
|
||||||
|
#departure_time.resolution(datetime.timedelta(0,0,1))
|
||||||
|
f.writerow([trip_id,arrival_time.__str__().split(".")[0],departure_time.__str__().split(".")[0],detail.stop.code,sequence])
|
||||||
|
else:
|
||||||
|
f.writerow([trip_id,"","",detail.stop.code,sequence])
|
||||||
|
|
||||||
|
"""
|
||||||
|
# if this is the last stop in the route, then
|
||||||
if sequence == len(details) - 1:
|
if sequence == len(details) - 1:
|
||||||
arrival = initial_time.hour * 60 + initial_time.minute + runtime_in_minutes(schedule)
|
arrival = initial_time.hour * 60 + initial_time.minute + runtime_in_minutes(schedule)
|
||||||
arrival_time = "%02d:%02d:00" % (int(arrival/60), arrival % 60)
|
arrival_time = "%02d:%02d:00" % (int(arrival/60), arrival % 60)
|
||||||
f.writerow([trip_id,arrival_time,departure_time,detail.stop.code,sequence])
|
f.writerow([trip_id,arrival_time,departure_time,detail.stop.code,sequence])
|
||||||
|
else:
|
||||||
departure_time = ""
|
departure_time = ""
|
||||||
|
f.writerow([trip_id,arrival_time,departure_time,detail.stop.code,sequence])
|
||||||
|
"""
|
||||||
|
|
||||||
#routelist = getRoutesHavingAllLocs()
|
#routelist = getRoutesHavingAllLocs()
|
||||||
|
|
||||||
#1. get routeDetails
|
#1. get routeDetails
|
||||||
#2. get unique routes as unr and the routeDetails subset as rd_subset for that uniqueroute
|
#2. get unique routes as unr and the routeDetails subset as rd_subset for that uniqueroute
|
||||||
#3. get unr.routeschedule as unr.rs ?? why is it multiple?
|
#3. get all unr.routeschedules as unr.rs
|
||||||
#4. get total distance as tdist from rd_subset
|
#4. get total distance as tdist from rd_subset
|
||||||
#5. get runtime from unr.rs
|
#5. get runtime from unr.rs
|
||||||
#6. if runtime1 is null, then runtime = abs(first_from - first_to)
|
#6. get_runtime()
|
||||||
#7. avgspeed = tdist/runtime... if runtime is not available then ??
|
#7. avgspeed = tdist/runtime... if runtime is not available then ??
|
||||||
#8.
|
#8.
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for r in routelist:
|
for r in routelist:
|
||||||
rdlist = RouteDetail.objects.filter(route=r).order_by('serial')
|
rdlist = RouteDetail.objects.filter(route=r).order_by('serial')
|
||||||
sr_no=0
|
sr_no=0
|
||||||
|
@ -282,6 +386,15 @@ from_stop, to_stop
|
||||||
rd_subset = rdlist[getserial(rdlist,from_stop):getserial(rdlist,to_stop)]
|
rd_subset = rdlist[getserial(rdlist,from_stop):getserial(rdlist,to_stop)]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def time_of(timestr):
|
||||||
|
try:
|
||||||
|
tm = timestr.split(":")
|
||||||
|
return datetime.time(int(tm[0]),int(tm[1]),int(tm[2]))
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def export_frequencies(routelist):
|
def export_frequencies(routelist):
|
||||||
f = make_csv_writer("frequencies.txt")
|
f = make_csv_writer("frequencies.txt")
|
||||||
|
@ -293,10 +406,10 @@ def export_frequencies(routelist):
|
||||||
|
|
||||||
then
|
then
|
||||||
"""
|
"""
|
||||||
TIMESPANS = ((None,"07:00:00"),
|
TIMESPANS = ((None,"06:59:59"),
|
||||||
("07:00:00","11:00:00"),
|
("07:00:00","10:59:59"),
|
||||||
("11:00:00","17:00:00"),
|
("11:00:00","16:59:59"),
|
||||||
("17:00:00","20:00:00"),
|
("17:00:00","19:59:59"),
|
||||||
("20:00:00",None))
|
("20:00:00",None))
|
||||||
|
|
||||||
f.writerow(["trip_id", "start_time","end_time","headway_secs"])
|
f.writerow(["trip_id", "start_time","end_time","headway_secs"])
|
||||||
|
@ -308,23 +421,54 @@ def export_frequencies(routelist):
|
||||||
schedule.headway4,
|
schedule.headway4,
|
||||||
schedule.headway5)
|
schedule.headway5)
|
||||||
for span, (start_time, end_time) in enumerate(TIMESPANS):
|
for span, (start_time, end_time) in enumerate(TIMESPANS):
|
||||||
|
# getting headway timings
|
||||||
|
# making sure the start_time is earlier than the endtime
|
||||||
|
# making start and end as datetime.time
|
||||||
|
|
||||||
if direction == "UP":
|
if direction == "UP":
|
||||||
if start_time is None: start_time = schedule.first_from
|
# if 'up' then take *_from values else take *_to values from schedule
|
||||||
if end_time is None: end_time = schedule.last_from
|
if start_time is None:
|
||||||
|
start_time = schedule.first_from.__str__()
|
||||||
|
if end_time is None:
|
||||||
|
end_time = schedule.last_from.__str__()
|
||||||
|
# if base values are null then put default values
|
||||||
|
if schedule.first_from == datetime.time(0,0,0):
|
||||||
|
start_time = "05:00:00" # magic number here in case BEST data isnt found
|
||||||
|
if schedule.last_from == datetime.time(0,0,0):
|
||||||
|
end_time = "22:59:59" # magic number here in case BEST data isnt found
|
||||||
|
# check if start_time is always earlier than end_time.. this needs to be logged soon!
|
||||||
|
if time_of(start_time) > time_of(end_time):
|
||||||
|
start_time = "05:00:00"
|
||||||
|
if time_of(end_time) < time_of(start_time):
|
||||||
|
end_time = "22:59:59"
|
||||||
else:
|
else:
|
||||||
if start_time is None: start_time = schedule.first_to
|
if start_time is None:
|
||||||
if end_time is None: end_time = schedule.last_to
|
start_time = schedule.first_to.__str__()
|
||||||
|
if end_time is None:
|
||||||
|
end_time = schedule.last_to.__str__()
|
||||||
|
|
||||||
|
# if base values are null then put default values
|
||||||
|
if schedule.first_from == datetime.time(0,0,0):
|
||||||
|
start_time = "05:00:00" # magic number here in case BEST data isnt found
|
||||||
|
if schedule.last_from == datetime.time(0,0,0):
|
||||||
|
end_time = "22:59:59" # magic number here in case BEST data isnt found
|
||||||
|
# check if start_time is always earlier than end_time.. this needs to be logged soon!
|
||||||
|
if time_of(start_time) > time_of(end_time):
|
||||||
|
start_time = "05:00:00" # magic number here in case BEST data isnt found
|
||||||
|
if time_of(end_time) < time_of(start_time):
|
||||||
|
end_time = "22:59:59" # magic number here in case BEST data isnt found
|
||||||
|
|
||||||
if headway[span] is not None:
|
if headway[span] is not None:
|
||||||
f.writerow([trip_id, start_time, end_time, headway[span]*60])
|
f.writerow([trip_id, start_time, end_time, headway[span]*60])
|
||||||
|
|
||||||
def fire_up():
|
def fire_up():
|
||||||
routelist = getRoutesHavingAllLocs()
|
routelist = getRoutesHavingAllLocs()
|
||||||
export_routes(routelist)
|
export_routes(routelist)
|
||||||
#export_stops()
|
export_stops(routelist)
|
||||||
export_frequencies()
|
export_frequencies(routelist)
|
||||||
export_stop_times()
|
export_stop_times(routelist)
|
||||||
export_calendar()
|
export_calendar()
|
||||||
export_trips()
|
export_trips(routelist)
|
||||||
export_agency()
|
export_agency()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,63 @@
|
||||||
route_id,route_short_name,route_long_name,route_type
|
route_id,route_short_name,route_long_name,route_type
|
||||||
|
0011,1LT,COLABA BUS STN. - SANTACRUZ DEPOT,3
|
||||||
|
0017,AS-,BACKBAY DEPOT - CADBURY JN.(THANE),3
|
||||||
|
0027,AS-,BACKBAY DEPOT - DAHISAR BUS STN.,3
|
||||||
|
0037,AS-,NEHRU PLANETARIUM - CADBURY JUNCTION(THANE),3
|
||||||
|
0047,AS-,BACKBAY DEPOT - OSHIWARA DEPOT,3
|
||||||
|
0057,AS-,KURLA TEL.STORES - CADBURY JUNCTION(THANE),3
|
||||||
|
0097,AS-,DR.SHAMAPRASAD MUKHERJI CHOWK - GHATKOPAR STATION (E)-1,3
|
||||||
|
0138,A-1,BACKBAY DEPOT - HIRANANDANI ESTATE,3
|
||||||
|
0161,16-,AMBIKA MILL B.STN/H.U.RAKHANGI CHK. - VASHINAKA M.M.R.D.A.CLY.,3
|
||||||
|
0171,17L,BACKBAY DEPOT - VIDYA VIHAR BUS STN(W),3
|
||||||
|
0172,17 ,BACKBAY DEPOT - VIDYA VIHAR BUS STN(W),3
|
||||||
|
0211,21L,R.C.CHURCH - TROMBAY,3
|
||||||
|
0221,22L,COLABA DEPOT - MAROL MAROSHI BUS STATION,3
|
||||||
|
0426,C-4,RANI LAXMIBAI CHK. - DADLANI PARK (THANE-W),3
|
||||||
|
0541,54-,COLABA BUS STATION - SANTACRUZ DEPOT,3
|
||||||
|
0660,66,BALLARD PIER - RANI LAXMIBAI CHOWK(BUS STATION),3
|
||||||
|
0661,66L,COLABA DEPOT - DHARAVI DEPOT,3
|
||||||
|
0670,67,KAMLA NEHRU PARK - ANTOP HILL,3
|
||||||
|
0708,A-7,NEHRU PLANETARIUM - MIRA ROAD STATION (E),3
|
||||||
|
0748,A-7,COLABA DEPOT - GOREGAON DEPOT,3
|
||||||
|
0852,85-,HUTATMA CHOWK - CHUNABHATTI BUS TERMINUS,3
|
||||||
|
0890,89,MANTRALAYA - WORLI DEPOT,3
|
||||||
|
1004,100,AHILYABAI HOLKAR CHOWK - AHILYABAI HOLKAR CHOWK,3
|
||||||
|
1060,106,R.C.CHURCH - KAMLA NEHRU PARK,3
|
||||||
|
1230,123,R.C.CHURCH - VASANTRAO NAIK CHOWK,3
|
||||||
|
1374,137,NAVY NAGAR - AHILYABAI HOLKAR CHOWK,3
|
||||||
|
0606,C-6,DEONAR DEPOT - BORIVLI STN(E),3
|
||||||
|
1700,170,ANTOP HILL EXTENSION - RANI LAXMIBAI CHOWK,3
|
||||||
|
2114,211,FATHER AGNEL ASHRAM - CHUIM VILLAGE,3
|
||||||
|
2120,212,P.THAKRE UDYAN BUS STN. - BANDRA BUS STN(W),3
|
||||||
|
2144,214,MOUNT MARY STEPS( MUNICIPAL GARDEN) - CHUIM VILLAGE,3
|
||||||
|
2200,220,BANDRA BUS STATION(W) - KHAR STATION (W),3
|
||||||
2820,282,KANDIVLI BUS STATION ( E ) - DAMU NAGAR EXTENSION,3
|
2820,282,KANDIVLI BUS STATION ( E ) - DAMU NAGAR EXTENSION,3
|
||||||
2894,289,KANDIVLI BUS STATION ( E ) - ANITA NAGAR,3
|
2894,289,KANDIVLI BUS STATION ( E ) - ANITA NAGAR,3
|
||||||
|
3200,320,KURLA STN (W) - FILTER PADA,3
|
||||||
|
3220,322,VIDYA VIHAR BUS STN(W) - MAHANT ROAD/PARLE(E),3
|
||||||
|
3520,352,TROMBAY - RANI LAXMIBAI CHOWK,3
|
||||||
|
3551,355,TROMBAY - VESAVA-YARI ROAD BUS STN.,3
|
||||||
|
3600,360,TROMBAY - KURLA BUS STN (E),3
|
||||||
|
3690,369,KURLA BUS STN (E) - VASHINAKA M.M.R.D.A.COLONY,3
|
||||||
|
3710,371,BANDRA BUS STN(W) - ANUSHAKTI NAGAR,3
|
||||||
|
3741,374,ANUSHAKTI NAGAR BUS STATION - GOREGAON STN(E),3
|
||||||
|
3780,378,TROMBAY - MANKHURD STATION (SOUTH),3
|
||||||
|
3894,389,GHATKOPAR STATION (W) - GHATKOPAR STATION (W),3
|
||||||
|
3904,390,GHATKOPAR STATION (W) - BARVE NAGAR,3
|
||||||
|
4060,406,GHATKOPAR STATION (E)-1 - RAILWAY POLICE COLONY(GHATKOPAR,3
|
||||||
|
4160,416,AMRUT NAGAR - GHATKOPAR STATION (W),3
|
||||||
|
4230,423,MANGATRAM PETROLPUMP - MAROL DEPOT,3
|
||||||
|
4260,426,VIDYA VIHAR BUS STN(W) - FILTER PADA,3
|
||||||
|
4290,429,GHATKOPAR STATION (W) - MILIND NAGAR,3
|
||||||
|
4330,433,VIDYA VIHAR BUS STN(W) - SANTACRUZ STN (E),3
|
||||||
|
4430,443,AGARKAR CHOWK - BAMANDAYA PADA,3
|
||||||
|
4460,446,KURLA STN (W) - BAMANDAYA PADA,3
|
||||||
|
4510,451,GOREGAON STN(E) - ADARSH NAGAR,3
|
||||||
|
4520,452,GOREGAON STN(E) - MAYUR NAGAR,3
|
||||||
|
5091,509,MAHESHWARI UDYAN - MILLENNIUM BUSINESS PARK,3
|
||||||
|
5141,514,MULUND-W CHECK NAKA BUS STN. - L & T INFOTECH(MAHAPE),3
|
||||||
|
5927,AS-,VASANTRAO NAIK CHK. - L & T INFOTECH(MAHAPE),3
|
||||||
|
6184,618,SANTACRUZ STATION ( E ) - SANTACRUZ STATION ( E ),3
|
||||||
|
0139,A-1,BACKBAY DEPOT - LODHA COMPLEX,3
|
||||||
|
0610,61,BALLARD PIER - MACCHIMAR NGR/RAHEJA HOSPITAL,3
|
||||||
|
8061,SPL,R.C.CHURCH - AHILYABAI HOLKAR CHOWK,3
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,3 +1,4 @@
|
||||||
|
route_id,service_id,trip_id
|
||||||
4510,SH,4510_SH_UP
|
4510,SH,4510_SH_UP
|
||||||
4510,SH,4510_SH_DOWN
|
4510,SH,4510_SH_DOWN
|
||||||
4510,MS,4510_MS_UP
|
4510,MS,4510_MS_UP
|
||||||
|
|
|
@ -1,212 +1,6 @@
|
||||||
from mumbai.models import *
|
|
||||||
import csv
|
|
||||||
from settings import PROJECT_ROOT
|
|
||||||
from os.path import join
|
|
||||||
import json
|
|
||||||
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
|
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
globalerr = []
|
|
||||||
|
|
||||||
def RouteType_save(entry):
|
|
||||||
obj = RouteType(code=entry[0], rtype=entry[1], faretype=entry[2])
|
|
||||||
obj.save()
|
|
||||||
#print obj.__dict__
|
|
||||||
|
|
||||||
def getFromToStopsFromRouteDetails(code):
|
|
||||||
routeDetails = RouteDetail.objects.filter(route_code=code).order_by('serial')
|
|
||||||
if routeDetails.count() == 0:
|
|
||||||
return None
|
|
||||||
fromStop = routeDetails[0].stop
|
|
||||||
toStop = routeDetails[routeDetails.count() -1].stop
|
|
||||||
return (fromStop, toStop,)
|
|
||||||
|
|
||||||
def Route_save(entry):
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
f_stop = Stop.objects.filter(name=str(entry[2]))[0]
|
|
||||||
except IndexError:
|
|
||||||
f_stop = None
|
|
||||||
|
|
||||||
try:
|
|
||||||
t_stop = Stop.objects.filter(name=str(entry[3]))[0]
|
|
||||||
except IndexError:
|
|
||||||
t_stop = None
|
|
||||||
"""
|
|
||||||
from_to = getFromToStopsFromRouteDetails(entry[0])
|
|
||||||
if from_to is None:
|
|
||||||
globalerr.append({"data" :entry[0], error:["Route not found"]})
|
|
||||||
|
|
||||||
#obj = Route(code=entry[0], alias=entry[1], from_stop_txt=entry[2], to_stop_txt=entry[3], from_stop=from_to[0], to_stop=from_to[1], distance=Decimal(entry[4]), stages=int(entry[5]))
|
|
||||||
|
|
||||||
|
|
||||||
obj = Route(
|
saveorder = ["Fare","Holiday","Area","Road","Depot","Stop", "StopMarathi","AreaMarathi","RouteDetail", "Route","RouteType","HardCodedRoute"]
|
||||||
code=str(entry[0]),
|
|
||||||
alias=str(entry[1]),
|
|
||||||
from_stop=from_to[0],
|
|
||||||
from_stop_txt=str(entry[2]),
|
|
||||||
to_stop_txt=str(entry[3]),
|
|
||||||
to_stop=from_to[1],
|
|
||||||
distance=Decimal(entry[4]),
|
|
||||||
stages=int(entry[5]))
|
|
||||||
obj.save()
|
|
||||||
|
|
||||||
# throw an error if the stops mapped do not exist.
|
|
||||||
# but load nulls into db anyway
|
|
||||||
# IndexError implies that nothing was mapped.
|
|
||||||
# MultipleRows found indicates ambiguity when there should'nt be.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#f_stop = Stop.objects.get(name=str(entry[2]))[0]
|
|
||||||
#t_stop = Stop.objects.get(name=str(entry[3]))[0]
|
|
||||||
|
|
||||||
#print obj.__dict__
|
|
||||||
|
|
||||||
def HardCodedRoute_save(entry):
|
|
||||||
obj = HardCodedRoute(code=str(entry[0]), alias=entry[1], faretype=entry[2])
|
|
||||||
obj.save()
|
|
||||||
#print obj.__dict__
|
|
||||||
|
|
||||||
def Depot_save(entry):
|
|
||||||
obj = Depot(
|
|
||||||
code=str(entry[0]),
|
|
||||||
name=str(entry[1]),
|
|
||||||
stop=int(entry[2])
|
|
||||||
)
|
|
||||||
obj.save()
|
|
||||||
#print obj.__dict__
|
|
||||||
|
|
||||||
def Holiday_save(entry):
|
|
||||||
date_format = entry[0].rsplit('.')
|
|
||||||
theday = int(date_format[0])
|
|
||||||
themonth = int(date_format[1])
|
|
||||||
theyear = int('20'+ date_format[2])
|
|
||||||
obj = Holiday(date=datetime.date(day=theday, month=themonth, year=theyear), name=str(entry[1]))
|
|
||||||
obj.save()
|
|
||||||
#print obj.__dict__
|
|
||||||
|
|
||||||
def RouteDetail_save(entry):
|
|
||||||
|
|
||||||
temp_stop=Stop.objects.get(code=int(entry[2]))
|
|
||||||
"""try:
|
|
||||||
temp_route=Route.objects.get(code=str(entry[0]))
|
|
||||||
except:
|
|
||||||
temp_route=None
|
|
||||||
try:
|
|
||||||
temp_stop=Stop.objects.get(code=int(entry[2]))
|
|
||||||
except:
|
|
||||||
temp_stop=None
|
|
||||||
"""
|
|
||||||
obj = RouteDetail(
|
|
||||||
route_code = entry[0],
|
|
||||||
route = None,
|
|
||||||
serial=int(entry[1]),
|
|
||||||
stop= temp_stop,
|
|
||||||
stage=(lambda:entry[3].startswith('1'), lambda:None)[ entry[3] == '' ](),
|
|
||||||
km=(lambda:None,lambda:Decimal(entry[4]))[ entry[4] != '' ]())
|
|
||||||
obj.save()
|
|
||||||
#print obj.__dict__
|
|
||||||
|
|
||||||
def Road_save(entry):
|
|
||||||
obj = Road(code=int(entry[0]), name=str(entry[1]))
|
|
||||||
obj.save()
|
|
||||||
#print obj.__dict__
|
|
||||||
|
|
||||||
def Fare_save(entry):
|
|
||||||
obj = Fare(
|
|
||||||
slab=Decimal(entry[0]),
|
|
||||||
ordinary=int(entry[1]),
|
|
||||||
limited=int(entry[2]),
|
|
||||||
express=int(entry[3]),
|
|
||||||
ac=int(entry[4]),
|
|
||||||
ac_express=int(entry[5])
|
|
||||||
)
|
|
||||||
obj.save()
|
|
||||||
#print obj.__dict__
|
|
||||||
|
|
||||||
def Area_save(entry):
|
|
||||||
obj = Area(code=int(entry[0]), name= str(entry[1]))
|
|
||||||
obj.save()
|
|
||||||
#print obj.__dict__
|
|
||||||
|
|
||||||
def Stop_save(entry):
|
|
||||||
|
|
||||||
_road = Road.objects.get(code=int(entry[4]))
|
|
||||||
_area = Area.objects.get(code=int(entry[5]))
|
|
||||||
try:
|
|
||||||
_depot = Depot.objects.filter(code=str(entry[6]))[0]
|
|
||||||
except IndexError:
|
|
||||||
_depot = None
|
|
||||||
|
|
||||||
obj = Stop(
|
|
||||||
code=int(entry[0]),
|
|
||||||
name=str(entry[1]),
|
|
||||||
dbdirection=str(entry[2]),
|
|
||||||
chowki=(entry[3]).startswith('TRUE'),
|
|
||||||
road=_road,
|
|
||||||
area=_area,
|
|
||||||
depot=_depot
|
|
||||||
)
|
|
||||||
|
|
||||||
obj.save()
|
|
||||||
#print obj.__dict__
|
|
||||||
|
|
||||||
# There is no model as StopMarathi/AreaMarathi, but this is done to separate errors arising from different files, and also that the Marathi names should be done after the Stop and Area entities have been fully loaded cuz thats how we get them from BEST.
|
|
||||||
|
|
||||||
def StopMarathi_save(entry):
|
|
||||||
obj = Stop.objects.get(code=int(entry[0]))
|
|
||||||
obj.name_mr = unicode(entry[1], 'utf-8')
|
|
||||||
obj.save()
|
|
||||||
#print obj.__dict__
|
|
||||||
|
|
||||||
def AreaMarathi_save(entry):
|
|
||||||
obj = Area.objects.get(code=int(entry[0]))
|
|
||||||
obj.name_mr = unicode(entry[1], 'utf-8')
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
saveorder = ["Fare","Holiday","Area","Road","Depot","Stop", "StopMarathi","AreaMarathi","RouteDetail", "Route","RouteType","HardCodedRoute","StopLocation" ]
|
|
||||||
|
|
||||||
mappingtosave = {
|
mappingtosave = {
|
||||||
"Fare":Fare_save,
|
"Fare":Fare_save,
|
||||||
|
@ -220,12 +14,11 @@ mappingtosave = {
|
||||||
"RouteType":RouteType_save,
|
"RouteType":RouteType_save,
|
||||||
"HardCodedRoute":HardCodedRoute_save,
|
"HardCodedRoute":HardCodedRoute_save,
|
||||||
"StopMarathi":StopMarathi_save,
|
"StopMarathi":StopMarathi_save,
|
||||||
"AreaMarathi":AreaMarathi_save,
|
"AreaMarathi":AreaMarathi_save
|
||||||
"StopLocation":StopLocation_save
|
|
||||||
# There is no model as StopMarathi/AreaMarathi, but this is done to separate errors arising from different input files.
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# There is no model as StopMarathi/AreaMarathi, but this is done to separate errors arising from different input files.
|
||||||
|
|
||||||
def loadFKinRouteDetail():
|
def loadFKinRouteDetail():
|
||||||
err=[]
|
err=[]
|
||||||
good_saves = 0
|
good_saves = 0
|
||||||
|
|
|
@ -16,12 +16,8 @@ def copynames2display_name():
|
||||||
obj.display_name =obj.name
|
obj.display_name =obj.name
|
||||||
obj.save()
|
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():
|
def addStopstoRoutes():
|
||||||
print "Getting stops linked to Routes..."
|
print "Getting stops linked to Routes..."
|
||||||
|
|
|
@ -117,6 +117,7 @@ class Stop(models.Model):
|
||||||
'road': self.road.name,
|
'road': self.road.name,
|
||||||
'area': self.area.name,
|
'area': self.area.name,
|
||||||
'name_mr': self.name_mr,
|
'name_mr': self.name_mr,
|
||||||
|
'direction': self.dbdirection,
|
||||||
'routes': ", ".join([r.route.alias for r in RouteDetail.objects.filter(stop=self)]),
|
'routes': ", ".join([r.route.alias for r in RouteDetail.objects.filter(stop=self)]),
|
||||||
'alternative_names': ", ".join([a.name for a in self.alt_names.all().filter(typ='common')])
|
'alternative_names': ", ".join([a.name for a in self.alt_names.all().filter(typ='common')])
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,6 +164,7 @@ var API_BASE = "/1.0/",
|
||||||
var $displayName = $('<h2 />').text(stop.display_name).appendTo($div);
|
var $displayName = $('<h2 />').text(stop.display_name).appendTo($div);
|
||||||
var $slug = $('<div />').addClass("stopSlug").text(stop.slug).appendTo($div);
|
var $slug = $('<div />').addClass("stopSlug").text(stop.slug).appendTo($div);
|
||||||
var $road = $("<div />").addClass("stopRoad").text("Road: " + stop.road).appendTo($div);
|
var $road = $("<div />").addClass("stopRoad").text("Road: " + stop.road).appendTo($div);
|
||||||
|
var $direction = $("<div />").addClass("stopDirection").text("Direction: " + stop.direction).appendTo($div);
|
||||||
var $routes = $('<div />').text("Routes: " + stop.routes).appendTo($div);
|
var $routes = $('<div />').text("Routes: " + stop.routes).appendTo($div);
|
||||||
// var $formLabel = $("<div />").text("Edit:").appendTo($div);
|
// var $formLabel = $("<div />").text("Edit:").appendTo($div);
|
||||||
var $form = $('<form />').attr("id", "stopForm").appendTo($div);
|
var $form = $('<form />').attr("id", "stopForm").appendTo($div);
|
||||||
|
@ -296,6 +297,8 @@ var API_BASE = "/1.0/",
|
||||||
clickout: false,
|
clickout: false,
|
||||||
toggle: true
|
toggle: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//map.addControl(new OpenLayers.Control.ZoomPanel());
|
||||||
map.addControl(mapControl);
|
map.addControl(mapControl);
|
||||||
mapControl.activate();
|
mapControl.activate();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user