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

dump function does not correctly format output for long variable names #672

Open
james-thunes opened this issue May 21, 2024 · 0 comments · May be fixed by #726
Open

dump function does not correctly format output for long variable names #672

james-thunes opened this issue May 21, 2024 · 0 comments · May be fixed by #726

Comments

@james-thunes
Copy link

If a FMU has a variable with a long name, the columns output in the variables block of the dump command are not correctly justified.

To reproduce:

from fmpy import *
fmu = 'fmuWithLongVariableNames.fmu'

dump(fmu)

the variables block in the returned output (variable names changed for privacy reasons):

Variables (input, output)

  Name               Causality              Start Value  Unit     Description
  aaaaaaaaaaaaaaaaa01 input                         0.55
  bbbbbbbbbbbbbbbbb0 input                     200000.0
  ccccccccccccccccc0123 input                          0.5
  ddddddddddddddddd012 input                     200000.0
  eeeeeeeeeeeeeeeee01234567 input                       319.82
  fffffffffffffffff0123456789 input                        285.5
  ggggggggggggggggg01234567890 output
  hhhhhhhhhhhhhhhhh012345678 output

The issue appears to be on ln698 of util.py:

        l.append('  {:18} {:10} {:>23}  {:8} {}'.format(*args))

The column width could either be set to the max variable name length (in which case the code would need to loop over the variables to find the maximum length followed by adjustment to ln687 in that same file) or the variable names would need to be truncated. I would suggest that truncation may be the most straightforward of solutions. It has the potential to be confusing if the variable names differ only after character 18, but having a fixed width table printed is preferable in my opinion.

The line could be changed to this:

        l.append('  {:.18} {:10} {:>23}  {:8} {}'.format(*args))

The output with that change:

Variables (input, output)

  Name               Causality              Start Value  Unit     Description
  aaaaaaaaaaaaaaaaaa input                         0.55
  bbbbbbbbbbbbbbbbbb input                     200000.0
  cccccccccccccccccc input                          0.5
  dddddddddddddddddd input                     200000.0
  eeeeeeeeeeeeeeeeee input                       319.82
  ffffffffffffffffff input                        285.5
  gggggggggggggggggg output
  hhhhhhhhhhhhhhhhhh output
t-sommer added a commit that referenced this issue Dec 11, 2024
@t-sommer t-sommer linked a pull request Dec 11, 2024 that will close this issue
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 a pull request may close this issue.

1 participant