frequencies and headways added for api

This commit is contained in:
Johnson Chetty 2012-09-22 08:20:45 +02:00
parent 0b0a2409b1
commit ea74ed4d1a
4 changed files with 32 additions and 13 deletions

View File

@ -1618,7 +1618,7 @@ def export_atlas():
f =codecs.open(join(PROJECT_ROOT, "gtfs", "recomputed_atlas.csv"), "w", "utf-8") f =codecs.open(join(PROJECT_ROOT, "gtfs", "recomputed_atlas.csv"), "w", "utf-8")
f = csv.writer(open(join(PROJECT_ROOT, "gtfs", "gtfs_mumbai_bus", "recomputed_atlas.csv"), "w"), delimiter="\t", quotechar='"', quoting=csv.QUOTE_MINIMAL) f = csv.writer(open(join(PROJECT_ROOT, "gtfs", "gtfs_mumbai_bus", "recomputed_atlas.csv"), "w"), delimiter="\t", quotechar='"', quoting=csv.QUOTE_MINIMAL)
f.writerow(["RouteCode","RouteAlias","BusesAM","BusesNoon","BusesPM","BusType","Depot","FromStopCode","FromStopName","FromStopOriginal","FirstFrom","LastFrom","ToStopCode","ToStopName","ToStopOriginal","FirstTo","LastTo","rt1","rt2","rt3","rt4","headway1","headway2","headway3","headway4","headway5","ScheduleType","RouteSpan/AtlasDistance", "DistanceMasterRoute", "DistanceRouteDetail", "mismatchedfromstop","mismatchedtostop","DaysOfRun" ]) f.writerow(["RouteCode","RouteAlias","BusesAM","BusesNoon","BusesPM","BusType","Depot","FromStopCode","FromStopName","FromStopOriginal","FromStopMarathi", "FirstFrom","LastFrom","ToStopCode","ToStopName","ToStopOriginal","ToStopMarathi","FirstTo","LastTo","rt1","rt2","rt3","rt4","headway1","headway2","headway3","headway4","headway5","ScheduleType","RouteSpan/AtlasDistance", "DistanceMasterRoute", "DistanceRouteDetail", "mismatchedfromstop","mismatchedtostop","DaysOfRun" ])
for unr in UniqueRoute.objects.all().order_by("route__code"): for unr in UniqueRoute.objects.all().order_by("route__code"):
for rs in unr.routeschedule_set.all().order_by("schedule_type"): for rs in unr.routeschedule_set.all().order_by("schedule_type"):
bus_type= RouteType.objects.get(code=str(unr.route.code)[3]).faretype bus_type= RouteType.objects.get(code=str(unr.route.code)[3]).faretype
@ -1633,15 +1633,15 @@ def export_atlas():
bus_type, bus_type,
rs.depot_txt, rs.depot_txt,
unr.from_stop.code, unr.from_stop.code,
unr.from_stop.name, unr.from_stop.name.title(),
unr.from_stop_txt, unr.from_stop_txt,
#unr.from_stop.name_mr.encode('utf-8'), unr.from_stop.name_mr.encode('utf-8'),
rs.first_from, rs.first_from,
rs.last_from, rs.last_from,
unr.to_stop.code, unr.to_stop.code,
unr.to_stop.name, unr.to_stop.name.title(),
unr.to_stop_txt, unr.to_stop_txt,
#unr.to_stop.name_mr.encode('utf-8'), unr.to_stop.name_mr.encode('utf-8'),
rs.first_to, rs.first_to,
rs.last_to, rs.last_to,
rs.runtime1,rs.runtime2,rs.runtime3,rs.runtime4, rs.runtime1,rs.runtime2,rs.runtime3,rs.runtime4,

View File

@ -36,6 +36,7 @@ SCHED = {
'SAT&SUN':[6, 7], 'SAT&SUN':[6, 7],
'MS&HOL':[1, 2, 3, 4, 5, 6, 8], 'MS&HOL':[1, 2, 3, 4, 5, 6, 8],
'FW':[1, 2, 3, 4, 5, 6, 7], 'FW':[1, 2, 3, 4, 5, 6, 7],
'MS&SUN':[1, 2, 3, 4, 5, 6, 7],
'SAT/SH':[6, 7, 8], 'SAT/SH':[6, 7, 8],
'SAT&HOL':[6, 8], 'SAT&HOL':[6, 8],
'SAT&SH':[6, 7, 8], 'SAT&SH':[6, 7, 8],

View File

@ -259,9 +259,16 @@ def route_headway(request, code):
scheds = [] scheds = []
for rs in RouteSchedule.objects.filter(unique_route__route=route): for rs in RouteSchedule.objects.filter(unique_route__route=route):
# if holiday schedule,
# if 8 in SCHED[rs.schedule_type]:
# if Holiday.objects.filter(date=current_time)
# read route schedule and return headway for time period
if day in SCHED[rs.schedule_type]: if day in SCHED[rs.schedule_type]:
scheds.append(rs) scheds.append(rs)
#(s.first_from if s.first_from < s.first_to else s.first_to)
TIMESPANS = ((None,"06:59:59"), TIMESPANS = ((None,"06:59:59"),
("07:00:00","10:59:59"), ("07:00:00","10:59:59"),
@ -269,13 +276,24 @@ def route_headway(request, code):
("17:00:00","19:59:59"), ("17:00:00","19:59:59"),
("20:00:00", None)) ("20:00:00", None))
#for s in scheds: freqs=[]
# if current_time< time_of("") from gtfs.gtfs_export import time_of
for s in scheds:
t = TIMESPANS
if current_time.time() < time_of(t[0][1]): freqs.append(s.headway1)
if current_time.time() < time_of(t[1][1]) and current_time.time() > time_of(t[0][1]): freqs.append(s.headway2)
if current_time.time() < time_of(t[2][1]) and current_time.time() > time_of(t[1][1]): freqs.append(s.headway3)
if current_time.time() < time_of(t[3][1]) and current_time.time() > time_of(t[2][1]): freqs.append(s.headway4)
if current_time.time() > time_of(t[0][1]): freqs.append(s.headway5)
avg = float(sum(freqs)/len(freqs))
frequencies = [x for x in freqs if x!=0]
return render_to_json_response( return render_to_json_response(
{ {
'route': route.get_dict(), 'route': route.get_dict(),
'scheds': [ (s.headway1, s.headway2, s.headway3, s.headway4, str(s.unique_route) ) for s in scheds] 'frequency': str(min(frequencies)) + "-" + str(max(frequencies))
#'scheds': [ (s.headway1, s.headway2, s.headway3, s.headway4, str(s.unique_route) ) for s in scheds]
}) })

View File

@ -36,7 +36,7 @@ DATABASES = {
# timezone as the operating system. # timezone as the operating system.
# If running in a Windows environment this must be set to the same as your # If running in a Windows environment this must be set to the same as your
# system time zone. # system time zone.
TIME_ZONE = 'America/Chicago' TIME_ZONE = 'Asia/Kolkata'
# Language code for this installation. All choices can be found here: # Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html # http://www.i18nguy.com/unicode/language-identifiers.html