Skip to content

fix: skip double conversion when time values are already in milliseconds#47

Open
Sufiyan-MSA wants to merge 1 commit intoOSIPI:mainfrom
Sufiyan-MSA:fix/issue-14-double-unit-conversion-time-ms
Open

fix: skip double conversion when time values are already in milliseconds#47
Sufiyan-MSA wants to merge 1 commit intoOSIPI:mainfrom
Sufiyan-MSA:fix/issue-14-double-unit-conversion-time-ms

Conversation

@Sufiyan-MSA
Copy link

Fixes #14

What this fixes

Stops time fields (e.g. PostLabelingDelay, EchoTime, RepetitionTimePreparation) that are already in milliseconds in the input from being multiplied by 1000 again, which was producing wrong values (e.g. 1800 → 1,800,000).

What I changed

  • package/src/pyaslreport/utils/unit_conversion_utils.py: In convert_to_milliseconds, added a heuristic so that if a scalar time value is greater than 10, or any element in a list is greater than 10, the value(s) are treated as already in milliseconds and conversion is skipped. Typical ASL times in seconds (EchoTime ~0.01–0.03 s, PLD ~1–3 s, RepetitionTime ~3–6 s) are all below 10, so this threshold avoids double conversion while keeping seconds→ms conversion for values in seconds.

How I tested it

Ran the four scenarios from the issue: (1) scalar seconds → ms (e.g. 1.8 → 1800), (2) scalar already ms unchanged (e.g. 1800 → 1800, 15 → 15, 4000.0 → 4000.0), (3) list already ms unchanged ([1800, 2000, 2200]), (4) list seconds → ms ([1.8, 2.0, 2.2] → [1800, 2000, 2200]). Confirmed no new linter issues on the modified file.

Notes

Fix is implemented only in UnitConverterUtils.convert_to_milliseconds; both the session normalization path and the M0 time conversion path in processor.py use this method, so both are fixed without further changes.

@Devguru-codes
Copy link

Main issue here is deciding why and how are we fixing the threshold. Any threshold wont work. This change is suggested by AI. Please refrain the indiscriminate use of AI and check what it edits. Please explain why you chose this threshold in the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Double unit conversion corrupts time data when values are already in milliseconds (Help needed)

2 participants