mathewthe2 / immersion_reader

iOS Reader with Japanese popup dictionary
MIT License
27 stars 1 forks source link

Reading Goals #4

Open mathewthe2 opened 1 year ago

mathewthe2 commented 1 year ago

Reading goals and read time tracker

Example: Apple Books image

Design Draft:

Time tracking

Create a statistics database with a table Sessions(id, start, seconds, type, content_id). Add key-value setting for desired daily target with default = 15 minutes (900 seconds).

On launching a book, trigger a new session with the current date time.

On returning to home screen or app life cycle in [inactive, paused, detached], stop timer and save session to database.

Note: delegate inactive states to app life cycles instead of manually observing user behavior on the app.

On home screen, fetch Sessions with start time between 00.00 and 23.59.99 today. Sum all seconds for the total time read today. Sessions that go into the next day will be counted towards the day of the their start date. As such, it is possible to exceed 24 hours read time in one day.

Goals and Streaks

Add a table Goals(id, date, goal, total, session_ids)

On session creation to database, create new goal with date=today if such goal does not exist otherwise update such goal. Add session id to the goal and update towards the total. Update goal of today whenever user changes their goal.

On home screen streaks component, fetch all goals between start and end of current month. Get the percentage of goal completion by total/goal. On click each day, fetch all sessions by session_id.

Updating daily goal

When user updates daily goal, update both key-value setting of desired daily target as well as the goal row with date=today.

Note that goal setting is in seconds but displayed in minutes.

mathewthe2 commented 1 year ago

81f5fe7de67a3bf8a4632c36bd7062482ef9ca33 36f0c468bb0493d3757bd72cba9f8a8daac1fcfc b01bfc9ef8b5aba6baf8466750b8c4c28702106e 861020fa121c931422153aa71626ceda93a1c8a8 d752b987adcccbf232adb0d61c45ef3e14ce578d 9ec0bb42b5bda3aef9d6f1573c2a0a53fd2b235f