Giter VIP home page Giter VIP logo

tcxdataprotocol's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tcxdataprotocol's Issues

Can't read TCX downloaded from Strava

When trying to read a TCX downloaded from Strava I get the following error:

No attribute or element found for key CodingKeys(stringValue: \"xmlns:ns2\", intValue: nil)

Which is correct, as it doesn't exist:

<TrainingCenterDatabase xmlns="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2" xmlns:up2="http://www.garmin.com/xmlschemas/UserProfile/v2" xmlns:ns3="http://www.garmin.com/xmlschemas/ActivityExtension/v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2 https://www8.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd http://www.garmin.com/xmlschemas/UserProfile/v2 https://www8.garmin.com/xmlschemas/UserProfileExtensionv2.xsd http://www.garmin.com/xmlschemas/ActivityExtension/v2 https://www8.garmin.com/xmlschemas/ActivityExtensionv2.xsd">

TCX file from Fitbit export fails

Hi,
I tested the decode and encode functions with my app and it worked very well.
But if I want to convert a TCX file from Fitbit export to the protocol it fails with the error:
The data couldn’t be read because it is missing.

Do you have any idea why it fails? I checked the TCX files and only found a difference at the tag and at the timestamp there is a 'Z' missing at the end.
But is that the root cause?
I attached the TCX file.
For any ideas I would be very happy.
Thanks

Is Power supported as an extension/element?

The Main Page (https://github.com/FitnessKit/TcxDataProtocol) does not list Power (watt) as a supported extension. However on the https://github.com/FitnessKit/TcxDataProtocol/blob/master/Sources/TcxDataProtocol/TcxExtensions/ActivityExtension.swift

I see there is watt there.

Anyways, this is taken from an indoor bike ride. Which I am looking to get power data (listed below as watt)

Just wanna confirm before I head down the rabbit hole to see if I can integrate this into my fitness app.
Thanks a Bunch.

       <Trackpoint>
            <Time>2020-10-04T01:14:10.000Z</Time>
            <HeartRateBpm xsi:type="HeartRateInBeatsPerMinute_t">
              <Value>77</Value>
            </HeartRateBpm>
            <Extensions>
              <TPX xmlns="http://www.garmin.com/xmlschemas/ActivityExtension/v2">
                <Speed>0</Speed>
                <Watts>74</Watts>
              </TPX>
            </Extensions>
          </Trackpoint>

TCX file need an XML root node

TCX file need a root XML node at the start (Strava rejects the file when the tag is not available). need <?xml version="1.0" encoding="UTF-8"?>

Problems using TCXFile.encode (BAD_ACCESS) - use of undeclared type XMLCoder

Hi,

I integrated TcxDataProtocol via Swift Package Manager into my app (Xcode 11.2.1, iOS, Swift 5) and had problems using the encode method of TCXFile. It gave an error in XMLKeyedEcondingContainer : 115 (EXC_BAD_ACCESS). Looking at some of the local variable and printing descriptions, some crash the debugger and others (Box) print the following description:

Printing description of box:
expression produced error: error: /var/folders/n6/mv47q0_15pz4802ptgpwg58m0000gn/T/expr5-c80751..swift:1:65: error: use of undeclared type 'XMLCoder'
Swift._DebuggerSupport.stringForPrintObject(Swift.UnsafePointer<XMLCoder.Box>(bitPattern: 0x10430d2f0)!.pointee)

So, I made a brand new project, TcxDataProtocol integrated via Swift Package Manager, with a single button to trigger the code example in the README.MD.

It gives the same error in the same method with underlying descriptions still giving the undeclared type XMLCoder error.

The error occurs on the simulator and installed on a device.

This is very odd because it comes down from Swift Package Manager fine ([email protected], [email protected]), builds and runs fine. The error appears to be thrown from an XMLCoder class so it doesn't really make sense.

I also tried adding XMLCoder via Swift Package Manager additionally (also adding the Framework, but it still gave the same error.

I couldn't see any other setup instructions in the README, but have I missed anything?

Thanks
Rich

TCX Decoding is very "particular" and only expects specific formats

I am trying to decode TCX data downloaded off Strava / RideWithGPS (even rides which the TCX is encoded by TCXDataProtocol) and I'm seeing a lot of inability to decode them.

When these TCX (from Strava / RideWithGPS) is uploaded to Garmin and then re-downloaded the TCX file, it will work.

I found that TcxDataProtocol is looking for very specific tags.

eg:
This results in decoding error

            <Extensions>
              <TPX xmlns="http://www.garmin.com/xmlschemas/ActivityExtension/v2">
                <Watts>139</Watts>
              </TPX>

Changing It to this works:

              <ns3:TPX>
                <ns3:Watts>139</ns3:Watts>
              </ns3:TPX>

For DateTime, the expectation is that this is the formatting,

            <Time>2020-02-22T17:19:56.000Z</Time>

but files downloaded from Strava/RideWithGPS would be encoded in this format and it would fail

            <Time>2020-02-22T17:19:56Z</Time>

Changing this line within TcxFile.swift would then make it work

/// TCX xss:timedate Formatter

    /// TCX xss:timedate Formatter
    private static let formatter: DateFormatter = {
        let formatter = DateFormatter()
//        formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
        formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'"
        formatter.timeZone = TimeZone(identifier: "UTC")
        formatter.locale = Locale(identifier: "en_US_POSIX")
        return formatter
    }()

This was the error from the debugger.

Swift.DecodingError.dataCorrupted(Swift.DecodingError.Context(codingPath: 
[CodingKeys(stringValue: "Activities", intValue: nil), 
CodingKeys(stringValue: "Activity", intValue: nil),
 XMLKey(stringValue: "0", intValue: 0), 
XMLKey(stringValue: "0", intValue: 0), 
CodingKeys(stringValue: "Id", intValue: nil)], 
debugDescription: "Date string does not match format expected by formatter.", underlyingError: nil))

Also for the XML Root, I found that if I were to indent the root, even by 1 space, the file will fail to be decoded.
eg:
<?xml version="1.0" encoding="UTF-8"?>
vs
(single space indent)<?xml version="1.0" encoding="UTF-8"?>

results in this error
Error Domain=NSXMLParserErrorDomain Code=111 "(null)"

Trying this within Xcode debugger:

(lldb) po TcxFile.decode(from: tcxData)
▿ DecodingError
  ▿ keyNotFound : 2 elements
    - .0 : CodingKeys(stringValue: "xmlns:ns4", intValue: nil)
    ▿ .1 : Context
      ▿ codingPath : 1 element
        - 0 : CodingKeys(stringValue: "xmlns:ns4", intValue: nil)
      - debugDescription : "No attribute or element found for key CodingKeys(stringValue: \"xmlns:ns4\", intValue: nil) (\"xmlns:ns4\")."
      - underlyingError : nil

Pasting the file (I've edited this file to only show 1 single trackpoint:

<?xml version="1.0" encoding="UTF-8"?>
<TrainingCenterDatabase xsi:schemaLocation="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2 http://www.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd" xmlns:ns5="http://www.garmin.com/xmlschemas/ActivityGoals/v1" xmlns:ns3="http://www.garmin.com/xmlschemas/ActivityExtension/v2" xmlns:ns2="http://www.garmin.com/xmlschemas/UserProfile/v2" xmlns="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<Activities>
		<Activity Sport="Other">
			<Id>2021-09-02T13:32:39Z</Id>
			<Lap StartTime="2021-09-02T13:32:39Z">
				<TotalTimeSeconds>0.0</TotalTimeSeconds>
				<DistanceMeters>174.97</DistanceMeters>
				<MaximumSpeed>12240.0</MaximumSpeed>
				<Calories>0</Calories>
				<AverageHeartRateBpm>
					<Value>101</Value>
				</AverageHeartRateBpm>
				<MaximumHeartRateBpm>
					<Value>105</Value>
				</MaximumHeartRateBpm>
				<Intensity>Active</Intensity>
				<Cadence>52</Cadence>
				<TriggerMethod>Manual</TriggerMethod>
				<Track>
					<Trackpoint>
						<Time>2021-09-02T13:32:39Z</Time>
						<Position>
							<LatitudeDegrees>2.7607049513608217</LatitudeDegrees>
							<LongitudeDegrees>101.738374941051</LongitudeDegrees>
						</Position>
						<AltitudeMeters>43.0</AltitudeMeters>
						<DistanceMeters>2.4000000953674316</DistanceMeters>
						<HeartRateBpm>
							<Value>104</Value>
						</HeartRateBpm>
						<Extensions>
							<ns3:TPX>
								<ns3:Speed>0.0</ns3:Speed>
								<ns3:Watts>84</ns3:Watts>
							</ns3:TPX>
						</Extensions>
					</Trackpoint>
				</Track>
			</Lap>
		</Activity>
	</Activities>
	<Author xsi:type="Application_t">
		<Name>Connect Api</Name>
		<Build>
			<Version>
				<VersionMajor>0</VersionMajor>
				<VersionMinor>0</VersionMinor>
				<BuildMajor>0</BuildMajor>
				<BuildMinor>0</BuildMinor>
			</Version>
		</Build>
		<LangID>en</LangID>
		<PartNumber>006-D2449-00</PartNumber>
	</Author>
</TrainingCenterDatabase>

Thanks!

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.