Help: How to create Points + Levels system and save progress using TinyDB

Hello,
I am building an app on MIT App Inventor and I need help designing a points + levels system.

Goal of the system:

User enters a daily water consumption limit (Example: 5 Liters)

Every day, the user enters the actual consumption

If the real consumption is less than the limit, the user earns points

When points reach a certain number (example: 100), the user levels up

What I need:

:white_check_mark: How to increase points
:white_check_mark: How to upgrade levels automatically
:white_check_mark: How to save both values using TinyDB so the user doesn’t lose progress

Example Logic:

If ActualConsumption < DailyLimit:
Points = Points + 10

If Points >= 100:
Level = Level + 1
Points = 0

TinyDB Tags I plan to use:

"DailyLimit"

"Points"

"Level"

If someone can show me example blocks or guide me on the best way to do this, I would really appreciate it.

Thanks!

Try a search

I tried and found some ideas that were somewhat similar, but I didn't understand them well and I didn't find a sufficient explanation.

All you need to save is the daily consumption.

The other quantities can be derived by counting forwards from the first day.

Save consumption under the yyyyMmdd date of that consumption.