fix missing headways fixed
This commit is contained in:
parent
b48f2ddb3d
commit
cea31844d7
|
@ -143,8 +143,6 @@ def fix_missing_runtimes():
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
hcolumns = ["headway%d" % n for n in range(1,6)]
|
hcolumns = ["headway%d" % n for n in range(1,6)]
|
||||||
def fix_missing_headways():
|
def fix_missing_headways():
|
||||||
for schedule in RouteSchedule.objects.all():
|
for schedule in RouteSchedule.objects.all():
|
||||||
|
@ -161,7 +159,7 @@ def fix_missing_headways():
|
||||||
if getattr(schedule, column): continue
|
if getattr(schedule, column): continue
|
||||||
|
|
||||||
# try to use the previous column....if available
|
# try to use the previous column....if available
|
||||||
if getattr(schedule, column): continue
|
#if getattr(schedule, column): continue
|
||||||
if col_idx > 0:
|
if col_idx > 0:
|
||||||
prev_headway = getattr(schedule, columns[col_idx-1])
|
prev_headway = getattr(schedule, columns[col_idx-1])
|
||||||
if prev_headway:
|
if prev_headway:
|
||||||
|
@ -175,6 +173,15 @@ def fix_missing_headways():
|
||||||
setattr(schedule, column, next_headway)
|
setattr(schedule, column, next_headway)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
#try any headway in the current row:
|
||||||
|
for hcol in hcolumns:
|
||||||
|
headway = getattr(schedule, hcol)
|
||||||
|
if headway:
|
||||||
|
setattr(schedule, column, headway)
|
||||||
|
break
|
||||||
|
|
||||||
|
if getattr(schedule, column):
|
||||||
|
continue
|
||||||
# otherwise, go through the other schedules for this subroute and
|
# otherwise, go through the other schedules for this subroute and
|
||||||
# see if we get a matching headway -- if so, use it
|
# see if we get a matching headway -- if so, use it
|
||||||
for sibling in sibling_schedules:
|
for sibling in sibling_schedules:
|
||||||
|
@ -185,41 +192,49 @@ def fix_missing_headways():
|
||||||
break
|
break
|
||||||
|
|
||||||
if getattr(schedule, column): continue
|
if getattr(schedule, column): continue
|
||||||
# otherwise, go through the matching schedules for the full-length versions of this
|
|
||||||
# route and extrapolate the headway.
|
|
||||||
if related_subroutes:
|
|
||||||
# first, try to get the schedules for the full routes, given the same schedule type
|
|
||||||
related_schedules = []
|
|
||||||
for related_route in related_subroutes:
|
|
||||||
related_schedules += list(related_route.routeschedule_set.filter(schedule_type=schedule.schedule_type))
|
|
||||||
|
|
||||||
# iterate over them and see if we got one with the right headway
|
break_loop = False
|
||||||
for related_schedule in related_schedules:
|
for sibling in sibling_schedules:
|
||||||
related_headway = getattr(related_schedule, column)
|
if break_loop:
|
||||||
if related_headway:
|
break
|
||||||
# if so, compute the partial headway of this schedule as the (possibly > 1.0) fraction of headway of the other schedule by distance
|
for hcol in hcolumns:
|
||||||
partial_headway = related_headway*float(schedule.unique_route.distance)/float(related_schedule.unique_route.distance)
|
headway = getattr(sibling, hcol)
|
||||||
# print "OK fix_missing_headways: %s %s adjusted to parent %s" % (schedule, column, related_schedule)
|
if headway:
|
||||||
setattr(schedule, column, partial_headway)
|
setattr(schedule, column, headway)
|
||||||
|
break_loop = True
|
||||||
break
|
break
|
||||||
|
|
||||||
# did we find a headway? great, use it
|
|
||||||
if getattr(schedule, column): continue
|
|
||||||
|
|
||||||
# failing that, try to get the schedules for the full routes, with ANY schedule type
|
if getattr(schedule, column):
|
||||||
for related_route in related_subroutes:
|
continue
|
||||||
related_schedules += list(related_route.routeschedule_set.all())
|
|
||||||
|
|
||||||
# iterate over them and see if we got one with the right headway
|
break_loop = False
|
||||||
for related_schedule in related_schedules:
|
for r in related_subroutes:
|
||||||
related_headway = getattr(related_schedule, column)
|
if break_loop:
|
||||||
if related_headway:
|
break
|
||||||
# if so, compute the partial headway of this schedule as the (possibly > 1.0) fraction of headway of the other schedule by distance
|
for related_schedule in r.routeschedule_set.all():
|
||||||
partial_headway = related_headway*float(schedule.unique_route.distance)/float(related_schedule.unique_route.distance)
|
if break_loop:
|
||||||
# print "OK fix_missing_headways: %s %s adjusted to parent %s" % (schedule, column, related_schedule)
|
break
|
||||||
setattr(schedule, column, partial_headway)
|
for hcol in hcolumns:
|
||||||
|
headway = getattr(related_schedule, hcol)
|
||||||
|
if break_loop:
|
||||||
|
break
|
||||||
|
if headway:
|
||||||
|
setattr(schedule, column, headway)
|
||||||
|
break_loop = True
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if getattr(schedule, column):
|
||||||
|
continue
|
||||||
|
|
||||||
|
if not getattr(schedule, column):
|
||||||
|
print Exception("All failed for schedule with id %d" % schedule.id)
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
if column != "headway5":
|
if column != "headway5":
|
||||||
print Exception("ERR fix_missing_headways: %s STILL missing %s!" % (schedule, column))
|
print Exception("ERR fix_missing_headways: %s STILL missing %s!" % (schedule, column))
|
||||||
|
'''
|
||||||
|
|
Loading…
Reference in New Issue
Block a user