Skip to content

Commit 2b2e1a0

Browse files
committed
Skip first pass for non-auto costing
1 parent 4a97191 commit 2b2e1a0

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

data/params.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ times:
4444
- pedestrian
4545
#- multimodal
4646

47+
# Costing modes in this list will do a first pass with cheaper/faster matrix
48+
# API settings. Otherwise, skip straight to a more expensive second pass
49+
two_pass:
50+
- auto
51+
4752
# Maximum size of chunk of origins AND destinations to process in a single call to
4853
# Valhalla. This is necessary because larger matrices will cause it to choke
4954
max_split_size: 100

data/src/calculate_times.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import pandas as pd
99
import yaml
10+
from utils.constants import DOCKER_ENDPOINT_SECOND_PASS
1011
from utils.logging import create_logger
1112
from utils.times import (
1213
TravelTimeCalculator,
@@ -70,7 +71,14 @@ def main() -> None:
7071
# if second-pass is enabled)
7172
logger.info("Tiles loaded and coodinates ready, starting routing")
7273
tt_calc = TravelTimeCalculator(config, inputs)
73-
results_df = tt_calc.many_to_many()
74+
if config.args.mode not in config.params["times"]["two_pass"]:
75+
logger.info("Skipping second pass for %s mode", config.args.mode)
76+
results_df = tt_calc.many_to_many(
77+
endpoint=DOCKER_ENDPOINT_SECOND_PASS, second_pass=False
78+
)
79+
else:
80+
results_df = tt_calc.many_to_many()
81+
7482
logger.info(
7583
"Finished calculating times for %s pairs in %s",
7684
len(results_df),

data/src/utils/times.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,11 @@ def _binary_search(
555555
)
556556
# fmt: on
557557

558-
def many_to_many(self, second_pass: bool = True) -> pd.DataFrame:
558+
def many_to_many(
559+
self,
560+
endpoint: str = DOCKER_ENDPOINT_FIRST_PASS,
561+
second_pass: bool = True,
562+
) -> pd.DataFrame:
559563
"""
560564
Entrypoint to calculate times for all combinations of origins and
561565
destinations in inputs. Includes an optional second pass which performs
@@ -587,7 +591,7 @@ def many_to_many(self, second_pass: bool = True) -> pd.DataFrame:
587591
cur_depth=0,
588592
origins=self.inputs.origins,
589593
destinations=self.inputs.destinations,
590-
endpoint=DOCKER_ENDPOINT_FIRST_PASS,
594+
endpoint=endpoint,
591595
)
592596
)
593597
for future in futures:

0 commit comments

Comments
 (0)