Backend server for Sleep Tracker, a web app tracking sleep time and mood in order to optimize your sleep time.
https://sleep-tracker-rui.herokuapp.com/
.gitignore | ||
LICENSE | ||
package-lock.json | ||
package.json | ||
README.md |
Sleep Tracker helps Users track their sleep and mood every day. It gives Users a better idea of their sleep pattern and improve their health. After one month, Sleep Tracker will give recommendation of optimal sleep duration.
Target Audience
Sleep Tracker is intended for anyone interested in improving their sleep and health.
Features
- Homepage view shows a graph of your nightly hours of sleep over time .
- Ability to create a night’s sleep entry. For each date set (1/1/19-1/2/19), user can scroll through a digital clock image (like when you set your alarm on your phone, or just type in) to enter what time they got in bed and what time they woke up. From this data, app will calculate their total time in bed.
- Ability to edit or delete a sleep entry.
- Ability to click one of four emoji buttons to rate how they felt right when they woke up, how they felt during the day, and how tired they felt when they went to bed. Behind the scenes, a score 1-4 is given for each emoji.
- The app will calculate an average mood score for 1/2/19, and compare it to the time spent in bed. The app will then recommend after using for >1 month how much sleep you need. “Your mood score tends to be highest when you sleep 7.5 hours”
Possible further features
- Make recommendations not only based on sleep time, but also on bed time (some reasearch will need to be done in that area)
- Connect to third party sleep tracking services
Database Schemas
Users users
field | data type | metadata |
---|---|---|
id | unsigned integer | primary key, auto-increments, generated by database |
string | required | |
username | string | required |
password | string | required |
Sleep Sessions sessions
field | data type | metadata |
---|---|---|
id | unsigned integer | primary key, auto-increments, generated by database |
user_id | unsigned integer | foreign key referencing users.id , required |
bed_time | unsigned integer | timestamp with date, required |
wake_time | unsigned integer | timestamp with date, required |
bed_tiredness | unsigned integer | between 1-5, |
wake_mood | unsigned integer | between 1-5, |
day_mood | unsigned integer | between 1-5, |
Average Mood per Sleep Session moods
field | data type | metadata |
---|---|---|
id | unsigned integer | primary key, auto-increments, generated by database |
session_date | unsigned integer | foreign key referencing sessions.wake_time |
sleep_duration | unsigned integer | |
average_mood | float | average of bed_tiredness/wake_mood/day_mood |
API Endpoints
-
POST /api/users
- add a new user -
GET /api/users/:id
- fetch a user -
PUT /api/users/:id
- update a user -
GET /api/sessions
- fetch list of all sessions -
POST /api/sessions
- add a session -
GET /api/sessions/:id
- get a single session by id -
PUT /api/sessions/:id
- update a session by user id -
DELETE /api/sessions/:id
- delete a session by user id -
GET /api/moods/:id
- fetch a list of last 30 moods by user id