{"id":13631528,"url":"https://github.com/rynoV/smart-sleep","last_synced_at":"2025-04-17T22:31:04.542Z","repository":{"id":41412088,"uuid":"258637219","full_name":"rynoV/smart-sleep","owner":"rynoV","description":"Use ML and Fitbit data to improve sleep","archived":false,"fork":false,"pushed_at":"2023-01-06T04:25:06.000Z","size":1885,"stargazers_count":4,"open_issues_count":12,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-08-01T22:48:48.278Z","etag":null,"topics":["fitbit","ml","sensor-data"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rynoV.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-24T22:22:50.000Z","updated_at":"2022-07-01T13:43:26.000Z","dependencies_parsed_at":"2023-02-05T07:15:48.346Z","dependency_job_id":null,"html_url":"https://github.com/rynoV/smart-sleep","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rynoV%2Fsmart-sleep","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rynoV%2Fsmart-sleep/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rynoV%2Fsmart-sleep/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rynoV%2Fsmart-sleep/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rynoV","download_url":"https://codeload.github.com/rynoV/smart-sleep/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223768501,"owners_count":17199355,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fitbit","ml","sensor-data"],"created_at":"2024-08-01T22:02:29.035Z","updated_at":"2024-11-08T23:30:53.398Z","avatar_url":"https://github.com/rynoV.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Smart Sleep\n\n\u003e **Note**: The development of this project has been moved to another (private) repository.\n\nAn application to use data from a Fitbit device and machine learning to wake the\nuser up during REM sleep.\n\n## Data\n\nWe will collect heart-rate and accelerometer data to use as input and use\nFitbit's sleep API for the labels.\n\n### Retrospective Input\n\n- Heart-rate data with 1 second granularity can be retrieved from the Fitbit\n API.\n- Accelerometer data is not stored automatically, so each night during sleep we\nwill collect accelerometer data, store it (using the companion's local storage\nmost likely), and when the sleep is finished we will send the data to the\nserver and clear the local stored data.\n    - We will collect the accelerometer data in batches with a certain number\n    of readings each second and average the x, y, and z values for each second.\n\n### Labels\n\n- Fitbit's sleep API gives sleep stages data which we will use as labels. The\n different sleep stages it returns are `wake`, `light`, `deep`, and `rem`. It\n  gives an array of objects each representing a portion of the sleep spent in\n   a certain stage. For example:\n```json5\n[\n  {\n    \"dateTime\": \"2020-04-27T22:47:00.000\",\n    \"level\": \"wake\",\n    \"seconds\": 300\n  },\n  {\n    \"dateTime\": \"2020-04-27T22:52:00.000\",\n    \"level\": \"light\",\n    \"seconds\": 1050\n  },\n  {\n    \"dateTime\": \"2020-04-27T23:09:30.000\",\n    \"level\": \"deep\",\n    \"seconds\": 480\n  },\n  // ...\n]\n```\n- It also gives `shortData` which contains `wake` sleep portions less than 3\n minutes in length. These will need to be merged into the rest of the data.\n\n### Training\n\n- We will gather all the heart and accelerometer data into our input matrix\n(with their times lined up), and assign each item a sleep stage label based on\nwhich sleep portion they fall in.\n- We can retrain the model after each night.\n\n### Evaluating\n\n- A set period before the user's desired wake-up time, we will start sending\n heart and accelerometer data to the server which can then use the model to\n  predict the sleep stage of the user and send off a signal to an alarm if\n   the predicted sleep stage is `wake` or `rem`.\n\n## Server-Fitbit Communication\n\nThe companion for the Fitbit communicates with the server via HTTP. The\nFitbit application has an IP address setting whose value is used to construct\nthe server's URL.\n\n### Finding the Server's IP Address\n\nThe server will use the IP address of its host machine and print that to the\nconsole. You can also find the IP address of the host machine using `ifconfig`\non Linux or `ipconfig` on Windows and looking for a `inet` or `IPv4 Address` IP\nunder a wifi interface if you're on wifi.\n\n#### WSL2 IP Address\n\nAt the time of writing, when running the server on WSL2 (Windows Subsystem for\nLinux 2) the IP of the host will not be accessible from other computers (namely\nthe phone running the Fitbit mobile app) due to the networking changes\nintroduced with WSL2. There are a few solutions:\n\n- [This\n  comment](https://github.com/microsoft/WSL/issues/4150#issuecomment-504209723)\n  has a potential workaround\n- Use WSL1\n- Use Windows\n\n### Ensuring Connection\n\nI am assuming the server is on the same network as Fitbit mobile app when a\nconnection is attempted. If you are not on the same network additional steps may\nbe required. If you are on the same network and are having trouble connecting,\nyou may have to allow traffic on the server's port.\n[Here](https://www.devopinion.com/access-localhost-from-another-computer-on-the-same-network/)\nis a guide for doing that on Windows.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FrynoV%2Fsmart-sleep","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FrynoV%2Fsmart-sleep","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FrynoV%2Fsmart-sleep/lists"}