Timetable layout is a hard problem to solve for all cases. Here’s an approach which will not generalize to all routes, but works often enough to be useful (link). In short, build a directed graph of all adjacent stop pairs (edges) made by trips in the timetable and topologically sort it to get the “header row”, then layout the stop times accordingly. A fully generalized approach requires finding an approximation of the shortest common supersequence of the set of stopping patterns—which is definitely non-trivial to do really well.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def segmentize(points, km): | |
npoints = len(points) | |
if npoints == 0: | |
return [] | |
elif npoints == 1: | |
return [points[0]] | |
a, b = points[:2] | |
rest = segmentize(points[2:], km) | |
if haversine(a, b) > km: |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
- http://harp.pythonanywhere.com/python_doc/whatsnew/3.6.html
- https://hg.python.org/cpython/rev/7fea2cebc604#l4.58
with ZipFile(path) as zipreader:
for entry in zipreader.filelist:
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parse_git_branch { | |
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' | |
} | |
function color_git_branch { | |
# '$1' represents the first variable passed to the script | |
if [[ "x$1" = "x" ]]; then | |
echo -e "$1" | |
else | |
local status="$(git status 2> /dev/null | tail -n1)" |