Skip to content
This repository has been archived by the owner on Dec 4, 2018. It is now read-only.

Commit

Permalink
Calculate duration from arrival and departure times.
Browse files Browse the repository at this point in the history
Duration is provided, but at second accuracy while arrival and departure
times are at minute accuracy. We need these to match to get the graphics
right and minute accuracy should be enough.
  • Loading branch information
otsaloma committed May 13, 2014
1 parent 53d0d5b commit 08b62d4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions qml/Route.qml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Canvas {
var bbox = map.getBoundingBox();
// Render also some nodes outside the bbox in order
// to render segments that cross the bbox edge.

// XXX: This mechanism works fine for simplified lines as we set
// the maximum length in the simplification call, but raw paths
// at high zoom levels will at times be rendered only partially.
Expand Down
15 changes: 8 additions & 7 deletions routers/hsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ def parse_legs(result):
for leg in result["legs"]:
item = dict(mode=MODES.get(leg["type"]),
line=parse_line(leg.get("code", "")),
duration=float(leg["duration"])/60,
length=float(leg["length"]),
dep_time=parse_time(leg["locs"][0]["depTime"]),
dep_unix=parse_unix_time(leg["locs"][0]["depTime"]),
Expand All @@ -83,6 +82,9 @@ def parse_legs(result):
dep_name="",
arr_name="")

# Calculate duration separately to match departure and
# arrival times rounded at one minute accuracy.
item["duration"] = item["arr_unix"] - item["dep_unix"]
item["color"] = COLORS[item["mode"]]
names = [loc["name"] for loc in leg["locs"]]
names = list(filter(None, names))
Expand All @@ -93,7 +95,7 @@ def parse_legs(result):
if len(items) > 1:
# Remove short walking legs, which usually occur
# when a geocoded endpoint matches a stop.
items = [x for x in items if x["length"] >= 10]
items = [x for x in items if x["length"] > 10]
return items

def parse_line(code):
Expand Down Expand Up @@ -154,9 +156,8 @@ def route(fm, to, params):
optimize = poor.conf.routers.hsl.optimize
url = URL.format(**locals())
# Date and time parameters are optional.
for name in ("date", "time", "timetype"):
if name in params:
url += "&{}={}".format(name, params[name])
for name in set(params) & set(("date", "time", "timetype")):
url += "&{}={}".format(name, params[name])
results = json.loads(poor.util.request_url(url, "utf_8"))
routes = [dict(alternative=i+1,
length=float(result[0]["length"]),
Expand All @@ -166,8 +167,8 @@ def route(fm, to, params):
) for i, result in enumerate(results)]

for route in routes:
# It seems that at times Journey Planner cannot count.
# We need the duration to match legs to get graphics right.
# Calculate duration separately to match departure and
# arrival times rounded at one minute accuracy.
dep = route["legs"][0]["dep_unix"]
arr = route["legs"][len(route["legs"])-1]["arr_unix"]
route["duration"] = arr - dep
Expand Down

0 comments on commit 08b62d4

Please sign in to comment.