Ejemplo n.º 1
0
def addTrackpoint(element, activity, trackpoint):
    timestamp  = unitconvert.local_date_to_utc(trackpoint.get_data("timestamp"))
    pos_lat    = trackpoint.get_data("position_lat")
    pos_long   = trackpoint.get_data("position_long")
    distance   = trackpoint.get_data("distance")
    altitude   = trackpoint.get_data("altitude")
    speed      = trackpoint.get_data("speed")
    heart_rate = trackpoint.get_data("heart_rate")

    createSubElement(element, "Time", timestamp.isoformat() + "Z")

    if pos_lat != None and pos_long != None:
        pos = createSubElement(element, "Position")
        createSubElement(pos, "LatitudeDegrees", str(unitconvert.semicircle_to_degrees(pos_lat)))
        createSubElement(pos, "LongitudeDegrees", str(unitconvert.semicircle_to_degrees(pos_long)))

    if altitude != None:
        createSubElement(element, "AltitudeMeters", str(altitude))
    if distance != None:
        createSubElement(element, "DistanceMeters", str(distance))

    if heart_rate != None:
        hr = createSubElement(element, "HeartRateBpm")
        hr.set(XML_SCHEMA + "type", "HeartRateInBeatsPerMinute_t")
        createSubElement(hr, "Value", str(heart_rate))

    if speed != None:
        ex  = createSubElement(element, "Extensions")
        tpx = createSubElement(ex, "TPX")
        tpx.set("xmlns", "http://www.garmin.com/xmlschemas/ActivityExtension/v2")
        tpx.set("CadenceSensor", "Footpod")
        createSubElement(tpx, "Speed", str(speed))
Ejemplo n.º 2
0
def add_lap(element, activity, lap):

    start_time = unitconvert.local_date_to_utc(lap.get_data("start_time"))
    end_time   = unitconvert.local_date_to_utc(lap.get_data("timestamp"))

    totaltime  = lap.get_data("total_elapsed_time")
    distance   = lap.get_data("total_distance")
    max_speed  = lap.get_data("max_speed") # opt
    calories   = lap.get_data("total_calories")

    #avg_heart  = lap.get_data("avg_heart_rate") #opt
    #max_heart  = lap.get_data("max_heart_rate") #opt

    intensity  = INTENSITY_MAP[lap.get_data("intensity")]

    cadence    = lap.get_data("avg_cadence") # XXX: or max?

    triggermet = LAP_TRIGGER_MAP[lap.get_data("lap_trigger")]

    #extensions

    lapelem = create_sub_element(element, "Lap")
    lapelem.set("StartTime", start_time.isoformat() + "Z")


    create_sub_element(lapelem, "TotalTimeSeconds", str(totaltime))
    create_sub_element(lapelem, "DistanceMeters", str(distance))
    create_sub_element(lapelem, "MaximumSpeed", str(max_speed))
    create_sub_element(lapelem, "Calories", str(calories))
    #create_sub_element(lapelem, "AverageHeartRateBpm", avg_heart)
    #create_sub_element(lapelem, "MaximumHeartRateBpm", max_heart)
    create_sub_element(lapelem, "Intensity", intensity)
    if cadence != None:
        create_sub_element(lapelem, "Cadence", str(cadence))
    create_sub_element(lapelem, "TriggerMethod", triggermet)

    # Add track points to lap
    trackelem = create_sub_element(lapelem, "Track")
    for trackpoint in activity.get_records_by_type('record'):
        tts = unitconvert.local_date_to_utc(trackpoint.get_data("timestamp"))
        if tts >= start_time and tts <= end_time:
            trackpointelem = create_sub_element(trackelem, "Trackpoint")
            add_trackpoint(trackpointelem, trackpoint)
Ejemplo n.º 3
0
def addLap(element, activity, lap):

    start_time = unitconvert.local_date_to_utc(lap.get_data("start_time"))
    end_time   = unitconvert.local_date_to_utc(lap.get_data("timestamp"))

    totaltime  = lap.get_data("total_elapsed_time")
    distance   = lap.get_data("total_distance")
    max_speed  = lap.get_data("max_speed") # opt
    calories   = lap.get_data("total_calories")

    avg_heart  = lap.get_data("avg_heart_rate") #opt
    max_heart  = lap.get_data("max_heart_rate") #opt

    intensity  = INTENSITY_MAP[lap.get_data("intensity")]

    #cadence    = #opt

    triggermet = LAP_TRIGGER_MAP[lap.get_data("lap_trigger")]

    #extensions

    lapelem = createSubElement(element, "Lap")
    lapelem.set("StartTime", start_time.isoformat() + "Z")


    createSubElement(lapelem, "TotalTimeSeconds", str(totaltime))
    createSubElement(lapelem, "DistanceMeters", str(distance))
    createSubElement(lapelem, "MaximumSpeed", str(max_speed))
    createSubElement(lapelem, "Calories", str(calories))
    #createSubElement(lapelem, "AverageHeartRateBpm", avg_heart)
    #createSubElement(lapelem, "MaximumHeartRateBpm", max_heart)
    createSubElement(lapelem, "Intensity", intensity)
    #createSubElement(lapelem, "Cadence", cadence)
    createSubElement(lapelem, "TriggerMethod", triggermet)

    # Add track points to lap
    trackelem = createSubElement(lapelem, "Track")
    for trackpoint in activity.get_records_by_type('record'):
        dt = unitconvert.local_date_to_utc(trackpoint.get_data("timestamp"))
        if dt >= start_time and dt <= end_time:
            trackpointelem = createSubElement(trackelem, "Trackpoint")
            addTrackpoint(trackpointelem, activity, trackpoint)
Ejemplo n.º 4
0
def add_activity(element, activity):

    session = next(activity.get_records_by_type('session'))

    # Sport type
    sport = session.get_data("sport")
    sport_mapping = {"running": "Running", "cycling": "Biking"}
    sport = sport_mapping[sport] if sport in sport_mapping else "Other"
    # Identity (in UTC)
    identity = unitconvert.local_date_to_utc(session.get_data("start_time"))

    actelem = create_sub_element(element, "Activity")
    actelem.set("Sport", sport)
    create_sub_element(actelem, "Id", identity.isoformat() + "Z")

    for lap in activity.get_records_by_type('lap'):
        add_lap(actelem, activity, lap)
Ejemplo n.º 5
0
def addActivity(element, activity):

    session = next(activity.get_records_by_type('session'))

    # Sport type
    sport = session.get_data("sport")
    sport_mapping = {"running": "Running", "cycling": "Biking"}
    sport = sport_mapping[sport] if sport in sport_mapping else "Other"
    # Identity (in UTC)
    identity = unitconvert.local_date_to_utc(session.get_data("start_time"))


    actelem = createSubElement(element, "Activity")
    actelem.set("Sport", sport)
    actidelem = createSubElement(actelem, "Id", identity.isoformat() + "Z")

    for lap in activity.get_records_by_type('lap'):
        addLap(actelem, activity, lap)