Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧹 Chore: Magic Numbers in Bus Speed Computations #132

Open
3 tasks
DavidOry opened this issue Feb 1, 2024 · 0 comments
Open
3 tasks

🧹 Chore: Magic Numbers in Bus Speed Computations #132

DavidOry opened this issue Feb 1, 2024 · 0 comments
Labels
chore overhead: doesn't add additional functionality, change performance, or refactor code

Comments

@DavidOry
Copy link
Collaborator

DavidOry commented Feb 1, 2024

The section of code that computes bus speeds from automobile speeds is ripe with magic numbers. These need to refer to either to fixed definitions defined in a data model or schema, or refer to dictionaries defined in the control files.

if auto_time > 0:
# https://github.com/BayAreaMetro/travel-model-one/blob/master/model-files/scripts/skims/PrepHwyNet.job#L106
tran_speed = 60 * link_length/auto_time
if (facility_type<=4 or facility_type==8) and (tran_speed<6):
tran_speed = 6
_transit_link_dict[_link_id]["@trantime"] = 60 * link_length/tran_speed
elif (tran_speed<3):
tran_speed = 3
_transit_link_dict[_link_id]["@trantime"] = 60 * link_length/tran_speed
else:
_transit_link_dict[_link_id]["@trantime"] = auto_time
# data1 is the auto time used in Mixed-Mode transit assigment
_transit_link_dict[_link_id].data1 = (_transit_link_dict[_link_id]["@trantime"] +
60*sov_toll/self.config.value_of_time)
# bus time calculation
if facility_type in [1,2,3,8]:
delayfactor = 0.0
else:
if area_type in [0,1]:
delayfactor = 2.46
elif area_type in [2,3]:
delayfactor = 1.74
elif area_type==4:
delayfactor = 1.14
else:
delayfactor = 0.08

Progress:

  • Sufficiently defined
  • Approach decided
  • Implemented

Considerations

Ideally, things like facility type would be defined in code in one and only one place. These references could then be imported and use in this code. In the short-term, moving the magic numbers to a config file would be an improvement.

cc @gregerhardt @lmz

@DavidOry DavidOry added the chore overhead: doesn't add additional functionality, change performance, or refactor code label Feb 1, 2024
@DavidOry DavidOry changed the title 🧹 Chore: Magic Numbers in 🧹 Chore: Magic Numbers in Bus Feb 1, 2024
@DavidOry DavidOry changed the title 🧹 Chore: Magic Numbers in Bus 🧹 Chore: Magic Numbers in Bus Speed Computations Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore overhead: doesn't add additional functionality, change performance, or refactor code
Projects
Status: Todo
Development

No branches or pull requests

1 participant