sport-activities-features


Namesport-activities-features JSON
Version 0.4.0 PyPI version JSON
download
home_pagehttps://github.com/firefly-cpp/sport-activities-features
SummaryA minimalistic toolbox for extracting features from sport activity files
upload_time2024-03-29 10:13:46
maintainerNone
docs_urlNone
authorIztok Fister Jr.
requires_python<4.0.0,>=3.9.0
licenseMIT
keywords computational intelligence cycling data mining datasets gpx optimization sport activities tcx
VCS
bugtrack_url
requirements matplotlib geopy overpy geotiler numpy tcxreader pandas niaaml tcx2gpx gpxpy ruff pytest
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <p align="center">
  <img width="200" src="https://raw.githubusercontent.com/firefly-cpp/sport-activities-features/main/.github/logo/sport_activities.png">
</p>

---

# sport-activities-features --- A minimalistic toolbox for extracting features from sports activity files written in Python

---

[![PyPI Version](https://img.shields.io/pypi/v/sport-activities-features.svg)](https://pypi.python.org/pypi/sport-activities-features)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/sport-activities-features.svg)
[![Documentation Status](https://readthedocs.org/projects/sport-activities-features/badge/?version=latest)](https://sport-activities-features.readthedocs.io/en/latest/?badge=latest)
![PyPI - Downloads](https://img.shields.io/pypi/dm/sport-activities-features.svg)
[![Downloads](https://pepy.tech/badge/sport-activities-features)](https://pepy.tech/project/sport-activities-features)
![GitHub repo size](https://img.shields.io/github/repo-size/firefly-cpp/sport-activities-features?style=flat-square)
[![GitHub license](https://img.shields.io/github/license/firefly-cpp/sport-activities-features.svg)](https://github.com/firefly-cpp/sport-activities-features/blob/master/LICENSE)
![GitHub commit activity](https://img.shields.io/github/commit-activity/w/firefly-cpp/sport-activities-features.svg)
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/firefly-cpp/sport-activities-features.svg)](http://isitmaintained.com/project/firefly-cpp/sport-activities-features "Average time to resolve an issue")
[![Percentage of issues still open](http://isitmaintained.com/badge/open/firefly-cpp/sport-activities-features.svg)](http://isitmaintained.com/project/firefly-cpp/sport-activities-features "Percentage of issues still open")
[![All Contributors](https://img.shields.io/badge/all_contributors-6-orange.svg?style=flat-square)](#contributors-)
[![Fedora package](https://img.shields.io/fedora/v/python3-sport-activities-features?color=blue&label=Fedora%20Linux&logo=fedora)](https://src.fedoraproject.org/rpms/python-sport-activities-features)
[![AUR package](https://img.shields.io/aur/version/python-sport-activities-features?color=blue&label=Arch%20Linux&logo=arch-linux)](https://aur.archlinux.org/packages/python-sport-activities-features)
[![Packaging status](https://repology.org/badge/tiny-repos/python:sport-activities-features.svg)](https://repology.org/project/python:sport-activities-features/versions)
[![DOI](https://img.shields.io/badge/DOI-10.1109/INES52918.2021.9512927-blue)](https://doi.org/10.1109/INES52918.2021.9512927)

* **Free software:** MIT license
* **Python versions:** 3.8.x, 3.9.x, 3.10.x, 3.11.x, 3.12.x
* **Documentation:** https://sport-activities-features.readthedocs.io/en/latest
* **Tested OS:** Windows, Ubuntu, Debian, Fedora, Alpine, Arch, macOS. **However, that does not mean it does not work on others.**

## Unleashing the Power of Sports Activity Analysis: A Framework Beyond Ordinary Metrics πŸš€

Prepare to dive into the thrilling world of sports activity analysis, where hidden geographic, topological, and personalized data await their grand unveiling. In this captivating journey, we embark on a quest to extract the deepest insights from the wealth of information generated by monitoring sports activities. Brace yourself for a framework that transcends the limitations of conventional analysis techniques. πŸ’ͺπŸ”

Traditional approaches often rely on integral metrics like total duration, total distance, and average heart rate, but they fall victim to the dreaded "overall metrics problem." These metrics fail to capture the essence of sports activities, omitting crucial components and leading to potentially flawed and misleading conclusions. They lack the ability to recognize distinct stages and phases of the activity, such as the invigorating warm-up, the endurance-testing main event, and the heart-pounding intervals. β±οΈπŸš΄β€β™€οΈπŸ“ˆ

Fortunately, our sport-activities-framework rises above these limitations, revealing a comprehensive panorama of your sports activity files. This framework combines the power of identification and extraction methods to unlock a treasure trove of valuable data. Picture this :camera: : effortlessly identifying the number of hills, extracting average altitudes of these remarkable formations, measuring the total distance conquered on those inclines, and even deriving climbing ratios for a true measure of accomplishment (total distance of hills vs. total distance). But that's just the tip of the iceberg! The framework seamlessly integrates a multitude of extensions, including historical weather parsing, statistical evaluations, and ex-post visualizations that bring your data to life. πŸ—»πŸ“ŠπŸŒ¦οΈ

For those seeking to venture further, we invite you to explore the realms of scientific papers on data mining that delve into these captivating topics. Discover how our framework complements the world of generating and predicting automated sport training sessions, creating a harmonious synergy between theory and practice. πŸ“šπŸ”¬πŸ’‘

## Detailed insights πŸ”

Prepare to be astounded by the capabilities of the sport-activities-features framework. It effortlessly handles TCX & GPX activity files and harnesses the power of the [Overpass API](https://wiki.openstreetmap.org/wiki/Overpass_API) nodes. Presenting the range of functions at your disposal:

- **Unleash the integral metrics**: From total distance to total duration and even calorie count, witness the extraction of these vital statistics with a single glance. πŸ“β°πŸ”₯ ([See example](examples/integral_metrics_extraction.py))

- **Conquer the peaks**: Ascend to new heights by extracting topographic features like the number of hills, their average altitudes, the total distance covered on these majestic slopes, and the thrilling climbing ratio. Prepare for a breathtaking adventure! β›°οΈπŸ“ˆπŸ§—β€β™‚οΈ ([See example](examples/hill_data_extraction.py))

- **Embark on a visual journey**: Immerse yourself in the beauty of your accomplishments as you plot the identified hills on a mesmerizing map. Witness the landscape come alive before your eyes. πŸ—ΊοΈπŸžοΈπŸ–ŒοΈ ([See example](examples/draw_map_with_identified_hills.py))

- **Embrace the rhythm of intervals**: Explore the intervals within your sports activities, uncovering their numbers, durations, distances, and heart rates. Unveil the heartbeat of your performance! πŸƒβ€β™€οΈπŸ“ŠπŸ’“ ([See example](examples/draw_map_with_identified_intervals.py))

- **Calculate the training loads**: Dive deep into the intricate world of training loads and discover the Banister TRIMP and Lucia TRIMP methods. Gain invaluable insights into optimizing your training regimen. πŸ“ˆβš–οΈπŸ‹οΈβ€β™‚οΈ ([See example](examples/calculate_training_load.py))

- **Weather the storm**: Unlock the power of historical weather data from external services, adding a fascinating layer of context to your sports activities. β˜€οΈπŸŒ§οΈβ›ˆοΈ

- **Unveil the secrets within coordinates**: Explore the integral metrics of your activities within specific geographical areas, uncovering valuable data on distance, heart rate, and speed. Peer into the depths of your performance! πŸŒπŸ“πŸ“‰ ([See example](examples/extract_data_inside_area.py))

- **Embrace randomness**: Extract activities from CSV files and indulge in the excitement of randomly selecting a specific number of activities. Embrace the element of surprise! πŸŽ²πŸ“‚πŸŽ‰ ([See example](examples/extract_random_activities_from_csv.py))

- **Conquer the dead ends**: Unravel the mysteries of your sports activities by identifying the dead ends. Prepare to navigate the uncharted territories of your performance! πŸš§πŸ—ΊοΈπŸ” ([See example](examples/dead_end_extraction.py))

- **Unlock the format**: Seamlessly convert TCX files to GPX, opening doors to even more possibilities. Adapt and conquer! βš™οΈπŸ”„βœ¨ ([See example](examples/convert_tcx_to_gpx.py))

And that's just the beginning! The sport-activities-framework holds countless other features, awaiting your exploration. Brace yourself for an exhilarating journey of discovery, where the ordinary becomes extraordinary, and your sports activities come alive like never before. 🌟πŸ”₯πŸƒβ€β™‚οΈ

The framework comes with two (testing) [benchmark datasets](https://github.com/firefly-cpp/sports-activity-dataset-collections), which are freely available to download from: [DATASET1](http://iztok-jr-fister.eu/static/publications/Sport5.zip), [DATASET2](http://iztok-jr-fister.eu/static/css/datasets/Sport.zip).


## Installation

### pip

Install sport-activities-features with pip:

```sh
pip install sport-activities-features
```

### Alpine Linux

To install sport-activities-features on Alpine, use:

```sh
$ apk add py3-sport-activities-features
```

### Fedora Linux

To install sport-activities-features on Fedora, use:

```sh
$ dnf install python3-sport-activities-features
```

### Arch Linux

To install sport-activities-features on Arch Linux, please use an [AUR helper](https://wiki.archlinux.org/title/AUR_helpers):

```sh
$ yay -Syyu python-sport-activities-features
```

## API

There is a simple API for remote work with the sport-activities-features package available [here](https://github.com/alenrajsp/sport-activities-features-api).

## Graphical User Interface

There is a simple Graphical User Interface for the sport-activities-features package available [here](https://github.com/firefly-cpp/sport-activities-features-gui).

## Historical weather data
Weather data parsed is collected from the [Visual Crossing Weather API](https://www.visualcrossing.com/).
Please note that this is an external unaffiliated service, and users must register to use the API.
The service has a free tier (1000 Weather reports/day) but is otherwise operating on a pay-as-you-go model.
For pricing and terms of use, please read the [official documentation](https://www.visualcrossing.com/weather-data-editions) of the API provider.

## Overpass API & Open Elevation API integration
Without performing activities, we can use the [OpenStreetMap](https://www.openstreetmap.org/) for the identification of hills,
total ascent, and descent. This is done using the [Overpass API](https://wiki.openstreetmap.org/wiki/Overpass_API)
which is a read-only API that allows querying of OSM map data. In addition to that altitude, data is retrieved by using the
[Open-Elevation API](https://open-elevation.com/) which is an open-source and free alternative to the Google Elevation API.
Both of the solutions can be used by using free publicly acessible APIs ([Overpass](https://wiki.openstreetmap.org/wiki/Overpass_API), [Open-Elevation](https://open-elevation.com/#public-api)) or can be self hosted on a server or as a Docker container ([Overpass](https://wiki.openstreetmap.org/wiki/Overpass_API/Installation), [Open-Elevation](https://github.com/Jorl17/open-elevation/blob/master/docs/host-your-own.md)).

## CODE EXAMPLES:

### Reading files

#### (*.TCX)
```python
from sport_activities_features.tcx_manipulation import TCXFile

# Class for reading TCX files
tcx_file=TCXFile()
data = tcx_file.read_one_file("path_to_the_file") # Represents data as dictionary of lists

# Alternative choice
data = tcx_file.read_one_file("path_to_the_file", numpy_array= True) # Represents data as dictionary of numpy.arrays

```

#### (*.GPX)
```python
from sport_activities_features.gpx_manipulation import GPXFile

# Class for reading GPX files
gpx_file=GPXFile()

# Read the file and generate a dictionary with 
data = gpx_file.read_one_file("path_to_the_file") # Represents data as dictionary of lists

# Alternative choice
data = gpx_file.read_one_file("path_to_the_file", numpy_array= True) # Represents data as dictionary of numpy.arrays

```



### Extraction of topographic features
```python
from sport_activities_features.hill_identification import HillIdentification
from sport_activities_features.tcx_manipulation import TCXFile
from sport_activities_features.topographic_features import TopographicFeatures
from sport_activities_features.plot_data import PlotData

# Read TCX file
tcx_file = TCXFile()
activity = tcx_file.read_one_file("path_to_the_file")

# Detect hills in data
Hill = HillIdentification(activity['altitudes'], 30)
Hill.identify_hills()
all_hills = Hill.return_hills()

# Extract features from data
Top = TopographicFeatures(all_hills)
num_hills = Top.num_of_hills()
avg_altitude = Top.avg_altitude_of_hills(activity['altitudes'])
avg_ascent = Top.avg_ascent_of_hills(activity['altitudes'])
distance_hills = Top.distance_of_hills(activity['positions'])
hills_share = Top.share_of_hills(distance_hills, activity['total_distance'])
```

### Extraction of intervals
```python
import sys
sys.path.append('../')

from sport_activities_features.interval_identification import IntervalIdentificationByPower, IntervalIdentificationByHeartrate
from sport_activities_features.tcx_manipulation import TCXFile

# Reading the TCX file
tcx_file = TCXFile()
activity = tcx_file.read_one_file("path_to_the_data")

# Identifying the intervals in the activity by power
Intervals = IntervalIdentificationByPower(activity["distances"], activity["timestamps"], activity["altitudes"], 70)
Intervals.identify_intervals()
all_intervals = Intervals.return_intervals()

# Identifying the intervals in the activity by heart rate
Intervals = IntervalIdentificationByHeartrate(activity["timestamps"], activity["altitudes"], activity["heartrates"])
Intervals.identify_intervals()
all_intervals = Intervals.return_intervals()
```

### Parsing of Historical weather data from an external service
```python
from sport_activities_features import WeatherIdentification
from sport_activities_features import TCXFile

# Read TCX file
tcx_file = TCXFile()
tcx_data = tcx_file.read_one_file("path_to_file")

# Configure visual crossing api key
visual_crossing_api_key = "weather_api_key" # https://www.visualcrossing.com/weather-api

# Explanation of elements - https://www.visualcrossing.com/resources/documentation/weather-data/weather-data-documentation/
weather = WeatherIdentification(tcx_data['positions'], tcx_data['timestamps'], visual_crossing_api_key)
weatherlist = weather.get_weather(time_delta=30)
tcx_weather = weather.get_average_weather_data(timestamps=tcx_data['timestamps'],weather=weatherlist)
# Add weather to TCX data
tcx_data.update({'weather':tcx_weather})
```

The weather list is of the following type:
```json
     [
        {
            "temperature": 14.3,
            "maximum_temperature": 14.3,
            "minimum_temperature": 14.3,
            "wind_chill": null,
            "heat_index": null,
            "solar_radiation": null,
            "precipitation": 0.0,
            "sea_level_pressure": 1021.6,
            "snow_depth": null,
            "wind_speed": 6.9,
            "wind_direction": 129.0,
            "wind_gust": null,
            "visibility": 40.0,
            "cloud_cover": 54.3,
            "relative_humidity": 47.6,
            "dew_point": 3.3,
            "weather_type": "",
            "conditions": "Partially cloudy",
            "date": "2016-04-02T17:26:09+00:00",
            "location": [
                46.079871179535985,
                14.738618675619364
            ],
            "index": 0
        }, ...
    ]
```

### Extraction of integral metrics
```python
import sys
sys.path.append('../')

from sport_activities_features.tcx_manipulation import TCXFile

# Read TCX file
tcx_file = TCXFile()

integral_metrics = tcx_file.extract_integral_metrics("path_to_the_file")

print(integral_metrics)

```

### Weather data extraction
```python
from sport_activities_features.weather_identification import WeatherIdentification
from sport_activities_features.tcx_manipulation import TCXFile

#read TCX file
tcx_file = TCXFile()
tcx_data = tcx_file.read_one_file("path_to_the_file")

#configure visual crossing api key
visual_crossing_api_key = "API_KEY" # https://www.visualcrossing.com/weather-api

#return weather objects
weather = WeatherIdentification(tcx_data['positions'], tcx_data['timestamps'], visual_crossing_api_key)
weatherlist = weather.get_weather()
```

### Using Overpass queried Open Street Map nodes
```python
import overpy
from sport_activities_features.overpy_node_manipulation import OverpyNodesReader

# External service Overpass API (https://wiki.openstreetmap.org/wiki/Overpass_API) (can be self-hosted)
overpass_api = "https://lz4.overpass-api.de/api/interpreter"

# External service Open Elevation API (https://api.open-elevation.com/api/v1/lookup) (can be self-hosted)
open_elevation_api = "https://api.open-elevation.com/api/v1/lookup"

# OSM Way (https://wiki.openstreetmap.org/wiki/Way)
open_street_map_way = 164477980

overpass_api = overpy.Overpass(url=overpass_api)

# Get an example Overpass way
q = f"""(way({open_street_map_way});<;);out geom;"""
query = overpass_api.query(q)

# Get nodes of an Overpass way
nodes = query.ways[0].get_nodes(resolve_missing=True)

# Extract basic data from nodes (you can, later on, use Hill Identification and Hill Data Extraction on them)
overpy_reader = OverpyNodesReader(open_elevation_api=open_elevation_api)
# Returns {
#         'positions': positions, 'altitudes': altitudes, 'distances': distances, 'total_distance': total_distance
#         }
data = overpy_reader.read_nodes(nodes)
```

### Extraction of data inside the area
```python
import numpy as np
import sys
sys.path.append('../')

from sport_activities_features.area_identification import AreaIdentification
from sport_activities_features.tcx_manipulation import TCXFile

# Reading the TCX file.
tcx_file = TCXFile()
activity = tcx_file.read_one_file('path_to_the_data')

# Converting the read data to arrays.
positions = np.array([*activity['positions']])
distances = np.array([*activity['distances']])
timestamps = np.array([*activity['timestamps']])
heartrates = np.array([*activity['heartrates']])

# Area coordinates should be given in clockwise orientation in the form of 3D array (number_of_hulls, hull_coordinates, 2).
# Holes in area are permitted.
area_coordinates = np.array([[[10, 10], [10, 50], [50, 50], [50, 10]],
                             [[19, 19], [19, 21], [21, 21], [21, 19]]])

# Extracting the data inside the given area.
area = AreaIdentification(positions, distances, timestamps, heartrates, area_coordinates)
area.identify_points_in_area()
area_data = area.extract_data_in_area()
```

### Identify interruptions
```python
from sport_activities_features.interruptions.interruption_processor import InterruptionProcessor
from sport_activities_features.tcx_manipulation import TCXFile

"""
Identify interruption events from a TCX or GPX file.
"""

# read TCX file (also works with GPX files)
tcx_file = TCXFile()
tcx_data = tcx_file.read_one_file("path_to_the_data")

"""
Time interval = time before and after the start of an event
Min speed = Threshold speed to trigger an event/interruption (trigger when under min_speed)
overpass_api_url = Set to something self-hosted, or use a public instance from https://wiki.openstreetmap.org/wiki/Overpass_API
"""
interruptionProcessor = InterruptionProcessor(time_interval=60, min_speed=2,
                                              overpass_api_url="url_to_overpass_api")

"""
If classify is set to true, also discover if interruptions are close to intersections. Returns a list of [ExerciseEvent]
"""
events = interruptionProcessor.events(tcx_data, True)
```

### Overpy (Overpass API) node manipulation
Generate TCXFile parsed like data object from overpy.Node objects
```python
import overpy
from sport_activities_features.overpy_node_manipulation import OverpyNodesReader


# External service Overpass API (https://wiki.openstreetmap.org/wiki/Overpass_API) (can be self-hosted)
overpass_api = "https://lz4.overpass-api.de/api/interpreter"

# External service Open Elevation API (https://api.open-elevation.com/api/v1/lookup) (can be self-hosted)
open_elevation_api = "https://api.open-elevation.com/api/v1/lookup"

# OSM Way (https://wiki.openstreetmap.org/wiki/Way)
open_street_map_way = 164477980

overpass_api = overpy.Overpass(url=overpass_api)

# Get an example Overpass way
q = f"""(way({open_street_map_way});<;);out geom;"""
query = overpass_api.query(q)

# Get nodes of an Overpass way
nodes = query.ways[0].get_nodes(resolve_missing=True)

# Extract basic data from nodes (you can, later on, use Hill Identification and Hill Data Extraction on them)
overpy_reader = OverpyNodesReader(open_elevation_api=open_elevation_api)
# Returns {
#         'positions': positions, 'altitudes': altitudes, 'distances': distances, 'total_distance': total_distance
#         }
data = overpy_reader.read_nodes(nodes)
```
### Missing elevation data extraction
```python
from sport_activities_features import ElevationIdentification
from sport_activities_features import TCXFile

tcx_file = TCXFile()
tcx_data = tcx_file.read_one_file('path_to_file')

elevations = ElevationIdentification(tcx_data['positions'])
"""Adds tcx_data['elevation'] = eg. [124, 21, 412] for each position"""
tcx_data.update({'elevations':elevations})
```

### Example of a visualization of the area detection

![Area Figure](https://i.imgur.com/Iz8Ga3B.png)

### Example of visualization of dead-end identification
![Dead End Figure](https://imgur.com/LgZzCFS.png)

## License

This package is distributed under the MIT License. This license can be found online at <http://www.opensource.org/licenses/MIT>.

## Disclaimer

This framework is provided as-is, and there are no guarantees that it fits your purposes or that it is bug-free. Use it at your own risk!

## Cite us

I. Jr. Fister, L. Lukač, A. Rajőp, I. Fister, L. Pečnik and D. Fister, "[A minimalistic toolbox for extracting features from sport activity files](http://iztok-jr-fister.eu/static/publications/294.pdf)", 2021 IEEE 25th International Conference on Intelligent Engineering Systems (INES), 2021, pp. 121-126, doi: [10.1109/INES52918.2021.9512927](http://dx.doi.org/10.1109/INES52918.2021.9512927).

## Further read

[1] [Awesome Computational Intelligence in Sports](https://github.com/firefly-cpp/awesome-computational-intelligence-in-sports)

## Related frameworks

[1] [AST-Monitor: A wearable Raspberry Pi computer for cyclists](https://github.com/firefly-cpp/AST-Monitor)

## Contributors ✨

Thanks go to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
  <tbody>
    <tr>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/alenrajsp"><img src="https://avatars.githubusercontent.com/u/27721714?v=4?s=100" width="100px;" alt="alenrajsp"/><br /><sub><b>alenrajsp</b></sub></a><br /><a href="https://github.com/firefly-cpp/sport-activities-features/commits?author=alenrajsp" title="Code">πŸ’»</a> <a href="https://github.com/firefly-cpp/sport-activities-features/commits?author=alenrajsp" title="Tests">⚠️</a> <a href="#example-alenrajsp" title="Examples">πŸ’‘</a> <a href="https://github.com/firefly-cpp/sport-activities-features/commits?author=alenrajsp" title="Documentation">πŸ“–</a> <a href="#ideas-alenrajsp" title="Ideas, Planning, & Feedback">πŸ€”</a> <a href="https://github.com/firefly-cpp/sport-activities-features/issues?q=author%3Aalenrajsp" title="Bug reports">πŸ›</a> <a href="#maintenance-alenrajsp" title="Maintenance">🚧</a></td>
      <td align="center" valign="top" width="14.28%"><a href="http://www.iztok-jr-fister.eu/"><img src="https://avatars.githubusercontent.com/u/1633361?v=4?s=100" width="100px;" alt="Iztok Fister Jr."/><br /><sub><b>Iztok Fister Jr.</b></sub></a><br /><a href="https://github.com/firefly-cpp/sport-activities-features/commits?author=firefly-cpp" title="Code">πŸ’»</a> <a href="https://github.com/firefly-cpp/sport-activities-features/issues?q=author%3Afirefly-cpp" title="Bug reports">πŸ›</a> <a href="https://github.com/firefly-cpp/sport-activities-features/commits?author=firefly-cpp" title="Tests">⚠️</a> <a href="#example-firefly-cpp" title="Examples">πŸ’‘</a> <a href="https://github.com/firefly-cpp/sport-activities-features/commits?author=firefly-cpp" title="Documentation">πŸ“–</a> <a href="#ideas-firefly-cpp" title="Ideas, Planning, & Feedback">πŸ€”</a> <a href="#mentoring-firefly-cpp" title="Mentoring">πŸ§‘β€πŸ«</a> <a href="#platform-firefly-cpp" title="Packaging/porting to new platform">πŸ“¦</a> <a href="#maintenance-firefly-cpp" title="Maintenance">🚧</a> <a href="#data-firefly-cpp" title="Data">πŸ”£</a></td>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/luckyLukac"><img src="https://avatars.githubusercontent.com/u/73126820?v=4?s=100" width="100px;" alt="luckyLukac"/><br /><sub><b>luckyLukac</b></sub></a><br /><a href="#ideas-luckyLukac" title="Ideas, Planning, & Feedback">πŸ€”</a> <a href="https://github.com/firefly-cpp/sport-activities-features/commits?author=luckyLukac" title="Code">πŸ’»</a> <a href="https://github.com/firefly-cpp/sport-activities-features/issues?q=author%3AluckyLukac" title="Bug reports">πŸ›</a> <a href="https://github.com/firefly-cpp/sport-activities-features/commits?author=luckyLukac" title="Tests">⚠️</a> <a href="#example-luckyLukac" title="Examples">πŸ’‘</a></td>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/rhododendrom"><img src="https://avatars.githubusercontent.com/u/3198785?v=4?s=100" width="100px;" alt="rhododendrom"/><br /><sub><b>rhododendrom</b></sub></a><br /><a href="https://github.com/firefly-cpp/sport-activities-features/commits?author=rhododendrom" title="Code">πŸ’»</a> <a href="#design-rhododendrom" title="Design">🎨</a> <a href="https://github.com/firefly-cpp/sport-activities-features/commits?author=rhododendrom" title="Documentation">πŸ“–</a> <a href="#ideas-rhododendrom" title="Ideas, Planning, & Feedback">πŸ€”</a></td>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/lukapecnik"><img src="https://avatars.githubusercontent.com/u/23029992?v=4?s=100" width="100px;" alt="Luka Pečnik"/><br /><sub><b>Luka Pečnik</b></sub></a><br /><a href="https://github.com/firefly-cpp/sport-activities-features/commits?author=lukapecnik" title="Code">πŸ’»</a> <a href="https://github.com/firefly-cpp/sport-activities-features/commits?author=lukapecnik" title="Documentation">πŸ“–</a> <a href="https://github.com/firefly-cpp/sport-activities-features/commits?author=lukapecnik" title="Tests">⚠️</a> <a href="https://github.com/firefly-cpp/sport-activities-features/issues?q=author%3Alukapecnik" title="Bug reports">πŸ›</a></td>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/spelap"><img src="https://avatars.githubusercontent.com/u/19300429?v=4?s=100" width="100px;" alt="spelap"/><br /><sub><b>spelap</b></sub></a><br /><a href="https://github.com/firefly-cpp/sport-activities-features/commits?author=spelap" title="Code">πŸ’»</a></td>
      <td align="center" valign="top" width="14.28%"><a href="http://carlosal1015.github.io"><img src="https://avatars.githubusercontent.com/u/21283014?v=4?s=100" width="100px;" alt="Oromion"/><br /><sub><b>Oromion</b></sub></a><br /><a href="#maintenance-carlosal1015" title="Maintenance">🚧</a> <a href="https://github.com/firefly-cpp/sport-activities-features/issues?q=author%3Acarlosal1015" title="Bug reports">πŸ›</a></td>
    </tr>
    <tr>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/KoprivcLuka"><img src="https://avatars.githubusercontent.com/u/45632449?v=4?s=100" width="100px;" alt="Luka Koprivc"/><br /><sub><b>Luka Koprivc</b></sub></a><br /><a href="https://github.com/firefly-cpp/sport-activities-features/issues?q=author%3AKoprivcLuka" title="Bug reports">πŸ›</a></td>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/garyjellyarms"><img src="https://avatars.githubusercontent.com/u/79595804?v=4?s=100" width="100px;" alt="Nejc Graj"/><br /><sub><b>Nejc Graj</b></sub></a><br /><a href="https://github.com/firefly-cpp/sport-activities-features/issues?q=author%3Agaryjellyarms" title="Bug reports">πŸ›</a></td>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/Mtvrt123"><img src="https://avatars.githubusercontent.com/u/50879568?v=4?s=100" width="100px;" alt="MlinaricNejc"/><br /><sub><b>MlinaricNejc</b></sub></a><br /><a href="https://github.com/firefly-cpp/sport-activities-features/issues?q=author%3AMtvrt123" title="Bug reports">πŸ›</a></td>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/KukovecRok"><img src="https://avatars.githubusercontent.com/u/33880044?v=4?s=100" width="100px;" alt="Tatookie"/><br /><sub><b>Tatookie</b></sub></a><br /><a href="https://github.com/firefly-cpp/sport-activities-features/commits?author=KukovecRok" title="Code">πŸ’»</a> <a href="https://github.com/firefly-cpp/sport-activities-features/issues?q=author%3AKukovecRok" title="Bug reports">πŸ›</a> <a href="https://github.com/firefly-cpp/sport-activities-features/commits?author=KukovecRok" title="Tests">⚠️</a> <a href="#example-KukovecRok" title="Examples">πŸ’‘</a> <a href="#maintenance-KukovecRok" title="Maintenance">🚧</a></td>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/zala-lahovnik"><img src="https://avatars.githubusercontent.com/u/105444201?v=4?s=100" width="100px;" alt="Zala Lahovnik"/><br /><sub><b>Zala Lahovnik</b></sub></a><br /><a href="https://github.com/firefly-cpp/sport-activities-features/commits?author=zala-lahovnik" title="Documentation">πŸ“–</a> <a href="https://github.com/firefly-cpp/sport-activities-features/commits?author=zala-lahovnik" title="Code">πŸ’»</a></td>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/lahovniktadej"><img src="https://avatars.githubusercontent.com/u/57890734?v=4?s=100" width="100px;" alt="Tadej Lahovnik"/><br /><sub><b>Tadej Lahovnik</b></sub></a><br /><a href="https://github.com/firefly-cpp/sport-activities-features/commits?author=lahovniktadej" title="Documentation">πŸ“–</a></td>
    </tr>
  </tbody>
</table>

<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind are welcome!

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/firefly-cpp/sport-activities-features",
    "name": "sport-activities-features",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0.0,>=3.9.0",
    "maintainer_email": null,
    "keywords": "computational intelligence, cycling, data mining, datasets, gpx, optimization, sport activities, tcx",
    "author": "Iztok Fister Jr.",
    "author_email": "iztok@iztok-jr-fister.eu",
    "download_url": "https://files.pythonhosted.org/packages/8a/16/800f20e58ba1f8e1613c1bf25cf7ef9d0c11921b6b13eabc017e4f7fe63f/sport_activities_features-0.4.0.tar.gz",
    "platform": null,
    "description": "<p align=\"center\">\n  <img width=\"200\" src=\"https://raw.githubusercontent.com/firefly-cpp/sport-activities-features/main/.github/logo/sport_activities.png\">\n</p>\n\n---\n\n# sport-activities-features --- A minimalistic toolbox for extracting features from sports activity files written in Python\n\n---\n\n[![PyPI Version](https://img.shields.io/pypi/v/sport-activities-features.svg)](https://pypi.python.org/pypi/sport-activities-features)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/sport-activities-features.svg)\n[![Documentation Status](https://readthedocs.org/projects/sport-activities-features/badge/?version=latest)](https://sport-activities-features.readthedocs.io/en/latest/?badge=latest)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/sport-activities-features.svg)\n[![Downloads](https://pepy.tech/badge/sport-activities-features)](https://pepy.tech/project/sport-activities-features)\n![GitHub repo size](https://img.shields.io/github/repo-size/firefly-cpp/sport-activities-features?style=flat-square)\n[![GitHub license](https://img.shields.io/github/license/firefly-cpp/sport-activities-features.svg)](https://github.com/firefly-cpp/sport-activities-features/blob/master/LICENSE)\n![GitHub commit activity](https://img.shields.io/github/commit-activity/w/firefly-cpp/sport-activities-features.svg)\n[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/firefly-cpp/sport-activities-features.svg)](http://isitmaintained.com/project/firefly-cpp/sport-activities-features \"Average time to resolve an issue\")\n[![Percentage of issues still open](http://isitmaintained.com/badge/open/firefly-cpp/sport-activities-features.svg)](http://isitmaintained.com/project/firefly-cpp/sport-activities-features \"Percentage of issues still open\")\n[![All Contributors](https://img.shields.io/badge/all_contributors-6-orange.svg?style=flat-square)](#contributors-)\n[![Fedora package](https://img.shields.io/fedora/v/python3-sport-activities-features?color=blue&label=Fedora%20Linux&logo=fedora)](https://src.fedoraproject.org/rpms/python-sport-activities-features)\n[![AUR package](https://img.shields.io/aur/version/python-sport-activities-features?color=blue&label=Arch%20Linux&logo=arch-linux)](https://aur.archlinux.org/packages/python-sport-activities-features)\n[![Packaging status](https://repology.org/badge/tiny-repos/python:sport-activities-features.svg)](https://repology.org/project/python:sport-activities-features/versions)\n[![DOI](https://img.shields.io/badge/DOI-10.1109/INES52918.2021.9512927-blue)](https://doi.org/10.1109/INES52918.2021.9512927)\n\n* **Free software:** MIT license\n* **Python versions:** 3.8.x, 3.9.x, 3.10.x, 3.11.x, 3.12.x\n* **Documentation:** https://sport-activities-features.readthedocs.io/en/latest\n* **Tested OS:** Windows, Ubuntu, Debian, Fedora, Alpine, Arch, macOS. **However, that does not mean it does not work on others.**\n\n## Unleashing the Power of Sports Activity Analysis: A Framework Beyond Ordinary Metrics \ud83d\ude80\n\nPrepare to dive into the thrilling world of sports activity analysis, where hidden geographic, topological, and personalized data await their grand unveiling. In this captivating journey, we embark on a quest to extract the deepest insights from the wealth of information generated by monitoring sports activities. Brace yourself for a framework that transcends the limitations of conventional analysis techniques. \ud83d\udcaa\ud83d\udd0d\n\nTraditional approaches often rely on integral metrics like total duration, total distance, and average heart rate, but they fall victim to the dreaded \"overall metrics problem.\" These metrics fail to capture the essence of sports activities, omitting crucial components and leading to potentially flawed and misleading conclusions. They lack the ability to recognize distinct stages and phases of the activity, such as the invigorating warm-up, the endurance-testing main event, and the heart-pounding intervals. \u23f1\ufe0f\ud83d\udeb4\u200d\u2640\ufe0f\ud83d\udcc8\n\nFortunately, our sport-activities-framework rises above these limitations, revealing a comprehensive panorama of your sports activity files. This framework combines the power of identification and extraction methods to unlock a treasure trove of valuable data. Picture this :camera: : effortlessly identifying the number of hills, extracting average altitudes of these remarkable formations, measuring the total distance conquered on those inclines, and even deriving climbing ratios for a true measure of accomplishment (total distance of hills vs. total distance). But that's just the tip of the iceberg! The framework seamlessly integrates a multitude of extensions, including historical weather parsing, statistical evaluations, and ex-post visualizations that bring your data to life. \ud83d\uddfb\ud83d\udcca\ud83c\udf26\ufe0f\n\nFor those seeking to venture further, we invite you to explore the realms of scientific papers on data mining that delve into these captivating topics. Discover how our framework complements the world of generating and predicting automated sport training sessions, creating a harmonious synergy between theory and practice. \ud83d\udcda\ud83d\udd2c\ud83d\udca1\n\n## Detailed insights \ud83d\udd0d\n\nPrepare to be astounded by the capabilities of the sport-activities-features framework. It effortlessly handles TCX & GPX activity files and harnesses the power of the [Overpass API](https://wiki.openstreetmap.org/wiki/Overpass_API) nodes. Presenting the range of functions at your disposal:\n\n- **Unleash the integral metrics**: From total distance to total duration and even calorie count, witness the extraction of these vital statistics with a single glance. \ud83d\udccf\u23f0\ud83d\udd25 ([See example](examples/integral_metrics_extraction.py))\n\n- **Conquer the peaks**: Ascend to new heights by extracting topographic features like the number of hills, their average altitudes, the total distance covered on these majestic slopes, and the thrilling climbing ratio. Prepare for a breathtaking adventure! \u26f0\ufe0f\ud83d\udcc8\ud83e\uddd7\u200d\u2642\ufe0f ([See example](examples/hill_data_extraction.py))\n\n- **Embark on a visual journey**: Immerse yourself in the beauty of your accomplishments as you plot the identified hills on a mesmerizing map. Witness the landscape come alive before your eyes. \ud83d\uddfa\ufe0f\ud83c\udfde\ufe0f\ud83d\udd8c\ufe0f ([See example](examples/draw_map_with_identified_hills.py))\n\n- **Embrace the rhythm of intervals**: Explore the intervals within your sports activities, uncovering their numbers, durations, distances, and heart rates. Unveil the heartbeat of your performance! \ud83c\udfc3\u200d\u2640\ufe0f\ud83d\udcca\ud83d\udc93 ([See example](examples/draw_map_with_identified_intervals.py))\n\n- **Calculate the training loads**: Dive deep into the intricate world of training loads and discover the Banister TRIMP and Lucia TRIMP methods. Gain invaluable insights into optimizing your training regimen. \ud83d\udcc8\u2696\ufe0f\ud83c\udfcb\ufe0f\u200d\u2642\ufe0f ([See example](examples/calculate_training_load.py))\n\n- **Weather the storm**: Unlock the power of historical weather data from external services, adding a fascinating layer of context to your sports activities. \u2600\ufe0f\ud83c\udf27\ufe0f\u26c8\ufe0f\n\n- **Unveil the secrets within coordinates**: Explore the integral metrics of your activities within specific geographical areas, uncovering valuable data on distance, heart rate, and speed. Peer into the depths of your performance! \ud83c\udf0d\ud83d\udccd\ud83d\udcc9 ([See example](examples/extract_data_inside_area.py))\n\n- **Embrace randomness**: Extract activities from CSV files and indulge in the excitement of randomly selecting a specific number of activities. Embrace the element of surprise! \ud83c\udfb2\ud83d\udcc2\ud83c\udf89 ([See example](examples/extract_random_activities_from_csv.py))\n\n- **Conquer the dead ends**: Unravel the mysteries of your sports activities by identifying the dead ends. Prepare to navigate the uncharted territories of your performance! \ud83d\udea7\ud83d\uddfa\ufe0f\ud83d\udd0d ([See example](examples/dead_end_extraction.py))\n\n- **Unlock the format**: Seamlessly convert TCX files to GPX, opening doors to even more possibilities. Adapt and conquer! \u2699\ufe0f\ud83d\udd04\u2728 ([See example](examples/convert_tcx_to_gpx.py))\n\nAnd that's just the beginning! The sport-activities-framework holds countless other features, awaiting your exploration. Brace yourself for an exhilarating journey of discovery, where the ordinary becomes extraordinary, and your sports activities come alive like never before. \ud83c\udf1f\ud83d\udd25\ud83c\udfc3\u200d\u2642\ufe0f\n\nThe framework comes with two (testing) [benchmark datasets](https://github.com/firefly-cpp/sports-activity-dataset-collections), which are freely available to download from: [DATASET1](http://iztok-jr-fister.eu/static/publications/Sport5.zip), [DATASET2](http://iztok-jr-fister.eu/static/css/datasets/Sport.zip).\n\n\n## Installation\n\n### pip\n\nInstall sport-activities-features with pip:\n\n```sh\npip install sport-activities-features\n```\n\n### Alpine Linux\n\nTo install sport-activities-features on Alpine, use:\n\n```sh\n$ apk add py3-sport-activities-features\n```\n\n### Fedora Linux\n\nTo install sport-activities-features on Fedora, use:\n\n```sh\n$ dnf install python3-sport-activities-features\n```\n\n### Arch Linux\n\nTo install sport-activities-features on Arch Linux, please use an [AUR helper](https://wiki.archlinux.org/title/AUR_helpers):\n\n```sh\n$ yay -Syyu python-sport-activities-features\n```\n\n## API\n\nThere is a simple API for remote work with the sport-activities-features package available [here](https://github.com/alenrajsp/sport-activities-features-api).\n\n## Graphical User Interface\n\nThere is a simple Graphical User Interface for the sport-activities-features package available [here](https://github.com/firefly-cpp/sport-activities-features-gui).\n\n## Historical weather data\nWeather data parsed is collected from the [Visual Crossing Weather API](https://www.visualcrossing.com/).\nPlease note that this is an external unaffiliated service, and users must register to use the API.\nThe service has a free tier (1000 Weather reports/day) but is otherwise operating on a pay-as-you-go model.\nFor pricing and terms of use, please read the [official documentation](https://www.visualcrossing.com/weather-data-editions) of the API provider.\n\n## Overpass API & Open Elevation API integration\nWithout performing activities, we can use the [OpenStreetMap](https://www.openstreetmap.org/) for the identification of hills,\ntotal ascent, and descent. This is done using the [Overpass API](https://wiki.openstreetmap.org/wiki/Overpass_API)\nwhich is a read-only API that allows querying of OSM map data. In addition to that altitude, data is retrieved by using the\n[Open-Elevation API](https://open-elevation.com/) which is an open-source and free alternative to the Google Elevation API.\nBoth of the solutions can be used by using free publicly acessible APIs ([Overpass](https://wiki.openstreetmap.org/wiki/Overpass_API), [Open-Elevation](https://open-elevation.com/#public-api)) or can be self hosted on a server or as a Docker container ([Overpass](https://wiki.openstreetmap.org/wiki/Overpass_API/Installation), [Open-Elevation](https://github.com/Jorl17/open-elevation/blob/master/docs/host-your-own.md)).\n\n## CODE EXAMPLES:\n\n### Reading files\n\n#### (*.TCX)\n```python\nfrom sport_activities_features.tcx_manipulation import TCXFile\n\n# Class for reading TCX files\ntcx_file=TCXFile()\ndata = tcx_file.read_one_file(\"path_to_the_file\") # Represents data as dictionary of lists\n\n# Alternative choice\ndata = tcx_file.read_one_file(\"path_to_the_file\", numpy_array= True) # Represents data as dictionary of numpy.arrays\n\n```\n\n#### (*.GPX)\n```python\nfrom sport_activities_features.gpx_manipulation import GPXFile\n\n# Class for reading GPX files\ngpx_file=GPXFile()\n\n# Read the file and generate a dictionary with \ndata = gpx_file.read_one_file(\"path_to_the_file\") # Represents data as dictionary of lists\n\n# Alternative choice\ndata = gpx_file.read_one_file(\"path_to_the_file\", numpy_array= True) # Represents data as dictionary of numpy.arrays\n\n```\n\n\n\n### Extraction of topographic features\n```python\nfrom sport_activities_features.hill_identification import HillIdentification\nfrom sport_activities_features.tcx_manipulation import TCXFile\nfrom sport_activities_features.topographic_features import TopographicFeatures\nfrom sport_activities_features.plot_data import PlotData\n\n# Read TCX file\ntcx_file = TCXFile()\nactivity = tcx_file.read_one_file(\"path_to_the_file\")\n\n# Detect hills in data\nHill = HillIdentification(activity['altitudes'], 30)\nHill.identify_hills()\nall_hills = Hill.return_hills()\n\n# Extract features from data\nTop = TopographicFeatures(all_hills)\nnum_hills = Top.num_of_hills()\navg_altitude = Top.avg_altitude_of_hills(activity['altitudes'])\navg_ascent = Top.avg_ascent_of_hills(activity['altitudes'])\ndistance_hills = Top.distance_of_hills(activity['positions'])\nhills_share = Top.share_of_hills(distance_hills, activity['total_distance'])\n```\n\n### Extraction of intervals\n```python\nimport sys\nsys.path.append('../')\n\nfrom sport_activities_features.interval_identification import IntervalIdentificationByPower, IntervalIdentificationByHeartrate\nfrom sport_activities_features.tcx_manipulation import TCXFile\n\n# Reading the TCX file\ntcx_file = TCXFile()\nactivity = tcx_file.read_one_file(\"path_to_the_data\")\n\n# Identifying the intervals in the activity by power\nIntervals = IntervalIdentificationByPower(activity[\"distances\"], activity[\"timestamps\"], activity[\"altitudes\"], 70)\nIntervals.identify_intervals()\nall_intervals = Intervals.return_intervals()\n\n# Identifying the intervals in the activity by heart rate\nIntervals = IntervalIdentificationByHeartrate(activity[\"timestamps\"], activity[\"altitudes\"], activity[\"heartrates\"])\nIntervals.identify_intervals()\nall_intervals = Intervals.return_intervals()\n```\n\n### Parsing of Historical weather data from an external service\n```python\nfrom sport_activities_features import WeatherIdentification\nfrom sport_activities_features import TCXFile\n\n# Read TCX file\ntcx_file = TCXFile()\ntcx_data = tcx_file.read_one_file(\"path_to_file\")\n\n# Configure visual crossing api key\nvisual_crossing_api_key = \"weather_api_key\" # https://www.visualcrossing.com/weather-api\n\n# Explanation of elements - https://www.visualcrossing.com/resources/documentation/weather-data/weather-data-documentation/\nweather = WeatherIdentification(tcx_data['positions'], tcx_data['timestamps'], visual_crossing_api_key)\nweatherlist = weather.get_weather(time_delta=30)\ntcx_weather = weather.get_average_weather_data(timestamps=tcx_data['timestamps'],weather=weatherlist)\n# Add weather to TCX data\ntcx_data.update({'weather':tcx_weather})\n```\n\nThe weather list is of the following type:\n```json\n     [\n        {\n            \"temperature\": 14.3,\n            \"maximum_temperature\": 14.3,\n            \"minimum_temperature\": 14.3,\n            \"wind_chill\": null,\n            \"heat_index\": null,\n            \"solar_radiation\": null,\n            \"precipitation\": 0.0,\n            \"sea_level_pressure\": 1021.6,\n            \"snow_depth\": null,\n            \"wind_speed\": 6.9,\n            \"wind_direction\": 129.0,\n            \"wind_gust\": null,\n            \"visibility\": 40.0,\n            \"cloud_cover\": 54.3,\n            \"relative_humidity\": 47.6,\n            \"dew_point\": 3.3,\n            \"weather_type\": \"\",\n            \"conditions\": \"Partially cloudy\",\n            \"date\": \"2016-04-02T17:26:09+00:00\",\n            \"location\": [\n                46.079871179535985,\n                14.738618675619364\n            ],\n            \"index\": 0\n        }, ...\n    ]\n```\n\n### Extraction of integral metrics\n```python\nimport sys\nsys.path.append('../')\n\nfrom sport_activities_features.tcx_manipulation import TCXFile\n\n# Read TCX file\ntcx_file = TCXFile()\n\nintegral_metrics = tcx_file.extract_integral_metrics(\"path_to_the_file\")\n\nprint(integral_metrics)\n\n```\n\n### Weather data extraction\n```python\nfrom sport_activities_features.weather_identification import WeatherIdentification\nfrom sport_activities_features.tcx_manipulation import TCXFile\n\n#read TCX file\ntcx_file = TCXFile()\ntcx_data = tcx_file.read_one_file(\"path_to_the_file\")\n\n#configure visual crossing api key\nvisual_crossing_api_key = \"API_KEY\" # https://www.visualcrossing.com/weather-api\n\n#return weather objects\nweather = WeatherIdentification(tcx_data['positions'], tcx_data['timestamps'], visual_crossing_api_key)\nweatherlist = weather.get_weather()\n```\n\n### Using Overpass queried Open Street Map nodes\n```python\nimport overpy\nfrom sport_activities_features.overpy_node_manipulation import OverpyNodesReader\n\n# External service Overpass API (https://wiki.openstreetmap.org/wiki/Overpass_API) (can be self-hosted)\noverpass_api = \"https://lz4.overpass-api.de/api/interpreter\"\n\n# External service Open Elevation API (https://api.open-elevation.com/api/v1/lookup) (can be self-hosted)\nopen_elevation_api = \"https://api.open-elevation.com/api/v1/lookup\"\n\n# OSM Way (https://wiki.openstreetmap.org/wiki/Way)\nopen_street_map_way = 164477980\n\noverpass_api = overpy.Overpass(url=overpass_api)\n\n# Get an example Overpass way\nq = f\"\"\"(way({open_street_map_way});<;);out geom;\"\"\"\nquery = overpass_api.query(q)\n\n# Get nodes of an Overpass way\nnodes = query.ways[0].get_nodes(resolve_missing=True)\n\n# Extract basic data from nodes (you can, later on, use Hill Identification and Hill Data Extraction on them)\noverpy_reader = OverpyNodesReader(open_elevation_api=open_elevation_api)\n# Returns {\n#         'positions': positions, 'altitudes': altitudes, 'distances': distances, 'total_distance': total_distance\n#         }\ndata = overpy_reader.read_nodes(nodes)\n```\n\n### Extraction of data inside the area\n```python\nimport numpy as np\nimport sys\nsys.path.append('../')\n\nfrom sport_activities_features.area_identification import AreaIdentification\nfrom sport_activities_features.tcx_manipulation import TCXFile\n\n# Reading the TCX file.\ntcx_file = TCXFile()\nactivity = tcx_file.read_one_file('path_to_the_data')\n\n# Converting the read data to arrays.\npositions = np.array([*activity['positions']])\ndistances = np.array([*activity['distances']])\ntimestamps = np.array([*activity['timestamps']])\nheartrates = np.array([*activity['heartrates']])\n\n# Area coordinates should be given in clockwise orientation in the form of 3D array (number_of_hulls, hull_coordinates, 2).\n# Holes in area are permitted.\narea_coordinates = np.array([[[10, 10], [10, 50], [50, 50], [50, 10]],\n                             [[19, 19], [19, 21], [21, 21], [21, 19]]])\n\n# Extracting the data inside the given area.\narea = AreaIdentification(positions, distances, timestamps, heartrates, area_coordinates)\narea.identify_points_in_area()\narea_data = area.extract_data_in_area()\n```\n\n### Identify interruptions\n```python\nfrom sport_activities_features.interruptions.interruption_processor import InterruptionProcessor\nfrom sport_activities_features.tcx_manipulation import TCXFile\n\n\"\"\"\nIdentify interruption events from a TCX or GPX file.\n\"\"\"\n\n# read TCX file (also works with GPX files)\ntcx_file = TCXFile()\ntcx_data = tcx_file.read_one_file(\"path_to_the_data\")\n\n\"\"\"\nTime interval = time before and after the start of an event\nMin speed = Threshold speed to trigger an event/interruption (trigger when under min_speed)\noverpass_api_url = Set to something self-hosted, or use a public instance from https://wiki.openstreetmap.org/wiki/Overpass_API\n\"\"\"\ninterruptionProcessor = InterruptionProcessor(time_interval=60, min_speed=2,\n                                              overpass_api_url=\"url_to_overpass_api\")\n\n\"\"\"\nIf classify is set to true, also discover if interruptions are close to intersections. Returns a list of [ExerciseEvent]\n\"\"\"\nevents = interruptionProcessor.events(tcx_data, True)\n```\n\n### Overpy (Overpass API) node manipulation\nGenerate TCXFile parsed like data object from overpy.Node objects\n```python\nimport overpy\nfrom sport_activities_features.overpy_node_manipulation import OverpyNodesReader\n\n\n# External service Overpass API (https://wiki.openstreetmap.org/wiki/Overpass_API) (can be self-hosted)\noverpass_api = \"https://lz4.overpass-api.de/api/interpreter\"\n\n# External service Open Elevation API (https://api.open-elevation.com/api/v1/lookup) (can be self-hosted)\nopen_elevation_api = \"https://api.open-elevation.com/api/v1/lookup\"\n\n# OSM Way (https://wiki.openstreetmap.org/wiki/Way)\nopen_street_map_way = 164477980\n\noverpass_api = overpy.Overpass(url=overpass_api)\n\n# Get an example Overpass way\nq = f\"\"\"(way({open_street_map_way});<;);out geom;\"\"\"\nquery = overpass_api.query(q)\n\n# Get nodes of an Overpass way\nnodes = query.ways[0].get_nodes(resolve_missing=True)\n\n# Extract basic data from nodes (you can, later on, use Hill Identification and Hill Data Extraction on them)\noverpy_reader = OverpyNodesReader(open_elevation_api=open_elevation_api)\n# Returns {\n#         'positions': positions, 'altitudes': altitudes, 'distances': distances, 'total_distance': total_distance\n#         }\ndata = overpy_reader.read_nodes(nodes)\n```\n### Missing elevation data extraction\n```python\nfrom sport_activities_features import ElevationIdentification\nfrom sport_activities_features import TCXFile\n\ntcx_file = TCXFile()\ntcx_data = tcx_file.read_one_file('path_to_file')\n\nelevations = ElevationIdentification(tcx_data['positions'])\n\"\"\"Adds tcx_data['elevation'] = eg. [124, 21, 412] for each position\"\"\"\ntcx_data.update({'elevations':elevations})\n```\n\n### Example of a visualization of the area detection\n\n![Area Figure](https://i.imgur.com/Iz8Ga3B.png)\n\n### Example of visualization of dead-end identification\n![Dead End Figure](https://imgur.com/LgZzCFS.png)\n\n## License\n\nThis package is distributed under the MIT License. This license can be found online at <http://www.opensource.org/licenses/MIT>.\n\n## Disclaimer\n\nThis framework is provided as-is, and there are no guarantees that it fits your purposes or that it is bug-free. Use it at your own risk!\n\n## Cite us\n\nI. Jr. Fister, L. Luka\u010d, A. Raj\u0161p, I. Fister, L. Pe\u010dnik and D. Fister, \"[A minimalistic toolbox for extracting features from sport activity files](http://iztok-jr-fister.eu/static/publications/294.pdf)\", 2021 IEEE 25th International Conference on Intelligent Engineering Systems (INES), 2021, pp. 121-126, doi: [10.1109/INES52918.2021.9512927](http://dx.doi.org/10.1109/INES52918.2021.9512927).\n\n## Further read\n\n[1] [Awesome Computational Intelligence in Sports](https://github.com/firefly-cpp/awesome-computational-intelligence-in-sports)\n\n## Related frameworks\n\n[1] [AST-Monitor: A wearable Raspberry Pi computer for cyclists](https://github.com/firefly-cpp/AST-Monitor)\n\n## Contributors \u2728\n\nThanks go to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->\n<!-- prettier-ignore-start -->\n<!-- markdownlint-disable -->\n<table>\n  <tbody>\n    <tr>\n      <td align=\"center\" valign=\"top\" width=\"14.28%\"><a href=\"https://github.com/alenrajsp\"><img src=\"https://avatars.githubusercontent.com/u/27721714?v=4?s=100\" width=\"100px;\" alt=\"alenrajsp\"/><br /><sub><b>alenrajsp</b></sub></a><br /><a href=\"https://github.com/firefly-cpp/sport-activities-features/commits?author=alenrajsp\" title=\"Code\">\ud83d\udcbb</a> <a href=\"https://github.com/firefly-cpp/sport-activities-features/commits?author=alenrajsp\" title=\"Tests\">\u26a0\ufe0f</a> <a href=\"#example-alenrajsp\" title=\"Examples\">\ud83d\udca1</a> <a href=\"https://github.com/firefly-cpp/sport-activities-features/commits?author=alenrajsp\" title=\"Documentation\">\ud83d\udcd6</a> <a href=\"#ideas-alenrajsp\" title=\"Ideas, Planning, & Feedback\">\ud83e\udd14</a> <a href=\"https://github.com/firefly-cpp/sport-activities-features/issues?q=author%3Aalenrajsp\" title=\"Bug reports\">\ud83d\udc1b</a> <a href=\"#maintenance-alenrajsp\" title=\"Maintenance\">\ud83d\udea7</a></td>\n      <td align=\"center\" valign=\"top\" width=\"14.28%\"><a href=\"http://www.iztok-jr-fister.eu/\"><img src=\"https://avatars.githubusercontent.com/u/1633361?v=4?s=100\" width=\"100px;\" alt=\"Iztok Fister Jr.\"/><br /><sub><b>Iztok Fister Jr.</b></sub></a><br /><a href=\"https://github.com/firefly-cpp/sport-activities-features/commits?author=firefly-cpp\" title=\"Code\">\ud83d\udcbb</a> <a href=\"https://github.com/firefly-cpp/sport-activities-features/issues?q=author%3Afirefly-cpp\" title=\"Bug reports\">\ud83d\udc1b</a> <a href=\"https://github.com/firefly-cpp/sport-activities-features/commits?author=firefly-cpp\" title=\"Tests\">\u26a0\ufe0f</a> <a href=\"#example-firefly-cpp\" title=\"Examples\">\ud83d\udca1</a> <a href=\"https://github.com/firefly-cpp/sport-activities-features/commits?author=firefly-cpp\" title=\"Documentation\">\ud83d\udcd6</a> <a href=\"#ideas-firefly-cpp\" title=\"Ideas, Planning, & Feedback\">\ud83e\udd14</a> <a href=\"#mentoring-firefly-cpp\" title=\"Mentoring\">\ud83e\uddd1\u200d\ud83c\udfeb</a> <a href=\"#platform-firefly-cpp\" title=\"Packaging/porting to new platform\">\ud83d\udce6</a> <a href=\"#maintenance-firefly-cpp\" title=\"Maintenance\">\ud83d\udea7</a> <a href=\"#data-firefly-cpp\" title=\"Data\">\ud83d\udd23</a></td>\n      <td align=\"center\" valign=\"top\" width=\"14.28%\"><a href=\"https://github.com/luckyLukac\"><img src=\"https://avatars.githubusercontent.com/u/73126820?v=4?s=100\" width=\"100px;\" alt=\"luckyLukac\"/><br /><sub><b>luckyLukac</b></sub></a><br /><a href=\"#ideas-luckyLukac\" title=\"Ideas, Planning, & Feedback\">\ud83e\udd14</a> <a href=\"https://github.com/firefly-cpp/sport-activities-features/commits?author=luckyLukac\" title=\"Code\">\ud83d\udcbb</a> <a href=\"https://github.com/firefly-cpp/sport-activities-features/issues?q=author%3AluckyLukac\" title=\"Bug reports\">\ud83d\udc1b</a> <a href=\"https://github.com/firefly-cpp/sport-activities-features/commits?author=luckyLukac\" title=\"Tests\">\u26a0\ufe0f</a> <a href=\"#example-luckyLukac\" title=\"Examples\">\ud83d\udca1</a></td>\n      <td align=\"center\" valign=\"top\" width=\"14.28%\"><a href=\"https://github.com/rhododendrom\"><img src=\"https://avatars.githubusercontent.com/u/3198785?v=4?s=100\" width=\"100px;\" alt=\"rhododendrom\"/><br /><sub><b>rhododendrom</b></sub></a><br /><a href=\"https://github.com/firefly-cpp/sport-activities-features/commits?author=rhododendrom\" title=\"Code\">\ud83d\udcbb</a> <a href=\"#design-rhododendrom\" title=\"Design\">\ud83c\udfa8</a> <a href=\"https://github.com/firefly-cpp/sport-activities-features/commits?author=rhododendrom\" title=\"Documentation\">\ud83d\udcd6</a> <a href=\"#ideas-rhododendrom\" title=\"Ideas, Planning, & Feedback\">\ud83e\udd14</a></td>\n      <td align=\"center\" valign=\"top\" width=\"14.28%\"><a href=\"https://github.com/lukapecnik\"><img src=\"https://avatars.githubusercontent.com/u/23029992?v=4?s=100\" width=\"100px;\" alt=\"Luka Pe\u010dnik\"/><br /><sub><b>Luka Pe\u010dnik</b></sub></a><br /><a href=\"https://github.com/firefly-cpp/sport-activities-features/commits?author=lukapecnik\" title=\"Code\">\ud83d\udcbb</a> <a href=\"https://github.com/firefly-cpp/sport-activities-features/commits?author=lukapecnik\" title=\"Documentation\">\ud83d\udcd6</a> <a href=\"https://github.com/firefly-cpp/sport-activities-features/commits?author=lukapecnik\" title=\"Tests\">\u26a0\ufe0f</a> <a href=\"https://github.com/firefly-cpp/sport-activities-features/issues?q=author%3Alukapecnik\" title=\"Bug reports\">\ud83d\udc1b</a></td>\n      <td align=\"center\" valign=\"top\" width=\"14.28%\"><a href=\"https://github.com/spelap\"><img src=\"https://avatars.githubusercontent.com/u/19300429?v=4?s=100\" width=\"100px;\" alt=\"spelap\"/><br /><sub><b>spelap</b></sub></a><br /><a href=\"https://github.com/firefly-cpp/sport-activities-features/commits?author=spelap\" title=\"Code\">\ud83d\udcbb</a></td>\n      <td align=\"center\" valign=\"top\" width=\"14.28%\"><a href=\"http://carlosal1015.github.io\"><img src=\"https://avatars.githubusercontent.com/u/21283014?v=4?s=100\" width=\"100px;\" alt=\"Oromion\"/><br /><sub><b>Oromion</b></sub></a><br /><a href=\"#maintenance-carlosal1015\" title=\"Maintenance\">\ud83d\udea7</a> <a href=\"https://github.com/firefly-cpp/sport-activities-features/issues?q=author%3Acarlosal1015\" title=\"Bug reports\">\ud83d\udc1b</a></td>\n    </tr>\n    <tr>\n      <td align=\"center\" valign=\"top\" width=\"14.28%\"><a href=\"https://github.com/KoprivcLuka\"><img src=\"https://avatars.githubusercontent.com/u/45632449?v=4?s=100\" width=\"100px;\" alt=\"Luka Koprivc\"/><br /><sub><b>Luka Koprivc</b></sub></a><br /><a href=\"https://github.com/firefly-cpp/sport-activities-features/issues?q=author%3AKoprivcLuka\" title=\"Bug reports\">\ud83d\udc1b</a></td>\n      <td align=\"center\" valign=\"top\" width=\"14.28%\"><a href=\"https://github.com/garyjellyarms\"><img src=\"https://avatars.githubusercontent.com/u/79595804?v=4?s=100\" width=\"100px;\" alt=\"Nejc Graj\"/><br /><sub><b>Nejc Graj</b></sub></a><br /><a href=\"https://github.com/firefly-cpp/sport-activities-features/issues?q=author%3Agaryjellyarms\" title=\"Bug reports\">\ud83d\udc1b</a></td>\n      <td align=\"center\" valign=\"top\" width=\"14.28%\"><a href=\"https://github.com/Mtvrt123\"><img src=\"https://avatars.githubusercontent.com/u/50879568?v=4?s=100\" width=\"100px;\" alt=\"MlinaricNejc\"/><br /><sub><b>MlinaricNejc</b></sub></a><br /><a href=\"https://github.com/firefly-cpp/sport-activities-features/issues?q=author%3AMtvrt123\" title=\"Bug reports\">\ud83d\udc1b</a></td>\n      <td align=\"center\" valign=\"top\" width=\"14.28%\"><a href=\"https://github.com/KukovecRok\"><img src=\"https://avatars.githubusercontent.com/u/33880044?v=4?s=100\" width=\"100px;\" alt=\"Tatookie\"/><br /><sub><b>Tatookie</b></sub></a><br /><a href=\"https://github.com/firefly-cpp/sport-activities-features/commits?author=KukovecRok\" title=\"Code\">\ud83d\udcbb</a> <a href=\"https://github.com/firefly-cpp/sport-activities-features/issues?q=author%3AKukovecRok\" title=\"Bug reports\">\ud83d\udc1b</a> <a href=\"https://github.com/firefly-cpp/sport-activities-features/commits?author=KukovecRok\" title=\"Tests\">\u26a0\ufe0f</a> <a href=\"#example-KukovecRok\" title=\"Examples\">\ud83d\udca1</a> <a href=\"#maintenance-KukovecRok\" title=\"Maintenance\">\ud83d\udea7</a></td>\n      <td align=\"center\" valign=\"top\" width=\"14.28%\"><a href=\"https://github.com/zala-lahovnik\"><img src=\"https://avatars.githubusercontent.com/u/105444201?v=4?s=100\" width=\"100px;\" alt=\"Zala Lahovnik\"/><br /><sub><b>Zala Lahovnik</b></sub></a><br /><a href=\"https://github.com/firefly-cpp/sport-activities-features/commits?author=zala-lahovnik\" title=\"Documentation\">\ud83d\udcd6</a> <a href=\"https://github.com/firefly-cpp/sport-activities-features/commits?author=zala-lahovnik\" title=\"Code\">\ud83d\udcbb</a></td>\n      <td align=\"center\" valign=\"top\" width=\"14.28%\"><a href=\"https://github.com/lahovniktadej\"><img src=\"https://avatars.githubusercontent.com/u/57890734?v=4?s=100\" width=\"100px;\" alt=\"Tadej Lahovnik\"/><br /><sub><b>Tadej Lahovnik</b></sub></a><br /><a href=\"https://github.com/firefly-cpp/sport-activities-features/commits?author=lahovniktadej\" title=\"Documentation\">\ud83d\udcd6</a></td>\n    </tr>\n  </tbody>\n</table>\n\n<!-- markdownlint-restore -->\n<!-- prettier-ignore-end -->\n\n<!-- ALL-CONTRIBUTORS-LIST:END -->\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind are welcome!\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A minimalistic toolbox for extracting features from sport activity files",
    "version": "0.4.0",
    "project_urls": {
        "Documentation": "https://sport-activities-features.readthedocs.io/en/latest/",
        "Homepage": "https://github.com/firefly-cpp/sport-activities-features",
        "Repository": "https://github.com/firefly-cpp/sport-activities-features"
    },
    "split_keywords": [
        "computational intelligence",
        " cycling",
        " data mining",
        " datasets",
        " gpx",
        " optimization",
        " sport activities",
        " tcx"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "171734751894a10532e70ae1e315854c2dbf5d96d3c3f1999bcd2e57883cada3",
                "md5": "6aa005c538b532999b94324530baf0ba",
                "sha256": "2c150cbfe57a07141c3b39208bf9cd4d6f6e4aed1c7904ddadcc3ce7c8dbd9cc"
            },
            "downloads": -1,
            "filename": "sport_activities_features-0.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6aa005c538b532999b94324530baf0ba",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0.0,>=3.9.0",
            "size": 56516,
            "upload_time": "2024-03-29T10:13:44",
            "upload_time_iso_8601": "2024-03-29T10:13:44.388195Z",
            "url": "https://files.pythonhosted.org/packages/17/17/34751894a10532e70ae1e315854c2dbf5d96d3c3f1999bcd2e57883cada3/sport_activities_features-0.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8a16800f20e58ba1f8e1613c1bf25cf7ef9d0c11921b6b13eabc017e4f7fe63f",
                "md5": "0369f0301a0d7aada33bb59df9c18e26",
                "sha256": "32de0aa933cf0c119c796f65bc4b94b52b9fc01887f79772649e6a57b9232884"
            },
            "downloads": -1,
            "filename": "sport_activities_features-0.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "0369f0301a0d7aada33bb59df9c18e26",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0.0,>=3.9.0",
            "size": 53490,
            "upload_time": "2024-03-29T10:13:46",
            "upload_time_iso_8601": "2024-03-29T10:13:46.223276Z",
            "url": "https://files.pythonhosted.org/packages/8a/16/800f20e58ba1f8e1613c1bf25cf7ef9d0c11921b6b13eabc017e4f7fe63f/sport_activities_features-0.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-29 10:13:46",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "firefly-cpp",
    "github_project": "sport-activities-features",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "matplotlib",
            "specs": [
                [
                    ">=",
                    "3.3.3"
                ]
            ]
        },
        {
            "name": "geopy",
            "specs": [
                [
                    ">=",
                    "2.0.0"
                ]
            ]
        },
        {
            "name": "overpy",
            "specs": [
                [
                    ">=",
                    "0.6"
                ]
            ]
        },
        {
            "name": "geotiler",
            "specs": [
                [
                    ">=",
                    "0.14.5"
                ]
            ]
        },
        {
            "name": "numpy",
            "specs": [
                [
                    "==",
                    "1.24"
                ]
            ]
        },
        {
            "name": "tcxreader",
            "specs": [
                [
                    ">=",
                    "0.4.4"
                ]
            ]
        },
        {
            "name": "pandas",
            "specs": [
                [
                    "==",
                    "1.5.3"
                ]
            ]
        },
        {
            "name": "niaaml",
            "specs": [
                [
                    "==",
                    "1.1.11"
                ]
            ]
        },
        {
            "name": "tcx2gpx",
            "specs": [
                [
                    "==",
                    "0.1.4"
                ]
            ]
        },
        {
            "name": "gpxpy",
            "specs": [
                [
                    ">=",
                    "1.4.2"
                ]
            ]
        },
        {
            "name": "ruff",
            "specs": [
                [
                    "==",
                    "0.0.292"
                ]
            ]
        },
        {
            "name": "pytest",
            "specs": [
                [
                    ">=",
                    "7.2.2"
                ]
            ]
        }
    ],
    "lcname": "sport-activities-features"
}
        
Elapsed time: 0.24059s