Calculation based on select_one

I have a set of six questions. Each of them is type select_one. The
questions each have 3 or 4 options.
I want to calculate a numeric score based on the answers to the six
questions.
If the selected answer to a question is the first option, this would be a
value of 1, second option, 2, etc.
Add up the numbers from all six questions to get a total score.
It looks like the "selected" operator would be useful but I would have to
do an elaborate test of each of the options for each of the questions to
see which one is selected.
The "selected-at" operator seems to apply only to multiple select questions
and it seems that I would also have to test each option.
Is there a function which will just give me the number (n)th of the
selected option for a select_one question?

Thank you,
Mark

If you wanted to, you could use a number 1, 2, etc. for the value of the
selection choice.

You could then use

number(/data/q1) + number(/data/q2) + ...

to convert the chosen value "1", "2", etc. (select-ones are always string
values) to numbers for your select questions (e.g., /data/q1 and /data/q2
etc. above) and add them up.

Otherwise, as you say, you would need to map whatever value you have for a
given label into a number, then add those up. If for some reason you must
keep the value a string, I would recommend using a calculated field to
store the numeric mapping for the value name, then adding up those
calculated numeric fields.

Mitch

··· On Wed, Mar 6, 2013 at 12:48 PM, Mark Spohr wrote:

I have a set of six questions. Each of them is type select_one. The
questions each have 3 or 4 options.
I want to calculate a numeric score based on the answers to the six
questions.
If the selected answer to a question is the first option, this would be a
value of 1, second option, 2, etc.
Add up the numbers from all six questions to get a total score.
It looks like the "selected" operator would be useful but I would have to
do an elaborate test of each of the options for each of the questions to
see which one is selected.
The "selected-at" operator seems to apply only to multiple select
questions and it seems that I would also have to test each option.
Is there a function which will just give me the number (n)th of the
selected option for a select_one question?

Thank you,
Mark

--

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/groups/opt_out.

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

I could make the choice just a number but the choices each have specific
text that must be displayed to guide the selection.
Is there a way to add "hint" text to each of the choices? The hint could
display the text.
Alternatively, I could have the text of each choice include the number
(such as "1. Confined to bed") and then use the substring function to parse
out the number.
However, I am a bit confused about the syntax of the substr operator. I
don't understand this:
extract a substringsubstr(xpath/to/value, start)
substr(xpath/to/value, start, end)calculate="substr('Test',1,2)='e'"returns
the substring beginning at the specified start and extends to the character
at index end - 1. start and end begin at '0'.

··· On Wed, Mar 6, 2013 at 12:55 PM, Mitch Sundt wrote:

If you wanted to, you could use a number 1, 2, etc. for the value of the
selection choice.

You could then use

number(/data/q1) + number(/data/q2) + ...

to convert the chosen value "1", "2", etc. (select-ones are always string
values) to numbers for your select questions (e.g., /data/q1 and /data/q2
etc. above) and add them up.

Otherwise, as you say, you would need to map whatever value you have for a
given label into a number, then add those up. If for some reason you must
keep the value a string, I would recommend using a calculated field to
store the numeric mapping for the value name, then adding up those
calculated numeric fields.

Mitch

On Wed, Mar 6, 2013 at 12:48 PM, Mark Spohr mhspohr@gmail.com wrote:

I have a set of six questions. Each of them is type select_one. The
questions each have 3 or 4 options.
I want to calculate a numeric score based on the answers to the six
questions.
If the selected answer to a question is the first option, this would be a
value of 1, second option, 2, etc.
Add up the numbers from all six questions to get a total score.
It looks like the "selected" operator would be useful but I would have to
do an elaborate test of each of the options for each of the questions to
see which one is selected.
The "selected-at" operator seems to apply only to multiple select
questions and it seems that I would also have to test each option.
Is there a function which will just give me the number (n)th of the
selected option for a select_one question?

Thank you,
Mark

--

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/groups/opt_out.

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

--

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 a topic in the
Google Groups "ODK Community" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/opendatakit/R9pwelsmTlY/unsubscribe?hl=en
.
To unsubscribe from this group and all its topics, send an email to
opendatakit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
Mark Spohr, MD
mhspohr@gmail.com
+1 530 554 2230

Hi Mark,
Choices have a name (aka value in xforms) and a label. The name will be
used in formulas that reference the choice. The label is used to guide
selection like the hint text you describe.
Regards,
-Nathan

··· On Wednesday, March 6, 2013 1:07:58 PM UTC-8, Mark Spohr wrote: > > I could make the choice just a number but the choices each have specific > text that must be displayed to guide the selection. > Is there a way to add "hint" text to each of the choices? The hint could > display the text. > Alternatively, I could have the text of each choice include the number > (such as "1. Confined to bed") and then use the substring function to parse > out the number. > However, I am a bit confused about the syntax of the substr operator. I > don't understand this: > extract a substring substr(xpath/to/value, start) > substr(xpath/to/value, start, end) calculate="substr('Test',1,2)='e'"returns the substring beginning at the specified start and extends to the > character at index end - 1. start and end begin at '0'. > > > On Wed, Mar 6, 2013 at 12:55 PM, Mitch Sundt <mitche...@gmail.com wrote: > >> If you wanted to, you could use a number 1, 2, etc. for the value of the >> selection choice. >> >> You could then use >> >> number(/data/q1) + number(/data/q2) + ... >> >> to convert the chosen value "1", "2", etc. (select-ones are always string >> values) to numbers for your select questions (e.g., /data/q1 and /data/q2 >> etc. above) and add them up. >> >> Otherwise, as you say, you would need to map whatever value you have for >> a given label into a number, then add those up. If for some reason you >> must keep the value a string, I would recommend using a calculated field to >> store the numeric mapping for the value name, then adding up those >> calculated numeric fields. >> >> Mitch >> >> On Wed, Mar 6, 2013 at 12:48 PM, Mark Spohr <mhs...@gmail.com wrote: >> >>> I have a set of six questions. Each of them is type select_one. The >>> questions each have 3 or 4 options. >>> I want to calculate a numeric score based on the answers to the six >>> questions. >>> If the selected answer to a question is the first option, this would be >>> a value of 1, second option, 2, etc. >>> Add up the numbers from all six questions to get a total score. >>> It looks like the "selected" operator would be useful but I would have >>> to do an elaborate test of each of the options for each of the questions to >>> see which one is selected. >>> The "selected-at" operator seems to apply only to multiple select >>> questions and it seems that I would also have to test each option. >>> Is there a function which will just give me the number (n)th of the >>> selected option for a select_one question? >>> >>> Thank you, >>> Mark >>> >>> >>> -- >>> -- >>> 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/groups/opt_out. >>> >>> >>> >> >> >> >> -- >> Mitch Sundt >> Software Engineer >> University of Washington >> mitche...@gmail.com >> >> -- >> -- >> 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 a topic in the >> Google Groups "ODK Community" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/opendatakit/R9pwelsmTlY/unsubscribe?hl=en >> . >> To unsubscribe from this group and all its topics, send an email to >> opendatakit...@googlegroups.com . >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > > > -- > Mark Spohr, MD > mhs...@gmail.com > +1 530 554 2230 > > >