@@ -160,6 +160,15 @@ public class Workout {
160160 }
161161 }
162162
163+ /// The weather temperature during the workout.
164+ public var weatherTemperature : HKQuantity ? {
165+ raw. metadata ? [ HKMetadataKeyWeatherTemperature] as? HKQuantity
166+ }
167+ /// The weather humidity during the workout.
168+ public var weatherHumidity : HKQuantity ? {
169+ raw. metadata ? [ HKMetadataKeyWeatherHumidity] as? HKQuantity
170+ }
171+
163172 private var rawStart : TimeInterval {
164173 return raw. startDate. timeIntervalSince1970
165174 }
@@ -432,7 +441,9 @@ public class Workout {
432441 activeEnergy? . formatAsEnergy ( withUnit: WorkoutUnit . calories. unit ( for: systemOfUnits) , rawFormat: true ) . toCSV ( ) ?? " " ,
433442 totalEnergy? . formatAsEnergy ( withUnit: WorkoutUnit . calories. unit ( for: systemOfUnits) , rawFormat: true ) . toCSV ( ) ?? " " ,
434443 elevationChange. ascended? . formatAsElevationChange ( withUnit: WorkoutUnit . elevation. unit ( for: systemOfUnits) , rawFormat: true ) . toCSV ( ) ?? " " ,
435- elevationChange. descended? . formatAsElevationChange ( withUnit: WorkoutUnit . elevation. unit ( for: systemOfUnits) , rawFormat: true ) . toCSV ( ) ?? " "
444+ elevationChange. descended? . formatAsElevationChange ( withUnit: WorkoutUnit . elevation. unit ( for: systemOfUnits) , rawFormat: true ) . toCSV ( ) ?? " " ,
445+ weatherTemperature? . formatAsTemperature ( withUnit: WorkoutUnit . temperature. unit ( for: systemOfUnits) , rawFormat: true ) . toCSV ( ) ?? " " ,
446+ weatherHumidity? . formatAsPercentage ( withUnit: WorkoutUnit . percentage. unit ( for: systemOfUnits) , rawFormat: true ) . toCSV ( ) ?? " "
436447 ]
437448 }
438449
@@ -472,15 +483,17 @@ public class Workout {
472483 try file. write ( " Start \( sep) " + genData[ 1 ] + " \n " )
473484 try file. write ( " End \( sep) " + genData[ 2 ] + " \n " )
474485 try file. write ( " Duration \( sep) " + genData[ 3 ] + " \n " )
475- try file. write ( " \( " Distance \( self . distanceUnit. unit ( for: systemOfUnits) . description ) " . toCSV ( ) ) \( sep) " + genData[ 4 ] + " \n " )
486+ try file. write ( " \( " Distance \( self . distanceUnit. unit ( for: systemOfUnits) . symbol ) " . toCSV ( ) ) \( sep) " + genData[ 4 ] + " \n " )
476487 try file. write ( " \( " Average Heart Rate " . toCSV ( ) ) \( sep) " + genData[ 5 ] + " \n " )
477488 try file. write ( " \( " Max Heart Rate " . toCSV ( ) ) \( sep) " + genData[ 6 ] + " \n " )
478- try file. write ( " \( " Average Pace time/ \( self . paceUnit. unit ( for: systemOfUnits) . description) " . toCSV ( ) ) \( sep) " + genData[ 7 ] + " \n " )
479- try file. write ( " \( " Average Speed \( self . speedUnit. unit ( for: systemOfUnits) . description) " . toCSV ( ) ) \( sep) " + genData[ 8 ] + " \n " )
480- try file. write ( " \( " Active Energy \( WorkoutUnit . calories. unit ( for: systemOfUnits) . description) " . toCSV ( ) ) \( sep) " + genData[ 9 ] + " \n " )
481- try file. write ( " \( " Total Energy \( WorkoutUnit . calories. unit ( for: systemOfUnits) . description) " . toCSV ( ) ) \( sep) " + genData[ 10 ] + " \n " )
482- try file. write ( " \( " Elevation Ascended \( WorkoutUnit . elevation. unit ( for: systemOfUnits) . description) " . toCSV ( ) ) \( sep) " + genData[ 11 ] + " \n " )
483- try file. write ( " \( " Elevation Descended \( WorkoutUnit . elevation. unit ( for: systemOfUnits) . description) " . toCSV ( ) ) \( sep) " + genData[ 12 ] + " \n " )
489+ try file. write ( " \( " Average Pace time/ \( self . paceUnit. unit ( for: systemOfUnits) . symbol) " . toCSV ( ) ) \( sep) " + genData[ 7 ] + " \n " )
490+ try file. write ( " \( " Average Speed \( self . speedUnit. unit ( for: systemOfUnits) . symbol) " . toCSV ( ) ) \( sep) " + genData[ 8 ] + " \n " )
491+ try file. write ( " \( " Active Energy \( WorkoutUnit . calories. unit ( for: systemOfUnits) . symbol) " . toCSV ( ) ) \( sep) " + genData[ 9 ] + " \n " )
492+ try file. write ( " \( " Total Energy \( WorkoutUnit . calories. unit ( for: systemOfUnits) . symbol) " . toCSV ( ) ) \( sep) " + genData[ 10 ] + " \n " )
493+ try file. write ( " \( " Elevation Ascended \( WorkoutUnit . elevation. unit ( for: systemOfUnits) . symbol) " . toCSV ( ) ) \( sep) " + genData[ 11 ] + " \n " )
494+ try file. write ( " \( " Elevation Descended \( WorkoutUnit . elevation. unit ( for: systemOfUnits) . symbol) " . toCSV ( ) ) \( sep) " + genData[ 12 ] + " \n " )
495+ try file. write ( " \( " Weather Temperature \( WorkoutUnit . temperature. unit ( for: systemOfUnits) . symbol) " . toCSV ( ) ) \( sep) " + genData[ 13 ] + " \n " )
496+ try file. write ( " \( " Weather Humidity \( WorkoutUnit . percentage. unit ( for: systemOfUnits) . symbol) " . toCSV ( ) ) \( sep) " + genData[ 14 ] + " \n " )
484497 } catch {
485498 callback ( nil )
486499 return
0 commit comments