Skip to content

Commit

Permalink
Add new 'power_adjust' config option.
Browse files Browse the repository at this point in the history
Warn about old X_pace_adjust options not working if still in config.
  • Loading branch information
gazpachoking committed Feb 7, 2022
1 parent bcf5e49 commit 0bace15
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
6 changes: 1 addition & 5 deletions config.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,5 @@ trainasone_email: [email protected]
trainasone_password: my_password
finalsurge_email: [email protected]
finalsurge_password: my_password
recovery_pace_adjust: [0, 0]
very_easy_pace_adjust: [0, 0]
easy_pace_adjust: [0, 0]
fast_pace_adjust: [0, 0]
extreme_pace_adjust: [0, 0]
power_adjust: [0, 0]
number_of_workouts: 1
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.2"
version = "0.7.3"
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
37 changes: 29 additions & 8 deletions trainaspower/models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import builtins
import datetime
from dataclasses import dataclass
from typing import List, NamedTuple, Union, Tuple
from typing import List, NamedTuple, Union, Tuple, Any

from loguru import logger
from pint import UnitRegistry, Quantity
from pydantic import BaseModel

from pydantic import BaseModel, Field, validator

ureg = UnitRegistry()
mile = ureg.mile
Expand All @@ -21,12 +22,24 @@ class Config(BaseModel):
trainasone_password: str
finalsurge_email: str
finalsurge_password: str
recovery_pace_adjust: Tuple[Union[float, int], Union[float, int]] = (0, 0)
very_easy_pace_adjust: Tuple[Union[float, int], Union[float, int]] = (0, 0)
easy_pace_adjust: Tuple[Union[float, int], Union[float, int]] = (0, 0)
fast_pace_adjust: Tuple[Union[float, int], Union[float, int]] = (0, 0)
extreme_pace_adjust: Tuple[Union[float, int], Union[float, int]] = (0, 0)
power_adjust: Tuple[Union[float, int], Union[float, int]] = (0, 0)
number_of_workouts: int = 1
# Old config values
recovery_pace_adjust: Any = Field(removed='Field `power_adjust` has been added instead')
very_easy_pace_adjust: Any = Field(removed='Field `power_adjust` has been added instead')
easy_pace_adjust: Any = Field(removed='Field `power_adjust` has been added instead')
fast_pace_adjust: Any = Field(removed='Field `power_adjust` has been added instead')
extreme_pace_adjust: Any = Field(removed='Field `power_adjust` has been added instead.')

@validator('*')
def warn_removed(cls, v, field):
removed = field.field_info.extra.get('removed')
if removed:
message = f'Config field `{field.name}` was removed.'
if isinstance(removed, str):
message += f' {removed}'
logger.warning(message)
return v

class Config:
extra = 'forbid'
Expand All @@ -41,6 +54,14 @@ def __init__(self, min_val, max_val):
self.min = max(0, min_val)
self.max = max_val

def __add__(self, other):
new = PowerRange(self.min, self.max)
if not len(other) == 2:
raise ValueError(f'Cannot add {repr(other)} to PowerRange')
new.min = builtins.max(0, self.min + other[0])
new.max += other[1]
return new


class PaceRange(NamedTuple):
min: Quantity
Expand Down
2 changes: 2 additions & 0 deletions trainaspower/trainasone.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ def convert_steps(steps, config: models.Config, perceived_effort: bool) -> Gener
else:
out_step.power_range = convert_pace_range_to_power(
out_step.pace_range)
# Add adjustment from config
out_step.power_range += config.power_adjust

yield out_step

Expand Down

0 comments on commit 0bace15

Please sign in to comment.