Baby Sleep Tracker ============= A personal baby sleep tracker
| |
We practice sleep training for our baby which involves tracking his wake and sleep patterns. Previously, we used a Google Sheet shared between several caregivers. Entering data into the Sheet is unwieldy especially for the less tech savvy, so I created a simple front end.
As this use case is specific to my needs, the app is not immediately useful to others. If you would like a starter template for Svelte, with built in PWA, Rollup, Tailwind and Now config, head over to svelte-pwa-now.
Otherwise, you can play around with this repo by cloning it (make sure you have NodeJS installed first).
Some work is required to set up a project on the Google Developers Console for authentication and API access.
credentials.js
like so:export const credentials = {
CLIENT_ID: YOUR_NEW_CLIENT_ID,
API_KEY: YOUR_NEW_API_KEY,
SCOPES: "https://www.googleapis.com/auth/spreadsheets",
DISCOVERY_DOCS: ["https://sheets.googleapis.com/$discovery/rest?version=v4"],
...
};
You will then need to create your own Google Sheet to act as the backend.
https://docs.google.com/spreadsheets/d/THIS_IS_THE_SPREADSHEET_ID/edit#gid=THIS_IS_THE_SHEET_ID
. The Sheet Name is simply the name of the sheet found in the bottom tab.credentials.js
like so:export const credentials = {
...
SPREADSHEET_ID: YOUR_SPREADSHEET_ID,
SHEET_NAME: YOUR_SHEET_NAME,
SHEET_ID: YOUR_SHEET_ID
};
You're all set! Now,
npm install
and then
npm run dev
will start the app at https://localhost:5000.
Build for production using
npm run build
and serve the dist
folder.
The main data entry logic is located at /components/Entry.svelte
. This will be your starting point if you would like to customize how data is recorded to the Google Sheet.
The function validateAndSend()
writes to the linked Sheet, including several additional cells of custom formulas related to sleep tracking. You can view the results by opening the Google Sheet after form submission.
The Summary page displays past trends and charts. The component is at /components/Summary.svelte
, including functions to plot charts at plotTWTVsFirstSleep(data)
and plotNapSleepTime(data)
. For references on how to use Chart.js, start here.
MIT