Skip to content

Commit

Permalink
[wait_time_estimation] Trim zeroes in default wait time estimation (#134
Browse files Browse the repository at this point in the history
)

* Drop zeroes

* Add comment

* Clarify comment

* Update avg cost mean test measure
  • Loading branch information
kuanb committed Apr 29, 2019
1 parent 8225eb4 commit e9b038f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion peartree/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ def _calculate_means_default(arrival_times: np.array) -> float:
# would replace this default method
na = np.array(wait_seconds)

# Prune 0-second delays as these excessively reduce wait-time estimates
na_no_zeroes = na[na > 0]

# Naive implementation: halve the headway to get average wait time
average_wait = na.mean() / 2
average_wait = na_no_zeroes.mean() / 2
return average_wait


Expand Down
3 changes: 2 additions & 1 deletion tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def test_generate_summary_graph_elements():
assert len(wait_times_by_stop[mask]) == 0

# Just a heuristic for avg_cost mean
assert wait_times_by_stop.avg_cost.mean() == pytest.approx(1015.6, abs=0.1)
avg_cost_mean = wait_times_by_stop.avg_cost.mean()
assert avg_cost_mean == pytest.approx(1109.380, abs=0.1)

# Make sure that there are stop ids unique
u = wait_times_by_stop.stop_id.unique()
Expand Down

0 comments on commit e9b038f

Please sign in to comment.