fitout


Namefitout JSON
Version 0.1.1 PyPI version JSON
download
home_pageNone
SummaryA Python library to extract FitBit Google Takeout data.
upload_time2024-11-25 11:12:44
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseNone
keywords fitbitbit google takeout data processing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # FitOut
[![GitHub license](https://img.shields.io/github/license/kev-m/FitOut)](https://github.com/kev-m/FitOut/blob/development/LICENSE.txt)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/fitout?logo=pypi)](https://pypi.org/project/fitout/)
[![semver](https://img.shields.io/badge/semver-2.0.0-blue)](https://semver.org/)
[![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/kev-m/FitOut?sort=semver)](https://github.com/kev-m/FitOut/releases)
[![Code style: autopep8](https://img.shields.io/badge/code%20style-autopep8-000000.svg)](https://pypi.org/project/autopep8/)

<!-- ![FitOut logo](https://github.com/kev-m/FitOut/blob/development/docs/source/figures/Logo_small.png) -->

The **FitOut** project is an open source Python library for extracting FitBit data from Google Takeout.

<!-- For detailed documentation, refer to the [FitOut Documentation](https://FitOut.readthedocs.io/). -->

## Installation

Use pip to install:
```bash
pip install fitout
```

## Example

How to use FitOut:

### Export
Export your [FitBit data](https://www.fitbit.com/settings/data/export), using [Google Takeout](https://takeout.google.com/settings/takeout/custom/fitbit?pli=1).

**Note:** Currently only export to zip is supported, and the zip files must be extracted to your local drive.

Once the export is complete, download the zip file and extract it. I use `C:/Dev/Fitbit/Google/`. 
This directory is the `takeout_dir`.

### Trivial Example
```python
import fitout as fo
from datetime import date

def main():
    # Specify the location where the Takeout zip files was extracted
    takeout_dir = 'C:/Dev/Fitbit/Google/'
    # Use the NativeFileLoader to load the data from the extracted files
    data_source = fo.NativeFileLoader(takeout_dir)
    
    # Specify the desired date range.
    start_date = date(2024, 10, 1)
    end_date = date(2024, 10, 31)
    
    # Generate a list of dates for the date range, for informational or plotting purposes.
    dates = fo.dates_array(start_date, end_date)
    print("Dates:", dates)
    
    # Create the breathing rate importer and fetch the data.
    breather_importer = fo.BreathingRate(data_source, 1)
    breathing_data = breather_importer.get_data(start_date, end_date)
    print("Breathing rate:", breathing_data)
    
    # Create the heart rate variability importer and fetch the data.
    hrv_importer = fo.HeartRateVariability(data_source)
    hrv_data = hrv_importer.get_data(start_date, end_date)
    print("HRV:", hrv_data)
    
    # Create the resting heart rate importer and fetch the data.
    rhr_importer = fo.RestingHeartRate(data_source)
    rhr_data = rhr_importer.get_data(start_date, end_date)
    print("RHR:", rhr_data)


if __name__ == "__main__":
    main()
```

### Plotting Example with Numpy and Matplotlib
**Note:** To run this example, you will need to install the dependencies:
```bash
pip install matplotlib numpy
```

```python
from datetime import date
import numpy as np
import matplotlib.pyplot as plt
import fitout as fo

def main():
    # Specify the location where the Takeout zip files was extracted
    takeout_dir = 'C:/Dev/Fitbit/Google/'
    # Use the NativeFileLoader to load the data from the extracted files
    data_source = fo.NativeFileLoader(takeout_dir)

    # Specify the desired date range.
    start_date = date(2024, 10, 1)
    end_date = date(2024, 10, 31)

    # Generate a list of dates for the date range, for informational or plotting purposes.
    dates = fo.dates_array(start_date, end_date)

    # Create the breathing rate importer and fetch the data.
    breather_importer = fo.BreathingRate(data_source, 1)
    breathing_data = breather_importer.get_data(start_date, end_date)

    # Create the heart rate variability importer and fetch the data.
    hrv_importer = fo.HeartRateVariability(data_source)
    hrv_data = hrv_importer.get_data(start_date, end_date)

    # Create the resting heart rate importer and fetch the data.
    rhr_importer = fo.RestingHeartRate(data_source)
    rhr_data = rhr_importer.get_data(start_date, end_date)

    # Fill in missing values with the mean of the neighbouring values
    breathing_data = fo.fill_missing_with_neighbours(breathing_data)
    hrv_data = fo.fill_missing_with_neighbours(hrv_data)
    rhr_data = fo.fill_missing_with_neighbours(rhr_data)

    # Adjust buggy data (typically values that are too high or too low) to the mean of the neighbouring values
    # These values depend on your personal ranges.
    breathing_data = fo.fix_invalid_data_points(breathing_data, 10, 20)
    hrv_data = fo.fix_invalid_data_points(hrv_data, 20, 50)
    rhr_data = fo.fix_invalid_data_points(rhr_data, 46, 54)

    # Convert lists to numpy arrays
    dates_array = np.asarray(dates)
    breathing_data_array = np.array(breathing_data).astype(float)
    hrv_data_array = np.array(hrv_data).astype(float)
    rhr_data_array = np.array(rhr_data).astype(float)


    # Create a combined calmness index as follows: 100-(RHR/2 + breathing rate*2 - HRV)
    calmness_index = 100 - (rhr_data_array / 2. + breathing_data_array * 2. - hrv_data_array)

    # Plot the calmness index
    plt.figure(figsize=(10, 6))
    plt.plot(dates_array, calmness_index, marker='o', linestyle='-', color='b')
    plt.xlabel('Date')
    plt.ylabel('Calmness Index')
    plt.title('Calmness Index Over Time')
    plt.ylim(60, 95)  # Set the y-range
    plt.grid(True)
    plt.xticks(rotation=45)
    plt.tight_layout()  
    # Fit a 4th order polynomial to the calmness index data
    dates_axis = np.arange(len(dates_array))
    polynomial_coefficients = np.polyfit(dates_axis, calmness_index, 4)
    polynomial = np.poly1d(polynomial_coefficients)
    fitted_calmness_index = polynomial(dates_axis)

    # Plot the fitted polynomial
    plt.plot(dates_array, fitted_calmness_index, linestyle='--', color='r', label='4th Order Polynomial Fit')
    plt.legend()

    plt.show()

    plt.show()
if __name__ == "__main__":
    main()
```

### More Examples

For more examples, see the [examples](https://github.com/kev-m/FitOut/tree/development/examples) directory.

## Contributing

If you'd like to contribute to **FitOut**, follow the guidelines outlined in the [Contributing Guide](https://github.com/kev-m/FitOut/blob/development/CONTRIBUTING.md).

## License

See [`LICENSE.txt`](https://github.com/kev-m/FitOut/blob/development/LICENSE.txt) for more information.

## Contact

For inquiries and discussion, use [FitOut Discussions](https://github.com/kev-m/FitOut/discussions).

## Issues

For issues related to this Python implementation, visit the [Issues](https://github.com/kev-m/FitOut/issues) page.



            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "fitout",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "FitBitbit, Google Takeout, Data Processing",
    "author": null,
    "author_email": "Kevin Meyer <kevin@kmz.co.za>",
    "download_url": "https://files.pythonhosted.org/packages/2f/61/db30b55eeb7b7d1b01fe2f485107ec5b36417dc788e5c2be72db9602155e/fitout-0.1.1.tar.gz",
    "platform": null,
    "description": "# FitOut\n[![GitHub license](https://img.shields.io/github/license/kev-m/FitOut)](https://github.com/kev-m/FitOut/blob/development/LICENSE.txt)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/fitout?logo=pypi)](https://pypi.org/project/fitout/)\n[![semver](https://img.shields.io/badge/semver-2.0.0-blue)](https://semver.org/)\n[![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/kev-m/FitOut?sort=semver)](https://github.com/kev-m/FitOut/releases)\n[![Code style: autopep8](https://img.shields.io/badge/code%20style-autopep8-000000.svg)](https://pypi.org/project/autopep8/)\n\n<!-- ![FitOut logo](https://github.com/kev-m/FitOut/blob/development/docs/source/figures/Logo_small.png) -->\n\nThe **FitOut** project is an open source Python library for extracting FitBit data from Google Takeout.\n\n<!-- For detailed documentation, refer to the [FitOut Documentation](https://FitOut.readthedocs.io/). -->\n\n## Installation\n\nUse pip to install:\n```bash\npip install fitout\n```\n\n## Example\n\nHow to use FitOut:\n\n### Export\nExport your [FitBit data](https://www.fitbit.com/settings/data/export), using [Google Takeout](https://takeout.google.com/settings/takeout/custom/fitbit?pli=1).\n\n**Note:** Currently only export to zip is supported, and the zip files must be extracted to your local drive.\n\nOnce the export is complete, download the zip file and extract it. I use `C:/Dev/Fitbit/Google/`. \nThis directory is the `takeout_dir`.\n\n### Trivial Example\n```python\nimport fitout as fo\nfrom datetime import date\n\ndef main():\n    # Specify the location where the Takeout zip files was extracted\n    takeout_dir = 'C:/Dev/Fitbit/Google/'\n    # Use the NativeFileLoader to load the data from the extracted files\n    data_source = fo.NativeFileLoader(takeout_dir)\n    \n    # Specify the desired date range.\n    start_date = date(2024, 10, 1)\n    end_date = date(2024, 10, 31)\n    \n    # Generate a list of dates for the date range, for informational or plotting purposes.\n    dates = fo.dates_array(start_date, end_date)\n    print(\"Dates:\", dates)\n    \n    # Create the breathing rate importer and fetch the data.\n    breather_importer = fo.BreathingRate(data_source, 1)\n    breathing_data = breather_importer.get_data(start_date, end_date)\n    print(\"Breathing rate:\", breathing_data)\n    \n    # Create the heart rate variability importer and fetch the data.\n    hrv_importer = fo.HeartRateVariability(data_source)\n    hrv_data = hrv_importer.get_data(start_date, end_date)\n    print(\"HRV:\", hrv_data)\n    \n    # Create the resting heart rate importer and fetch the data.\n    rhr_importer = fo.RestingHeartRate(data_source)\n    rhr_data = rhr_importer.get_data(start_date, end_date)\n    print(\"RHR:\", rhr_data)\n\n\nif __name__ == \"__main__\":\n    main()\n```\n\n### Plotting Example with Numpy and Matplotlib\n**Note:** To run this example, you will need to install the dependencies:\n```bash\npip install matplotlib numpy\n```\n\n```python\nfrom datetime import date\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport fitout as fo\n\ndef main():\n    # Specify the location where the Takeout zip files was extracted\n    takeout_dir = 'C:/Dev/Fitbit/Google/'\n    # Use the NativeFileLoader to load the data from the extracted files\n    data_source = fo.NativeFileLoader(takeout_dir)\n\n    # Specify the desired date range.\n    start_date = date(2024, 10, 1)\n    end_date = date(2024, 10, 31)\n\n    # Generate a list of dates for the date range, for informational or plotting purposes.\n    dates = fo.dates_array(start_date, end_date)\n\n    # Create the breathing rate importer and fetch the data.\n    breather_importer = fo.BreathingRate(data_source, 1)\n    breathing_data = breather_importer.get_data(start_date, end_date)\n\n    # Create the heart rate variability importer and fetch the data.\n    hrv_importer = fo.HeartRateVariability(data_source)\n    hrv_data = hrv_importer.get_data(start_date, end_date)\n\n    # Create the resting heart rate importer and fetch the data.\n    rhr_importer = fo.RestingHeartRate(data_source)\n    rhr_data = rhr_importer.get_data(start_date, end_date)\n\n    # Fill in missing values with the mean of the neighbouring values\n    breathing_data = fo.fill_missing_with_neighbours(breathing_data)\n    hrv_data = fo.fill_missing_with_neighbours(hrv_data)\n    rhr_data = fo.fill_missing_with_neighbours(rhr_data)\n\n    # Adjust buggy data (typically values that are too high or too low) to the mean of the neighbouring values\n    # These values depend on your personal ranges.\n    breathing_data = fo.fix_invalid_data_points(breathing_data, 10, 20)\n    hrv_data = fo.fix_invalid_data_points(hrv_data, 20, 50)\n    rhr_data = fo.fix_invalid_data_points(rhr_data, 46, 54)\n\n    # Convert lists to numpy arrays\n    dates_array = np.asarray(dates)\n    breathing_data_array = np.array(breathing_data).astype(float)\n    hrv_data_array = np.array(hrv_data).astype(float)\n    rhr_data_array = np.array(rhr_data).astype(float)\n\n\n    # Create a combined calmness index as follows: 100-(RHR/2 + breathing rate*2 - HRV)\n    calmness_index = 100 - (rhr_data_array / 2. + breathing_data_array * 2. - hrv_data_array)\n\n    # Plot the calmness index\n    plt.figure(figsize=(10, 6))\n    plt.plot(dates_array, calmness_index, marker='o', linestyle='-', color='b')\n    plt.xlabel('Date')\n    plt.ylabel('Calmness Index')\n    plt.title('Calmness Index Over Time')\n    plt.ylim(60, 95)  # Set the y-range\n    plt.grid(True)\n    plt.xticks(rotation=45)\n    plt.tight_layout()  \n    # Fit a 4th order polynomial to the calmness index data\n    dates_axis = np.arange(len(dates_array))\n    polynomial_coefficients = np.polyfit(dates_axis, calmness_index, 4)\n    polynomial = np.poly1d(polynomial_coefficients)\n    fitted_calmness_index = polynomial(dates_axis)\n\n    # Plot the fitted polynomial\n    plt.plot(dates_array, fitted_calmness_index, linestyle='--', color='r', label='4th Order Polynomial Fit')\n    plt.legend()\n\n    plt.show()\n\n    plt.show()\nif __name__ == \"__main__\":\n    main()\n```\n\n### More Examples\n\nFor more examples, see the [examples](https://github.com/kev-m/FitOut/tree/development/examples) directory.\n\n## Contributing\n\nIf you'd like to contribute to **FitOut**, follow the guidelines outlined in the [Contributing Guide](https://github.com/kev-m/FitOut/blob/development/CONTRIBUTING.md).\n\n## License\n\nSee [`LICENSE.txt`](https://github.com/kev-m/FitOut/blob/development/LICENSE.txt) for more information.\n\n## Contact\n\nFor inquiries and discussion, use [FitOut Discussions](https://github.com/kev-m/FitOut/discussions).\n\n## Issues\n\nFor issues related to this Python implementation, visit the [Issues](https://github.com/kev-m/FitOut/issues) page.\n\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A Python library to extract FitBit Google Takeout data.",
    "version": "0.1.1",
    "project_urls": {
        "Bug tracker": "https://github.com/kev-m/FitOut/issues",
        "Changelog": "https://github.com/kev-m/FitOut/blob/release/CHANGELOG.md",
        "Code of Conduct": "https://github.com/kev-m/FitOut/blob/release/CODE_OF_CONDUCT.md",
        "Contributing": "https://github.com/kev-m/FitOut/blob/release/CONTRIBUTING.md",
        "Home": "https://github.com/kev-m/FitOut",
        "Source": "https://github.com/kev-m/FitOut"
    },
    "split_keywords": [
        "fitbitbit",
        " google takeout",
        " data processing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7a87efc4e615c788041e1f113c331f14995f2d7c45733d3c74fa7f5c2d0f38fc",
                "md5": "17477260f0d5e52e1bf305df26c95400",
                "sha256": "5513d74246258bbaf9dd2d5b558ab83be4def296f10fdfb9775d4e17ae00345f"
            },
            "downloads": -1,
            "filename": "fitout-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "17477260f0d5e52e1bf305df26c95400",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 19041,
            "upload_time": "2024-11-25T11:12:42",
            "upload_time_iso_8601": "2024-11-25T11:12:42.675558Z",
            "url": "https://files.pythonhosted.org/packages/7a/87/efc4e615c788041e1f113c331f14995f2d7c45733d3c74fa7f5c2d0f38fc/fitout-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2f61db30b55eeb7b7d1b01fe2f485107ec5b36417dc788e5c2be72db9602155e",
                "md5": "8b757a3ec4884d63515c439f8c1558af",
                "sha256": "298aab66fbea23ae3a4e614c8620489590708a29283b2dec9f362bce8d66a43d"
            },
            "downloads": -1,
            "filename": "fitout-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "8b757a3ec4884d63515c439f8c1558af",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 22708,
            "upload_time": "2024-11-25T11:12:44",
            "upload_time_iso_8601": "2024-11-25T11:12:44.025525Z",
            "url": "https://files.pythonhosted.org/packages/2f/61/db30b55eeb7b7d1b01fe2f485107ec5b36417dc788e5c2be72db9602155e/fitout-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-25 11:12:44",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kev-m",
    "github_project": "FitOut",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "fitout"
}
        
Elapsed time: 0.41863s