Commit 0bbfd0df authored by dagal's avatar dagal
Browse files

Don't merge bad gtfs routes anymore

parent 0ab0ce1a
......@@ -31,37 +31,8 @@ def main(argv):
stops = [s.split("-")[1] for s in line.strip().split(",")]
if current_line in line_stops:
current_indices = []
last_i = 0
for stop in stops:
try:
i = line_stops[current_line].index(stop,last_i)
current_indices.append(i)
last_i = i
except ValueError:
current_indices.append(None)
if all(i is None for i in current_indices):
if len(stops) > len(line_stops[current_line]):
if len(stops) > len(line_stops[current_line]):
line_stops[current_line] = stops
elif None in current_indices:
k = 0
last_i = 0
for i in current_indices:
if i is None:
k += 1
else:
i += 1
stops[k:k+1] = line_stops[current_line][last_i:i]
k += i - last_i
last_i = i
stops.extend(line_stops[current_line][last_i:])
line_stops[current_line] = stops
else:
line_stops[current_line] = stops
......
......@@ -37,6 +37,7 @@ def main(argv):
line_freqs[current_line] = [0] * len(stops)
line_vars[current_line] = [0] * len(stops)
current_line = None
for line in sys.stdin:
line = line.strip()
......@@ -51,63 +52,35 @@ def main(argv):
elif time_match:
t0 = parse_time(time_match.group(0)[:-1])
stops = [(parse_time(t[0])-t0, t[1]) for t in [s.split("-") for s in line.split(",")]]
last_i = -1
last_i = 0
for s in stops:
try:
i = line_stops[current_line].index(s[1], max(last_i,0))
if last_i == -1 and i > 0:
for_later.append((current_line, t0, stops))
break
else:
line_times[current_line][i] += s[0]
line_vars[current_line][i] += s[0]*s[0]
line_freqs[current_line][i] += 1
last_i = i+1
i = line_stops[current_line].index(s[1], last_i)
line_times[current_line][i] += s[0]
line_vars[current_line][i] += s[0]*s[0]
line_freqs[current_line][i] += 1
last_i = i+1
except ValueError:
pass
for current_line, t0, stops in for_later:
last_i = -1
for line,times in sorted(line_times.items()):
line_freqs[line] = [max(f,1) for f in line_freqs[line]]
stops = sorted(list([(t/f,s) for t,f,s in zip(times, line_freqs[line], enumerate(line_stops[line]))]))
t0 = stops[0][0]
stops = [(t-t0,s) for t,(_,s) in stops]
for s in stops:
try:
i = line_stops[current_line].index(s[1], max(last_i,0))
print("%s: %s" % (line, ",".join([str(int(t)) for t,_ in stops])))
if line_freqs[current_line][i] > 0:
t0 = s[0]
last_i = i
break
except ValueError:
last_i = -1
pass
last_t = 0
if last_i == -1:
continue
# adjust every value
stops = [(line_times[current_line][last_i] / line_freqs[current_line][last_i] + t - t0, s) for t,s in stops]
last_i = 0
for s in stops:
try:
i = line_stops[current_line].index(s[1], max(last_i,0))
line_times[current_line][i] += s[0]
line_vars[current_line][i] += s[0]*s[0]
line_freqs[current_line][i] += 1
last_i = i+1
except ValueError:
for s in stops[1:]:
if s[0] <= last_t:
#print("wtf " + str(s) + " > " + str(last_t))
pass
with open(argv[1], "w") as lineStops:
for line,times in sorted(line_times.items()):
line_freqs[line] = [max(f,1) for f in line_freqs[line]]
stops = sorted(list([(t/f,s) for t,f,s in zip(times, line_freqs[line], enumerate(line_stops[line]))]))
t0 = stops[0][0]
stops = [(t-t0,s) for t,(_,s) in stops]
print("%s: %s" % (line, ",".join([str(int(t)) for t,_ in stops])))
lineStops.write("%s: %s\n" % (line, ",".join([s for _,s in stops])))
last_t = s[0]
if __name__ == "__main__":
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment