def create_lap(lap, sport_type):
    elements = [
        E.TotalTimeSeconds("%0.2f" % (lap.total_time / 100.)),
        E.DistanceMeters(str(lap.total_dist)),
        E.MaximumSpeed(str(lap.max_speed)),
        E.Calories(str(lap.calories))]
    if lap.avg_heart_rate or lap.max_heart_rate:
        elements.extend([
            E.AverageHeartRateBpm(E.Value(str(lap.avg_heart_rate))),
            E.MaximumHeartRateBpm(E.Value(str(lap.max_heart_rate)))])
    elements.append(
        E.Intensity(format_intensity(lap.intensity)))
    if lap.avg_cadence is not None and sport_type != 0:
        elements.append(
            E.Cadence(str(lap.avg_cadence)))
    elements.append(E.TriggerMethod(format_trigger_method(lap.trigger_method)))
    wpts = [el for el in (create_wpt(w, sport_type) for w in lap.wpts) if el is not None]
    if wpts:
        elements.append(E.Track(*wpts))
    if lap.avg_cadence is not None and sport_type == 0:
        elements.append(E.Extensions(X.LX(X.AvgRunCadence(str(lap.avg_cadence)))))
    return E.Lap(
        {"StartTime": format_time(lap.start_time.gmtime)},
        *elements)
dataset/ETHPy150Open braiden/python-ant-downloader/antd/tcx.py/create_lap/original