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

Add randomize(nodeset) and randomize(nodeset, seed) functions #273

Closed
lognaturel opened this issue Mar 13, 2018 · 3 comments
Closed

Add randomize(nodeset) and randomize(nodeset, seed) functions #273

lognaturel opened this issue Mar 13, 2018 · 3 comments

Comments

@lognaturel
Copy link
Member

lognaturel commented Mar 13, 2018

See getodk/xforms-spec#51 (comment)

  • Use Fisher-Yates for shuffling
  • If a seed is provided, that seed is passed when building a Random object. nextInt is used to get random values
  • Tests and expected values should be shared on the XForms spec issue so other implementations can verify their outcomes are the same
@lognaturel
Copy link
Member Author

I started exploring this a bit and it's trickier than I originally imagined. ItemsetBinding is built on a path expression, not an arbitrary expression containing function calls.

@lognaturel
Copy link
Member Author

lognaturel commented Mar 26, 2018

Here's a quick and dirty first stab at the function itself: https://github.com/lognaturel/javarosa/tree/randomize To be clear, the real challenge comes in actually using it.

The intended usage is something like

<select1 ref="/form/state">
    <itemset nodeset="randomize(instance('choices')/states/state)">
        <label ref="name"/>
        <value ref="value"/>
    </itemset>
</select1>

randomize.xml.txt

parseItemset in XFormParser currently fails because there are places where it expects XPath paths but is getting XPath expressions. Overall, ItemsetBinding is very much built on the assumption the nodeset attribute is populated by a reference to a nodeset, not something that evaluates to a nodeset.

@lognaturel lognaturel removed their assignment Mar 27, 2018
@lognaturel
Copy link
Member Author

lognaturel commented Mar 27, 2018

Interestingly, someone just asked a question about using the result of two repeats as the options for a select -- https://forum.opendatakit.org/t/two-repeating-group-and-filtering-specific-field-data/12452. This should be possible by setting the nodeset to something like "/my-form/people1 | /my-form/people2" (| is the union operator) but we run into the same limitation.

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

No branches or pull requests

2 participants