From 401eab917f5bb157d08138ed6da4d7496a3f0b08 Mon Sep 17 00:00:00 2001 From: Chase Sterling Date: Sat, 26 Mar 2022 14:56:26 -0400 Subject: [PATCH] Add support for runback step. fix #25 --- pyproject.toml | 2 +- trainaspower/finalsurge.py | 25 +++++++++++++++---------- trainaspower/models.py | 4 ++-- trainaspower/trainasone.py | 8 +++++--- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 0632611..25ecbda 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "trainaspower" -version = "0.7.4" +version = "0.7.5" description = "Convert TrainAsOne plans to power and upload to Final Surge for use with Stryd pod." authors = ["Chase Sterling "] license = "MIT" diff --git a/trainaspower/finalsurge.py b/trainaspower/finalsurge.py index bd632dc..6e99b58 100644 --- a/trainaspower/finalsurge.py +++ b/trainaspower/finalsurge.py @@ -58,20 +58,25 @@ def convert_step(step: models.Step, id_counter) -> dict: return convert_repeat(step, id_counter) if not isinstance(step, models.ConcreteStep): raise ValueError(f"unknown step type received {step.type}") - s = { + if step.length is None: + s = {"durationType": "OPEN"} + elif step.length.check("[time]"): + s = { + "durationType": "TIME", + "duration": str(timedelta(seconds=step.length.to("seconds").magnitude)), + } + else: + s = { + "durationType": "DISTANCE", + "durationDist": step.length.magnitude, + "distUnit": f"{step.length.units:~}", + } + s.update({ "type": "step", "id": next(id_counter), "name": None, - "durationType": "TIME" if step.length.check("[time]") else "DISTANCE", - "duration": ( - str(timedelta(seconds=step.length.to("seconds").magnitude)) - if step.length.check("[time]") - else 0 - ), "targetAbsOrPct": "", - "durationDist": 0 if step.length.check("[time]") else step.length.magnitude, "data": [], - "distUnit": f"{step.length.units:~}" if step.length.check("[length]") else "mi", "target": [ { "targetType": "power", @@ -94,7 +99,7 @@ def convert_step(step: models.Step, id_counter) -> dict: ], "intensity": step.type, "comments": None, - } + }) return s diff --git a/trainaspower/models.py b/trainaspower/models.py index 5ed47f7..f52ba4e 100644 --- a/trainaspower/models.py +++ b/trainaspower/models.py @@ -1,7 +1,7 @@ import builtins import datetime from dataclasses import dataclass -from typing import List, NamedTuple, Union, Tuple, Any +from typing import List, NamedTuple, Union, Tuple, Any, Optional from loguru import logger from pint import UnitRegistry, Quantity @@ -86,7 +86,7 @@ class Step: class ConcreteStep(Step): power_range: PowerRange pace_range: PaceRange - length: Quantity + length: Optional[Quantity] class RepeatStep(Step): diff --git a/trainaspower/trainasone.py b/trainaspower/trainasone.py index c79d4d5..7993bc5 100644 --- a/trainaspower/trainasone.py +++ b/trainaspower/trainasone.py @@ -1,5 +1,4 @@ import datetime -import re from typing import Generator import dateparser @@ -128,8 +127,8 @@ def convert_steps(steps, config: models.Config, perceived_effort: bool) -> Gener raise ValueError( f"Unsupported target type {step['targetType']}. Please ensure that you have selected speed as \"Workout step target\" in the TAO settings under \"Garmin workout preferences\"") - if step["intensity"] == "WARMUP": - out_step.type = "WARMUP" + if step["intensity"] in ["WARMUP", "COOLDOWN"]: + out_step.type = step["intensity"] elif step["intensity"] in active_step_types: if "targetValueLow" in step and step["targetValueLow"] == 0.0: out_step.type = "REST" @@ -141,6 +140,9 @@ def convert_steps(steps, config: models.Config, perceived_effort: bool) -> Gener if step["durationType"] == "DISTANCE": out_step.length = round( step["durationValue"]) * models.meter + elif step["durationType"] == "OPEN": + # Runback step + out_step.length = None else: out_step.length = step["durationValue"] * models.second