Skip to content

Commit

Permalink
Merge pull request #18 from vkurup/package-clean-up
Browse files Browse the repository at this point in the history
Clean up package
  • Loading branch information
vkurup authored Apr 27, 2018
2 parents 9dd3ac9 + ab21099 commit 56309fd
Show file tree
Hide file tree
Showing 17 changed files with 211 additions and 68 deletions.
6 changes: 6 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[run]
branch = true
source = tcxparser

[report]
show_missing = true
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
sudo: false
language: python
python:
- "2.7"
install: python setup.py install
script: python setup.py test
- "3.5"
install: pip install tox-travis
script: tox
15 changes: 15 additions & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Primary author:
---------------

* Vinod Kurup (@vkurup)


Other contributions from:
-------------------------

* Iztok Fister Jr (@firefly-cpp)
* Jason M. (@DaddyTheRunner)
* Adam Neumann (@noizwaves)
* Stephen Doyle (@stevedoyle)

Thank you!
47 changes: 47 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
CHANGES
=======

v0.8.0, 2018-04-27
------------------

* Add coverage, flake8
* Support Python 3
* Move code into its own package
* Add some cycling support (#16)
* Run tests on CI using tox-travis


v0.7.2, 2017-03-02
------------------

* Don't fail if lat/lon not present.


v0.7.1, 2016-08-14
------------------

* Fix for tracks with only 1 trackpoint.


v0.7.0, 2016-01-01
------------------

* Added average altitude support. Thanks @firefly-cpp


v0.6.0, 2014-11-18
------------------

* Added heart rate data & pace support. Thanks @stevedoyle


v0.3.0, 2013-01-09
------------------

* Changed methods to properties


v0.1.0, 2013-01-07
------------------

* Initial release.
11 changes: 0 additions & 11 deletions CHANGES.txt

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE.txt → LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2013-6, Vinod Kurup
Copyright (c) 2013-8, Vinod Kurup
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand Down
41 changes: 35 additions & 6 deletions README.md → README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# python-tcxparser
python-tcxparser
================

[ ![Codeship Status for vkurup/python-tcxparser](https://codeship.com/projects/eb924480-4493-0134-5e03-3a611b6d72e6/status?branch=master)](https://codeship.com/projects/168475)
.. image:: https://img.shields.io/pypi/v/python-tcxparser.svg
:target: https://pypi.python.org/pypi/python-tcxparser
:alt: Latest PyPI version

.. image:: https://travis-ci.org/vkurup/python-tcxparser.svg?branch=master
:target: https://travis-ci.org/vkurup/python-tcxparser
:alt: Latest Travis CI build status

.. image:: https://pyup.io/repos/github/vkurup/python-tcxparser/shield.svg
:target: https://pyup.io/repos/github/vkurup/python-tcxparser/
:alt: Updates

python-tcxparser is a minimal parser for Garmin's TCX file format. It
is not in any way exhaustive. It extracts just enough data to allow me
Expand All @@ -21,11 +32,17 @@ Data extracted:
- max and min altitude
- time stamp of each data point (in ISO UTC)

## Installation
Installation
------------

Install it from PyPI::

pip install python-tcxparser
pip install python-tcxparser

## Usage
Usage
-----

Basic usage example::

>>> import tcxparser
>>> tcx = tcxparser.TCXParser('/home/vinod/Downloads/20121226-212953.tcx')
Expand All @@ -51,5 +68,17 @@ Data extracted:
... tcx.calories
379

## Contact
Compatibility
-------------

* Python 2.7 or 3.5+

License
-------

BSD

Contact
-------

Please contact me with any questions: Vinod Kurup ([email protected])
5 changes: 4 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[metadata]
description-file = README.md
description-file = README.rst

[flake8]
max-line-length = 120
19 changes: 13 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
from setuptools import setup
from setuptools import setup, find_packages

__version__ = '0.7.2'
__version__ = '0.8.0'

setup(
name='python-tcxparser',
version=__version__,
description='Simple parser for Garmin TCX files',
long_description=open('README.rst').read(),
author='Vinod Kurup',
author_email='[email protected]',
py_modules=['tcxparser', 'test_tcxparser'],
url='https://github.com/vkurup/python-tcxparser/',
packages=find_packages(include=['tcxparser']),
include_package_data=True,
license='BSD',
description='Simple parser for Garmin TCX files',
zip_safe=False,
keywords='tcx',
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Topic :: Software Development :: Libraries :: Python Modules',
],
long_description=open('README.md').read(),
install_requires=[
"lxml",
],
test_suite="test_tcxparser",
test_suite="tests",
)
1 change: 1 addition & 0 deletions tcxparser/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .tcxparser import TCXParser # noqa
30 changes: 16 additions & 14 deletions tcxparser.py → tcxparser/tcxparser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"Simple parser for Garmin TCX files."
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import time
from lxml import objectify
Expand All @@ -21,10 +25,10 @@ def altitude_points(self):

def time_values(self):
return [x.text for x in self.root.xpath('//ns:Time', namespaces={'ns': namespace})]

def cadence_values(self):
return [int(x.text) for x in self.root.xpath('//ns:Cadence', namespaces={'ns': namespace})]

@property
def latitude(self):
if hasattr(self.activity.Lap.Track.Trackpoint, 'Position'):
Expand All @@ -42,17 +46,15 @@ def activity_type(self):
@property
def completed_at(self):
return self.activity.Lap[-1].Track.Trackpoint[-1].Time.pyval

@property
def cadence_avg(self):
return self.activity.Lap[-1].Cadence

@property
def distance(self):
distance_values = self.root.findall('.//ns:DistanceMeters', namespaces={'ns': namespace})
if distance_values:
return distance_values[-1]
return 0
return distance_values[-1] if distance_values else 0

@property
def distance_units(self):
Expand All @@ -66,12 +68,12 @@ def duration(self):
@property
def calories(self):
return sum(lap.Calories for lap in self.activity.Lap)

@property
def hr_avg(self):
"""Average heart rate of the workout"""
hr_data = self.hr_values()
return sum(hr_data)/len(hr_data)
return int(sum(hr_data) / len(hr_data))

@property
def hr_max(self):
Expand All @@ -86,14 +88,14 @@ def hr_min(self):
@property
def pace(self):
"""Average pace (mm:ss/km for the workout"""
secs_per_km = self.duration/(self.distance/1000)
secs_per_km = self.duration / (self.distance / 1000)
return time.strftime('%M:%S', time.gmtime(secs_per_km))

@property
def altitude_avg(self):
"""Average altitude for the workout"""
altitude_data = self.altitude_points()
return sum(altitude_data)/len(altitude_data)
return sum(altitude_data) / len(altitude_data)

@property
def altitude_max(self):
Expand Down Expand Up @@ -131,6 +133,6 @@ def descent(self):

@property
def cadence_max(self):
"""Returns max cadence of workout"""
cadence_data = self.cadence_values()
return max(cadence_data)
"""Returns max cadence of workout"""
cadence_data = self.cadence_values()
return max(cadence_data)
Empty file added tests/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions tests/test_cycling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os
from unittest import TestCase

from tcxparser import TCXParser


class TestParseCyclingTCX(TestCase):

def setUp(self):
tcx_file = 'test2.tcx'
path = os.path.join(os.path.dirname(__file__), 'files', tcx_file)
self.tcx = TCXParser(path)

def test_cadence_max_is_correct(self):
self.assertEqual(self.tcx.cadence_max, 115)

def test_cadence_avg_is_correct(self):
self.assertEqual(self.tcx.cadence_avg, 82)
Loading

0 comments on commit 56309fd

Please sign in to comment.