Skip to content

Commit

Permalink
Add support for runback step. fix #25
Browse files Browse the repository at this point in the history
  • Loading branch information
gazpachoking committed Mar 26, 2022
1 parent 599b092 commit 401eab9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
license = "MIT"
Expand Down
25 changes: 15 additions & 10 deletions trainaspower/finalsurge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -94,7 +99,7 @@ def convert_step(step: models.Step, id_counter) -> dict:
],
"intensity": step.type,
"comments": None,
}
})
return s


Expand Down
4 changes: 2 additions & 2 deletions trainaspower/models.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -86,7 +86,7 @@ class Step:
class ConcreteStep(Step):
power_range: PowerRange
pace_range: PaceRange
length: Quantity
length: Optional[Quantity]


class RepeatStep(Step):
Expand Down
8 changes: 5 additions & 3 deletions trainaspower/trainasone.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import datetime
import re
from typing import Generator

import dateparser
Expand Down Expand Up @@ -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"
Expand All @@ -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

Expand Down

0 comments on commit 401eab9

Please sign in to comment.