### Post

3 followers Follow

# Scoring Category Fields

We train service dogs for children with autism.  As part of that, we evaluate the dogs at points during their training to give them a "score" to see how they're doing.  My challenge is trying to convert a "word" category option to a "number" that can provide a numerical score.

Category: Out (Single Choice, Inline Category Field)

Option 1: Lagger

Calculation: "Lagger" should = 0 and "Leader" should = 1

So the Calculation field should output a 0 or 1 depending on whether the trainer selects Lagger or Leader

I hope I'm making sense!

So first, I'm not sure how to assign the numerics to the Options and then do the calculation.  Can this be done in one Calculation field?

Second, I will need another Calculation field that adds up all the Scores (i.e. @OutScore + @BackScore + @GaitScore = TotalScore) which would be the Total Numeric Score

Oh and I train dogs for kids, not write code, so if you could help explain in Captain Dummy talk so I can understand, that would be fantastic!! I have seen a few similar posts in the forum, but not sure I'm getting it.

Thanks!

Jim

Jim Cantrell

Hi Jim,

it works this way for each category field:

var field = @OutScore;
var option1 = "Lagger";
field == option1 ? 0 : field == option2 ? 1 : null

If a score field has more than 2 options:

var field = @XYZScore;
var option1 = "A";
var option2 = "B";
var option3 = "C";
var option4 = "D";
field == option1 ? 0 : field == option2 ? 1 :  field == option3 ? 2 :  field == option4 ? 3 : null

Read it as: IF equal to (==) THEN (?) ELSE (:). You must always end it with an ELSE; null means - show nothing
I use the version with vars (= variables) cause that you can copy and paste into each score calculation field, you need to change the values (like "A", "B" etc) only (and the value for var field)

@OutScoreCalculation +  @BackScoreCalculation + @GaitScoreCalculation

Hope that helps you for your very important job!
Greetings from an owner of 2 dogs to the dog trainer.

Rainer

Ok my dog is a bit rusty but here you go.

Bark ruff snuffle woof sniff tail wag grrr yip. Head shake woof ruff roll over yip. Cover head with paws jump up woof grrr sniff bark.

For those not fluent in dog or in case I made a mess of that translation:

Make a calculation field that looks like this.

@field_name == "Leader" ? 1 : 0

If you had more options then just the two than it would take something a bit more complicated.

BTW on your second question you for it right.

Make a calculation field Total Numeric Score that would be: @OutScore + @BackScore + @GaitScore

Remember you can't use a new created calculation field in a subsequent calculation field until you have saved one time.