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

DFReader: fixed handling of multlipiers from FMTU and MULT #965

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion DFReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def set_mult_ids(self, mult_ids, mult_lookup):
for i in range(len(self.units)):
# If the format has its own multiplier, do not adjust the unit,
# and if no unit is specified there is nothing to adjust

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to update this comment based on the final test logic.

if self.msg_mults[i] is not None or self.units[i] == "":
if self.msg_mults[i] is not None or self.units[i] != "":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need just:

Suggested change
if self.msg_mults[i] is not None or self.units[i] != "":
if self.msg_mults[i] is not None:

Otherwise, things like *.TimeUS will say its in 's' instead of 'μs' and PM.Load will say its in '%' instead of 'd%', when running 'dump PM --verbose'.

continue
# Get the unit multiplier from the lookup table
if mult_ids[i] in mult_lookup:
Expand All @@ -176,6 +176,9 @@ def set_mult_ids(self, mult_ids, mult_lookup):
self.units[i] = MULT_TO_PREFIX[unitmult]+self.units[i]
else:
self.units[i] = "%.4g %s" % (unitmult, self.units[i])
if self.units[i] in FORMAT_TO_STRUCT:
Copy link
Contributor

@shancock884 shancock884 Aug 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the "if self.units[i] in FORMAT_TO_STRUCT" bit is working because the prefix for "centi" and the code for "int16_t * 100" are both 'c' - but in my mind they aren't really the same 'c'!

Assuming your aim is that any parameter which has no-unit but does have a multiplier specified, has that multiplier applied to the value, instead of becoming a unit prefix, then maybe something like this is cleaner:

Suggested change
if self.units[i] in FORMAT_TO_STRUCT:
# For unitless values, apply multiplier to value. For params with a unit,
# turn the multiplier into a unit prefix.
if self.units[i] == "":
self.msg_mults[i] = mult_lookup[mult_ids[i]]
elif unitmult in MULT_TO_PREFIX:
self.units[i] = MULT_TO_PREFIX[unitmult]+self.units[i]
else:
self.units[i] = "%.4g %s" % (unitmult, self.units[i])

(to replace all lines 175 -181)

Not checked in detail, but I think this should then work for any multiplier which is set on a unitless parameter, even if that multiplier is not 100.

(label, mul, t) = FORMAT_TO_STRUCT[self.units[i]]
self.msg_mults[i] = mul

def get_unit(self, col):
'''Return the unit for the specified field'''
Expand Down
Loading