Skip to content

Commit

Permalink
Merge pull request #2 from hanabix/support-interval
Browse files Browse the repository at this point in the history
支持简单跑步活动
  • Loading branch information
zhongl authored Jul 30, 2024
2 parents 23fe41e + cee5879 commit 845cf47
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/Box.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ trait Box[A] extends (A => Data):

object Box:
given laps(using MetersPerBeat[Performace]): Box[js.Array[Cast[Lap]]] = laps =>
val active = laps.filter(_.intensityType == "ACTIVE")
Data
.PartialPlotDataAutobinx()
.setY(active.map(_.mpb))
.setY(laps.map(_.mpb))
.setHoverinfo(cs.y)
.setWidth(0.1)
.setType(cs.box)
Expand Down
5 changes: 4 additions & 1 deletion src/GarminCN.scala
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,11 @@ object Garmin:

def laps(activityId: Double) =
val url = s"${base}/activity-service/activity/${activityId}/splits?_=${js.Date.now()}"
import Functional.*
inline def equal[A](a: A): js.UndefOr[A] => Boolean = a == _
inline def running: Cast[Lap] => Boolean = ((_: Cast[Lap]).intensityType) |> (equal("ACTIVE") || equal("INTERVAL"))
for r <- service[js.Dynamic](url, s"https://connect.garmin.cn/modern/activity/${activityId}")
yield r.lapDTOs.asInstanceOf[js.Array[Cast[Lap]]]
yield r.lapDTOs.asInstanceOf[js.Array[Cast[Lap]]].filter(running)

inline def service[A](url: String, referrerV: String = window.location.href): Future[A] =
val hi = js.Dynamic
Expand Down
8 changes: 4 additions & 4 deletions src/Scatter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ trait Scatter[A] extends (A => Data):
extension (a: A) def scatter = this(a)

object Scatter:

given laps(using
MetersPerBeat[Performace],
HoverText[Performace]
): Scatter[js.Array[Cast[Lap]]] =
laps =>
val active = laps.filter(_.intensityType == "ACTIVE")
Data
.PartialPlotDataAutobinx()
.setY(active.map(_.mpb))
.setX(active.map(_.lapIndex.get))
.setHovertext(active.map(_.text))
.setY(laps.map(_.mpb))
.setX(laps.map(_.lapIndex.get))
.setHovertext(laps.map(_.text))
.setHovertemplate("<b>%{y:.3f}</b><br>%{hovertext}<extra></extra>")

given activityLaps(using Scatter[js.Array[Cast[Lap]]], DateFormat[String]): Scatter[ActivityLaps] = ga =>
Expand Down

0 comments on commit 845cf47

Please sign in to comment.