forked from dtcooper/python-fitparse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample_program.py
More file actions
executable file
·66 lines (54 loc) · 1.97 KB
/
sample_program.py
File metadata and controls
executable file
·66 lines (54 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
#
# Copyright (c) 2011, David Cooper <dave@kupesoft.com>
# All rights reserved.
#
# Dedicated to Kate Lacey
#
# Permission to use, copy, modify, and/or distribute this software
# for any purpose with or without fee is hereby granted, provided
# that the above copyright notice, the above dedication, and this
# permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIMS ALL
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
# THE AUTHORS BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
import os
import sys
# Add folder to search path
PROJECT_PATH = os.path.realpath(os.path.join(sys.path[0], '..'))
sys.path.append(PROJECT_PATH)
from fitparse import Activity
quiet = 'quiet' in sys.argv or '-q' in sys.argv
filenames = None
if len(sys.argv) >= 2:
filenames = [f for f in sys.argv[1:] if os.path.exists(f)]
if not filenames:
filenames = [os.path.join(PROJECT_PATH, 'tests', 'data', 'sample-activity.fit')]
def print_record(rec, ):
global record_number
record_number += 1
print ("-- %d. #%d: %s (%d entries) " % (record_number, rec.num, rec.type.name, len(rec.fields))).ljust(60, '-')
for field in rec.fields:
to_print = "%s [%s]: %s" % (field.name, field.type.name, field.data)
if field.data is not None and field.units:
to_print += " [%s]" % field.units
print to_print
print
for f in filenames:
if quiet:
print f
else:
print ('##### %s ' % f).ljust(60, '#')
print_hook_func = None
if not quiet:
print_hook_func = print_record
record_number = 0
a = Activity(f)
a.parse(hook_func=print_hook_func)