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

Sentences with missing information are retained in the rendered text #4

Closed
tsalo opened this issue Feb 5, 2024 · 7 comments · Fixed by #6
Closed

Sentences with missing information are retained in the rendered text #4

tsalo opened this issue Feb 5, 2024 · 7 comments · Fixed by #6
Labels
bug Something isn't working

Comments

@tsalo
Copy link
Member

tsalo commented Feb 5, 2024

In the pre-template version of BIDSReport, optional or recommended information that was missing was excluded from the rendered text. For example, when it comes to the MR scanner information, some info was required (or at least needed a stand-in value of "UNKNOWN"), while other info would just be dropped, but the current version has something like the following:

MRI data were acquired using a UNKNOWN Tesla using a system from , with serial number .

Instead, I think something like the following would be better:

MRI data were acquired using a UNKNOWN Tesla scanner.

@tsalo tsalo added the bug Something isn't working label Feb 5, 2024
@Remi-Gau
Copy link
Contributor

Remi-Gau commented Feb 5, 2024

Yeah so for pybids-report there is a "keep" on main branch of chevron that would at least leave the name of the missing parameters rather than those annoying blanks.

But the package has not been updated in a long while... 😒

noahmorrison/chevron#114

@Remi-Gau
Copy link
Contributor

Remi-Gau commented Feb 5, 2024

Ideally I would prefer to have

MRI data were acquired using a UNKNOWN Tesla using a system from {{ bar }}, with serial number {{ foo }} .

But I think this is something that should be handled by the pybids-reports

@tsalo
Copy link
Member Author

tsalo commented Feb 5, 2024

That's reasonable. Can bids-methods handle conditional logic, or does that need to happen on pybids-reports' side?

@Remi-Gau
Copy link
Contributor

Remi-Gau commented Feb 5, 2024

yes the mustache templating language can handle some conditional logic, by using sections: https://mustache.github.io/mustache.5.html

See the mustache spec: https://github.com/mustache/spec/blob/master/specs/sections.yml

Let me create a MWE.

@Remi-Gau
Copy link
Contributor

Remi-Gau commented Feb 5, 2024

You can open and close "sections" with {{#bla}} and close them with {{/bla}}.

import chevron

template = """Data was acquired on a {{model_name}} system
{{#manufacturer}}from {{manufacturer}}, {{/manufacturer}}
{{#DeviceSerialNumber}}with serial number {{DeviceSerialNumber}}{{/DeviceSerialNumber}}."""

data =  {'model_name': 'UNKNWON', "DeviceSerialNumber": 1234}

text = chevron.render(template, data)

print(text)
$ /home/remi/miniconda3/bin/python /home/remi/github/bids/pybids-reports/tmp.py

Data was acquired on a UNKNWON system

with serial number 1234.

Does that help?

@Remi-Gau
Copy link
Contributor

Remi-Gau commented Feb 5, 2024

We could add some conditional logic in the templates that way to avoid some of ugliest renders.

@Remi-Gau
Copy link
Contributor

Remi-Gau commented Feb 7, 2024

I will try to address #7 and then I can try to update pybids-report accordingly to take this into account

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants