OpenRailAssociation / osrd

An open source web application for railway infrastructure design, capacity analysis, timetabling and simulation
https://osrd.fr
436 stars 40 forks source link

front: fix problem many zeros after setting the initial velocity in a… #8332

Closed theocrsb closed 1 month ago

theocrsb commented 1 month ago

close #7271

codecov-commenter commented 1 month ago

:warning: Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 34.48276% with 19 lines in your changes missing coverage. Please review.

Project coverage is 37.95%. Comparing base (ef77780) to head (eaac9e2).

Files Patch % Lines
.../ManageTrainSchedule/helpers/checkCurrentConfig.ts 0.00% 11 Missing :warning:
...e/components/ManageTrainSchedule/TrainSettings.tsx 0.00% 4 Missing :warning:
...ainSchedule/helpers/adjustConfWithTrainToModify.ts 0.00% 2 Missing :warning:
front/src/utils/numbers.ts 83.33% 0 Missing and 2 partials :warning:

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## dev #8332 +/- ## ========================================= Coverage 37.94% 37.95% Complexity 2163 2163 ========================================= Files 1248 1248 Lines 114950 114978 +28 Branches 3135 3137 +2 ========================================= + Hits 43623 43640 +17 - Misses 69479 69488 +9 - Partials 1848 1850 +2 ``` | [Flag](https://app.codecov.io/gh/OpenRailAssociation/osrd/pull/8332/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Coverage Δ | | |---|---|---| | [core](https://app.codecov.io/gh/OpenRailAssociation/osrd/pull/8332/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | `75.59% <ø> (ø)` | | | [editoast](https://app.codecov.io/gh/OpenRailAssociation/osrd/pull/8332/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | `66.82% <ø> (+0.02%)` | :arrow_up: | | [front](https://app.codecov.io/gh/OpenRailAssociation/osrd/pull/8332/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | `16.35% <34.48%> (+<0.01%)` | :arrow_up: | | [gateway](https://app.codecov.io/gh/OpenRailAssociation/osrd/pull/8332/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | `2.03% <ø> (ø)` | | | [railjson_generator](https://app.codecov.io/gh/OpenRailAssociation/osrd/pull/8332/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | `87.49% <ø> (ø)` | | | [tests](https://app.codecov.io/gh/OpenRailAssociation/osrd/pull/8332/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | `72.98% <ø> (ø)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

theocrsb commented 1 month ago

With your solution, the value entered by the user will always be rounded even if he doesn't want to.

The issue related by the bug comes from the fact that the endpoint to add a train requires a speed in m/s and not in km/h. So when the conversion is done when adding (save) and getting the train (for edit), some extra decimals can pop.

I think it would be better to handle this logic in the adjustConfWithTrainToModifyV2 function, l.151 when we are getting the initialSpeed from the train and update the store with it by converting the value in km/h.

const convertedInitialSpeed = initial_speed ? Math.round(msToKmh(initial_speed) * 10) / 10 : 0)
dispatch(updateInitialSpeed(convertedtedInitialSpeed));

NB :

  • Maybe you can add the const before all the dispatch
  • Maybe we need to check with a PO how many decimal max we want

After discussion with a PO, it was decided to keep only one digit after the decimal point.