orangepineapple
New member
- Joined
- Feb 15, 2020
- Messages
- 3
So I'm a little stuck on this.
A plant needs to be watered four times over the course of minimum 48 hours as it's growth increases by percentage up to 100%.
This means that for every 12 hours, the plant needs to be watered once. If it has not been watered, the percentage will stop at it's limit (i.e. if it has been watered only once, it will stop at 25%) and it's growth will stop increasing by the second. I need to write a piece of code which will calculate this every second, and return the percentage growth. Instead of having the code check for 48 hours and update the database with new growth every second, I want to use math and calculate this instead.
What we know is:
- the time the plant began growing
- the last time it was watered
- the amount of times it's been watered.
Here's the code I'm working with, if anyone understands it:
So far, I've calculated the percentage growth using (current time - begin time / end time). How can I dynamically limit the growth and calculate this percentage by the number of time's it's been watered, and resume it from that point once the plant has been watered using the last time it was watered? Essentially I need an equation which will do all of this using the information provided, if it's even possible.
Any help would be appreciated c:
A plant needs to be watered four times over the course of minimum 48 hours as it's growth increases by percentage up to 100%.
This means that for every 12 hours, the plant needs to be watered once. If it has not been watered, the percentage will stop at it's limit (i.e. if it has been watered only once, it will stop at 25%) and it's growth will stop increasing by the second. I need to write a piece of code which will calculate this every second, and return the percentage growth. Instead of having the code check for 48 hours and update the database with new growth every second, I want to use math and calculate this instead.
What we know is:
- the time the plant began growing
- the last time it was watered
- the amount of times it's been watered.
Here's the code I'm working with, if anyone understands it:
Code:
function GetMaturity()
on_going = time - time_planted
maturity = round(on_going / 172800, 3)
if maturity > 1 then
return 1.0
else
return maturity
end
end
function GetNeedsWater()
on_going = time - time_planted
maturity = round(on_going / 172800, 3)
percentage = maturity / 0.25
water_level = round(1 - percentage - number_of_times_watered, 3)
if water_level < 0 then
return 0.0
else
return water_level
end
end
So far, I've calculated the percentage growth using (current time - begin time / end time). How can I dynamically limit the growth and calculate this percentage by the number of time's it's been watered, and resume it from that point once the plant has been watered using the last time it was watered? Essentially I need an equation which will do all of this using the information provided, if it's even possible.
Any help would be appreciated c:
Last edited: