Auto-generating card no

Hi all,

In repeat group, I am adding name of members of organization. After
entering name of each member, I have to assign them a random card with a
number i.e CARD NO 101 to first member, CARD NO 102 to second member and
so on till the nth member.

More specifically, I want the structure of follow-up question/note in
repeat group like this:

  1. SCREEN 1 - What is the name of member (1)?
    2.SCREEN 2 - Hand out card no 101 to member (1)?
  2. SCREEN 3 - What is the name of member (2)?
  3. SCREEN 4 - Hand out card no 102 to member (2)?

Is there any way to auto-generate card number for every member as mentioned
above in repeat group?

Before beginning, it is useful to clarify what you want:

(A) Do you need to ensure that card nos are not re-used across filled-in
form instances? If you do, you need an external application to ensure that
the card nos are never re-used.

(B) Do you need the card nos to be a permutation (jumbling) of a set of
values from (100+1)..(100+M), where M is the total number of members
registered in this form?

(C) Do you just need to assign a unique random card no to each member
within this one form. I.e., from a larger range of numbers
(100+1)..(100+N), pick M distinct values from that set (so that each member
gets their own card no and it is ensured that this card no is not reused by
any other member).

AND, for (C),

Is it OK for this card_no to change if you use the hierarchy view to delete
or add repeat groups (members) in the form? If this is a problem, you
would want to use an external application that can ensure that the card nos
are never re-used.

··· ---------- For (C), without the concern for reassignments from adding or deleting members, I would approach it as follows:
  1. generate a random ordering of N card numbers. Put this into a choice
    list in the form (I forget how to do this in XLSForm -- I am thinking about
    cascading selects
    https://opendatakit.org/help/form-design/cascading-selects/ ). Call this
    choice list 'card_nos'.

N is the upper bound of the number of members you are going to enter into
any one form. Card nos are going to be
assigned from this set. I.e., they are not going to be permutations of
0..M-1.

  1. at the start of the form, have a calculate field 'seed' that captures:

    once(int(random()*N))

This will be an integer from 0..N-1. This will be the randomly-chosen
offset into card_nos from which we are going to begin drawing card numbers.

  1. within the repeat group where you are asking for member names, compute
    'card_nos_index' as:

(position(current()/..) + int(${seed})) mod N

This will take the current repeat # and offset it by the value of seed,
then ensure this is in the range 0..N-1 (so that it can be used to access a
value in 'card_nos')

  1. Define a calculate field within the member repeat to retrieve the card
    number as:

instance('card_nos')/data[position(.)=int(current()/../card_nos_index)]/name

(you would need to adjust this to whatever the XPath is for the fields
produced in 1.)


To make this work, you should play around with generic cascading selects in
XLSForm. Then look at how the cascading selects are written into the XML
file. And modify step 4 accordingly.

If (C) is what you want, then perhaps you can post a working XLSX example
to this list?

For (B), you cannot do this entirely within the first repeat group, as you
don't know the total number of members until after you have entered all the
member names. You would have a second repeat group where you computed the
permutation and displayed it. And, of course, in this case, deleting or
adding members should always re-assign all the card nos. That makes
validation and correctness tricky if you allow people to jump around the
form.

On Fri, May 27, 2016 at 2:47 AM, abbasr725@gmail.com wrote:

Hi all,

In repeat group, I am adding name of members of organization. After
entering name of each member, I have to assign them a random card with a
number i.e CARD NO 101 to first member, CARD NO 102 to second member and
so on till the nth member.

More specifically, I want the structure of follow-up question/note in
repeat group like this:

  1. SCREEN 1 - What is the name of member (1)?
    2.SCREEN 2 - Hand out card no 101 to member (1)?
  2. SCREEN 3 - What is the name of member (2)?
  3. SCREEN 4 - Hand out card no 102 to member (2)?

Is there any way to auto-generate card number for every member as
mentioned above in repeat group?

--

Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en


You received this message because you are subscribed to the Google Groups
"ODK Community" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

Thanks Mitch for possible solutions. I will try these and let you if I had
any queries.

Abbas

··· On Saturday, May 28, 2016 at 12:51:44 AM UTC+5, Mitch Sundt wrote: > > Before beginning, it is useful to clarify what you want: > > (A) Do you need to ensure that card nos are not re-used across filled-in > form instances? If you do, you need an external application to ensure that > the card nos are never re-used. > > (B) Do you need the card nos to be a permutation (jumbling) of a set of > values from (100+1)..(100+M), where M is the total number of members > registered in this form? > > (C) Do you just need to assign a unique random card no to each member > within this one form. I.e., from a larger range of numbers > (100+1)..(100+N), pick M distinct values from that set (so that each member > gets their own card no and it is ensured that this card no is not reused by > any other member). > > AND, for (C), > > Is it OK for this card_no to change if you use the hierarchy view to > delete or add repeat groups (members) in the form? If this is a problem, > you would want to use an external application that can ensure that the card > nos are never re-used. > > ---------- > For (C), without the concern for reassignments from adding or deleting > members, I would approach it as follows: > > 1. generate a random ordering of N card numbers. Put this into a choice > list in the form (I forget how to do this in XLSForm -- I am thinking about > cascading selects > https://opendatakit.org/help/form-design/cascading-selects/ ). Call this > choice list 'card_nos'. > > N is the upper bound of the number of members you are going to enter into > any one form. Card nos are going to be > assigned from this set. I.e., they are not going to be permutations of > 0..M-1. > > 2. at the start of the form, have a calculate field 'seed' that captures: > > once(int(random()*N)) > > This will be an integer from 0..N-1. This will be the randomly-chosen > offset into card_nos from which we are going to begin drawing card numbers. > > 3. within the repeat group where you are asking for member names, compute > 'card_nos_index' as: > > (position(current()/..) + int(${seed})) mod N > > This will take the current repeat # and offset it by the value of seed, > then ensure this is in the range 0..N-1 (so that it can be used to access a > value in 'card_nos') > > 4. Define a calculate field within the member repeat to retrieve the card > number as: > > > instance('card_nos')/data[position(.)=int(current()/../card_nos_index)]/name > > (you would need to adjust this to whatever the XPath is for the fields > produced in 1.) > > ------------- > To make this work, you should play around with generic cascading selects > in XLSForm. Then look at how the cascading selects are written into the XML > file. And modify step 4 accordingly. > > If (C) is what you want, then *perhaps you can post a working XLSX > example to this list?* > > For (B), you cannot do this entirely within the first repeat group, as you > don't know the total number of members until after you have entered all the > member names. You would have a second repeat group where you computed the > permutation and displayed it. And, of course, in this case, deleting or > adding members should always re-assign all the card nos. That makes > validation and correctness tricky if you allow people to jump around the > form. > > > > > > On Fri, May 27, 2016 at 2:47 AM, <abba...@gmail.com > wrote: > >> Hi all, >> >> In repeat group, I am adding name of members of organization. After >> entering name of each member, I have to assign them a random card with a >> number i.e CARD NO 101 to first member, CARD NO 102 to second member and >> so on till the nth member. >> >> More specifically, I want the structure of follow-up question/note in >> repeat group like this: >> 1. SCREEN 1 - What is the name of member (1)? >> 2.SCREEN 2 - Hand out card no 101 to member (1)? >> 3. SCREEN 3 - What is the name of member (2)? >> 4. SCREEN 4 - Hand out card no 102 to member (2)? >> >> Is there any way to auto-generate card number for every member as >> mentioned above in repeat group? >> >> -- >> -- >> Post: opend...@googlegroups.com >> Unsubscribe: opendatakit...@googlegroups.com >> Options: http://groups.google.com/group/opendatakit?hl=en >> >> --- >> You received this message because you are subscribed to the Google Groups >> "ODK Community" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to opendatakit...@googlegroups.com . >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > Mitch Sundt > Software Engineer > University of Washington > mitche...@gmail.com >