|
|
|
|
@ -36,6 +36,26 @@ case class PaceTarget(from: Pace, to: Pace) extends Target { |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case class PowerCustomTarget(from: Int, to: Int) extends Target { |
|
|
|
|
override def json = |
|
|
|
|
Json.obj( |
|
|
|
|
"targetType" -> Json.obj("workoutTargetTypeId" -> 2, "workoutTargetTypeKey" -> "power.zone"), |
|
|
|
|
"targetValueOne" -> from, |
|
|
|
|
"targetValueTwo" -> to, |
|
|
|
|
"zoneNumber" -> JsNull |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case class CadenceCustomTarget(from: Int, to: Int) extends Target { |
|
|
|
|
override def json = |
|
|
|
|
Json.obj( |
|
|
|
|
"targetType" -> Json.obj("workoutTargetTypeId" -> 3, "workoutTargetTypeKey" -> "cadence.zone"), |
|
|
|
|
"targetValueOne" -> from, |
|
|
|
|
"targetValueTwo" -> to, |
|
|
|
|
"zoneNumber" -> JsNull |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case class SpeedTarget(from: Speed, to: Speed) extends Target { |
|
|
|
|
override def json = |
|
|
|
|
Json.obj( |
|
|
|
|
@ -75,14 +95,18 @@ case class Speed(unit: DistanceUnits.DistanceUnit, exp: String) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
object Target { |
|
|
|
|
private val CadenceCustomRx = """^(\d{1,3})\s*-\s*(\d{1,3})\s*rpm$""".r |
|
|
|
|
private val HrZoneRx = """^z(\d)$""".r |
|
|
|
|
private val HrCustomRx = """^(\d{1,3})\s*-\s*(\d{1,3})\s*bpm$""".r |
|
|
|
|
private val PaceRangeRx = """^(\d{1,2}:\d{2})\s*-\s*(\d{1,2}:\d{2})\s*(mpk|mpm)?$""".r |
|
|
|
|
private val PowerCustomRx = """^(\d{1,3})\s*-\s*(\d{1,3})\s*W$""".r |
|
|
|
|
private val SpeedRangeRx = """^(\d{1,3}(\.\d{1})?)\s*-\s*(\d{1,3}(\.\d{1})?)\s*(kph|mph)?""".r |
|
|
|
|
|
|
|
|
|
def parse(x: String)(implicit msys: MeasurementSystems.MeasurementSystem): Target = x.trim match { |
|
|
|
|
case CadenceCustomRx(from, to) => CadenceCustomTarget(from.toInt, to.toInt) |
|
|
|
|
case HrZoneRx(zone) => HrZoneTarget(zone.toInt) |
|
|
|
|
case HrCustomRx(from, to) => HrCustomTarget(from.toInt, to.toInt) |
|
|
|
|
case PowerCustomRx(from, to) => PowerCustomTarget(from.toInt, to.toInt) |
|
|
|
|
case SpeedRangeRx(from, _, to, _, uom) => |
|
|
|
|
val du = Option(uom).fold(msys.distance)(DistanceUnits.withSpeedUOM) |
|
|
|
|
SpeedTarget(Speed(du, from), Speed(du, to)) |
|
|
|
|
|