Repository navigation
Add shared unit conversion helpers (#45) - #98
Merged
Merged
Conversation
New sim/units.py with mph/mps, meters/miles/km, and minutes/hours/seconds helpers. Replace duplicated 2.237, 1609.34 and 1000.0 literals in config, reporting, plotting, simulator and the planning sweep. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Contributor
|
awesome |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
sim/units.pywith shared unit-conversion helpers and replaces the duplicatedconversion literals (
2.237,1609.34,1000.0) with them. No simulator behavior changes.Changes
sim/units.py(new):mph_to_mps,mps_to_mph,meters_to_miles,meters_to_km,km_to_meters,minutes_to_hours,minutes_to_seconds. The constants are defined once here.sim/config.py,sim/reporting.py,sim/plotting.py,sim/simulator.pyandsim/planning/sweep.py. The oldMPH_TO_MPSconstant insweep.pyis removed.tests/test_units.py(new): 49 pytest tests.Testing
python3 -m pytest testspasses (71 tests). The new tests cover:SimulationResults,TrackConfigand the sweep's mph-to-m/s conversion use the helpers correctly2.237or1609.34reappear outsidesim/units.pyTo check that outputs are unchanged, I ran all 3 tracks x 4 strategies plus fixed-speed sweeps
on
mainand on this branch and diffed the output. Reports, lap counts and feasibility areidentical. The only differences are last-digit floating-point noise (~1e-16) in two sweep rows,
from
mph / 2.237replacingmph * (1 / 2.237).Related Issue
Closes #45
Notes
interactive_laps_sim.pystill has its own2.237/1609.34literals. I left it alone to keepthis change small, as the issue asks. It could be a follow-up.
/ 3600.0inphysics.pyis a J-to-Wh conversion, not one of the helpers in the issue,so I left it.