Setting a Score based off a range of numbers

I’m working on a project where I need to assign a score to a range of possible numbers. I’m not entirely sure where to start. I attached a screenshot of what I’ve been fiddling around with. Am I on the right track? Using the table below as an example, ideally I’d like to be able to assign any temperature input from 0-6 degrees as a 5, and any distance input from 1.1 to 1.2 miles as a 3. From there I’d like to add two scores (In this case 5 and 3) to reach a final score. Is there anyone who could help me out? Thanks :slight_smile:

It’s certainly possible to do this with a series of if > and ≤ statements as you demonstrated but it’s a pain and well, there’s a reason we have math! :wink:

I usually think about this by starting with the extreme values of each range. So if we divide by the difference in rows (each row is 7 apart from the one above it):


Then we can round the answers down using a “floor” function and get this:

Why is this useful? Well, if we start with the value 5 which is your highest score, we can subtract 0.5 for each row:

Score = 5 - (0.5 * floor(Temperature / 7)

I think that will work! Now it’s just a matter of finding the right blocks to make that equation.

1 Like

See the “@danielstebbins math” screen in this project:

Note that the equation won’t work for values above 62 so you’ll need to check for those and adjust.

Thank you so much for your help! The screenshot you posted really helped me to understand some of the blocks a lot better. I’ve been messing around with the idea you gave me and I’m having trouble getting my final score with the layout I designed before. What I’m struggling with is getting the inputs for temperature and distance to convert to the score and then add together in the final score box. Thanks again for your help! :slight_smile:

The Distance formula you’re using has a divisor of 5 but the difference between each row is 0.2 so you need to divide by 0.2 not 5.

The way I’m calculating that is by looking at the last number in each row:


(A difference of 0.2)

For Temperature, it’s a difference of 7:

Which is why I divided by 7 in the formula I created for you.

1 Like

I changed the number I was dividing by from 5 to 0.2 and no matter what inputs I put in to temperature or distance I only get 10 or 5. I’m wondering how to get the scores to correspond to my table, and then take add the two scores for a final score out of 10. Thanks :slight_smile:

You’re using the same equations I provided in my demo. So the only thing I can think of is that you are not updating the values when the Temperature or Distance changes. But I can’t see the rest of your project. Can you share a link with me?

Edit: It looks like those are all of the blocks you’re using. So you’re setting Temperature and Distance to zero when the screen opens and then the Scores get calculated immediately. So 5 minus 0 equals 5. That’s why you get 5 every time.

How are you going to allow the user to change the values of those variables? I assume you’ll want to use the textinput's text blocks from the Text Input drawer in place of the Temperature and Distance variables.

Maybe i didn’t understand right your requirement, as I see a lot of math here, and I’m thinking a straight solution as a CASE IF:

You do same for distance and you get scores easy… :thinking:

PS.: If you are not familiar with CASE statement, in that block, app will execute first condition met and then will go further. For example, if TEMPERATURE is 58, will check if 58 >=63 - NOT, then if 58>=56 - YES so temperatureSCORE will be 1 then go to the next block.

1 Like

Yes, I would like the user to change with values with the text inputs I shared a link to my project below :slight_smile:

Like this:

Note that for Score 2, you should not add or subtract anything to the product. So I left it as 0 + … instead of 5 + …


Awesome! That’s just what I needed :slight_smile: Is there any way to make it so any score above 63 for temperature and any score above 2 miles for distance would result in a score of 5? Thanks again!

Sure, just use an If/Else block and set up the logic and math blocks to check for that.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.