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
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!
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):
0/7=0
6/7=0.85
7/7=1
13/7=1.85
…
Then we can round the answers down using a “floor” function and get this:
floor(0/7)=0
floor(6/7)=0
floor(7/7)=1
floor(13/7)=1
…
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.
See the “@danielstebbins math” screen in this project:
https://x.thunkable.com/copy/0676d9efb5142638c347fd2a7dc36245
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!
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:
0.2
0.4
0.6
0.8
1
…
(A difference of 0.2)
For Temperature, it’s a difference of 7:
6
13
20
27
34
…
Which is why I divided by 7 in the formula I created for you.
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
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…
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.
Yes, I would like the user to change with values with the text inputs I shared a link to my project below
https://x.thunkable.com/copy/d5339e6d8854a3c71b643b6ec9ed5fd5
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 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.