Git Product home page Git Product logo

tcxdataprotocol's Introduction

TcxDataProtocol

Swift5 Version License Platform Readme Score

Provides a Swift version of the TCX XML format.

Installation

TcxDataProtocol is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'TcxDataProtocol'

Swift Package Manager:

dependencies: [
    .package(url: "https://github.com/FitnessKit/TcxDataProtocol", from: "1.0.2")
]

How to Use

Decode

let tcxUrl = URL(fileURLWithPath: "TestFile" + ".tcx")
let tcxData = try? Data(contentsOf: tcxUrl)

if let tcxData = tcxData {
    let tcxFile = try? TcxFile.decode(from: tcxData)
}

Encode

Each Trackpoint time has to be unique. Below example shows a per second increment from the previous.

let workoutStartDateTime = Date()
let build = Build(version: Version(major: 0, minor: 1, buildMajor: 0, buildMinor: 0), time: nil, builder: nil, type: .alpha)
let author = Author(name: "TcxDataProtocol", build: build, language: nil, partNumber: "11-22-33")
let track = [Track(trackPoint: [
                    Trackpoint(time: workoutStartDateTime.addingTimeInterval(Double(1)), position: nil, altitude: nil, distance: 1.11, heartRate: HeartRateInBeatsPerMinute(heartRate: 100), cadence: 100, sensorState: SensorState.present, extensions: [Extension(activityTrackpointExtension: ActivityTrackpointExtension.init(speed: 11.2, runCadence: nil, watts: 111, cadenceSensor: CadenceSensorType(rawValue: "bike")), activityLapExtension: nil, activityGoals: nil)]),
                    Trackpoint(time: workoutStartDateTime.addingTimeInterval(Double(2)), position: nil, altitude: nil, distance: 1.11, heartRate: HeartRateInBeatsPerMinute(heartRate: 101), cadence: 101, sensorState: SensorState.present, extensions: [Extension(activityTrackpointExtension: ActivityTrackpointExtension.init(speed: 11.3, runCadence: nil, watts: 222, cadenceSensor: CadenceSensorType(rawValue: "bike")), activityLapExtension: nil, activityGoals: nil)])
                    ])]

let lap = ActivityLap(startTime: workoutStartDateTime, totalTime: 45.0, distance: 12.0, maximumSpeed: nil, calories: 120, averageHeartRate: nil, maximumHeartRate: nil, intensity: .active, cadence: nil, triggerMethod: .manual, track: track, notes: nil, extensions: nil)

let activity = Activity(sport: .biking, identification: workoutStartDateTime, lap: [lap], notes: nil, training: nil, creator: nil)

let activities = ActivityList(activities: [activity], multiSportSession: nil)

let database = TrainingCenterDatabase(activities: activities, courses: nil, author: author)

let TCXFile = TcxFile(database: database)

let encodedData = try? TCXFile.encode(prettyPrinted: true)

if let encodedData = encodedData {
    let xml = String(bytes: encodedData, encoding: .utf8)
    print(xml!)
}

Supported Elements

  • ActivityList
  • Activity
  • ActivityLap
  • ActivityReference
  • Application
  • Author
  • Build
  • BuildType
  • Course
  • CourseLap
  • CourseList
  • CoursePoint
  • CoursePointType
  • Creator
  • Gender
  • HeartRateInBeatsPerMinute
  • HeartRateInBeatsPercentMax
  • Intensity
  • MultiSportSession
  • NextSport
  • Plan
  • Position
  • QuickWorkoutResults
  • SensorState
  • Sport
  • Track
  • Trackpoint
  • Training
  • TrainingType
  • TriggerMethod
  • Version

Supported Extensions

  • ActivityExtension

    • CadenceSensorType
    • ActivityTrackpointExtension
    • ActivityLapExtension
  • ActivityGoals

    • Measure
    • RecurrenceCode
    • Period
    • ActivityGoal
    • ActivityGoals

Author

This package is developed and maintained by Kevin A. Hoogheem

License

TcxDataProtocol is available under the MIT license

tcxdataprotocol's People

Contributors

chepiok avatar khoogheem avatar mjunkmyjunk avatar nnethery avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.