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
Calculated and conditional fields in metadata #3703
Comments
Nice suggestions. I agree with the idea of a "calculated" field, but not for the same application. I would have more in mind the possibility of entering values using different units. Say, a pressure measurement. The user could fill in a field named "Pressure" in Pascal, bar, mbar, or mmHg (Torr) and select the unit used. This would go to a "rawValue" field that would be displayed. The actual "value" field would be hidden and contain the calculated standardised value (in Pascal in this case). When a search is done for a pressure value or range, then it could be found regardless of unit used during the search. Ideally all measurements would be in S.I., but everyday research is not like this. Hope this makes sense. It's not a priority, IMO, but would be nice. Unless others can come up with more urgent reasons. |
One way users could implement this with the above proposal would be {
"extra_fields": [
{
"name": "pressure_input",
"label": "Pressure",
"type": "number",
},
{
"name": "pressure_unit",
"label": "Unit of pressure measurement",
"type": "select",
"value": "Pascal",
"options": ["Pascal", "bar", "mmHg"]
},
{
"name": "pressure_value",
"type": "calculated",
"show_only_if": "false",
"formula": "ifelse(eq({pressure_unit}, 'Pascal'), {pressure_input},ifelse(eq({pressure_unit}, 'bar'), {pressure_input} * 100000, {pressure_input} * 133.322))"
}
]
}
It might be nice to provide lots of helper functions already for example for unit conversions, |
Hi Nicolas, @JuliaSprenger, @SylvainTakerkart |
I haven't looked into it precisely yet, but I agree it would be an interesting feature. |
@NicolasCARPi I used similar functionality in Salesforce to create (really) complex id's and was happy with it |
I would find such functionality very useful as well. In my case, it would be for acquisition settings on imaging instruments. |
I would be very interested having calculated fields and values. the extra step of manually calculating fields is very error prone since it moves the responsibility from the software to the user. as a work around this could be solved by using worker scripts which run on a regular basis and fill out all "calculated" fields, but this adds a whole new layer of possible problems. is this feature something that you plan on implementing, or is it more on the "could be" list? |
seems very far on the todolist, I'm currently focusing on other matters that I belive are more important to implement. But the whole idea is good. |
Feature request
Hi Nico,
When designing the new format for the metadata JSON, I suggest - if you haven't already - to consider support for calculated fields and conditional displaying of fields.
Calculated fields could be used directly for all kinds of scores or unit conversions, and conditionally displayed fields would provide most of "intelligent forms" features.
There are libraries like JSFormula or fparse which allow evaluating simple formulas without the headaches of Javascript eval() - and are still flexible enough to provide custom features.
Suppose you have fields:
With these features (and the heavy lifting provided by the formula evaluator) it should be possible to support quite sophisticated forms with very little implementation effort. The formula evaluators simply get the formula as a string, and a Javascript object with all the previous field values.
I'm very much aware that this is a slippery slope, and one might be tempted to request editable per-project function libraries, additional layout parameters, matrix/tabular-questions..., but this should not stand in the way of a simple solution.
I would be happy to provide a proof-of-concept implementation if this is not already done or you are outright rejecting this idea - regardless of the outcome, I would expect to learn something about elabftw development.
PS: Sorry for sneaking in the distinction between name and label, which is actually another suggestion.
I'm using the hosted version or I have PRO support: NO
The text was updated successfully, but these errors were encountered: