-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor more generic. * Clean code. * Clean code.
- Loading branch information
Showing
27 changed files
with
457 additions
and
426 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package core | ||
|
||
enum Gauge: | ||
case MeterPerBeat | ||
case BeatPerMinute | ||
case StepPerMinute | ||
case Pace | ||
|
||
def label: String = this match | ||
case MeterPerBeat => "mpb" | ||
case BeatPerMinute => "bpm" | ||
case StepPerMinute => "spm" | ||
case Pace => "/km" | ||
end Gauge | ||
object Gauge: | ||
type MeterPerBeat = MeterPerBeat.type | ||
type BeatPerMinute = BeatPerMinute.type | ||
type StepPerMinute = StepPerMinute.type | ||
type Pace = Pace.type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package core | ||
|
||
|
||
trait Page[A] extends (Mutation => Option[Mutation]) | ||
|
||
object Page: | ||
given any: Page[EmptyTuple] = Some(_) | ||
|
||
given tuple[H, T <: Tuple](using h: Page[H], t: Page[T]): Page[H *: T] = | ||
a => h(a).flatMap(t) | ||
|
||
def apply[A](using pa: Page[A]) = pa | ||
end Page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package core | ||
|
||
opaque type Read[T, A, B] = A => B | ||
object Read: | ||
def apply[T, A, B](a: A)(using r: Read[T, A, B]): B = r(a) | ||
|
||
def apply[T, A, B](f: A => B): Read[T, A, B] = f |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package garmin.read | ||
|
||
import scala.scalajs.js | ||
|
||
import core.* | ||
|
||
given Read[Gauge.BeatPerMinute, js.Dynamic, Double] = Read: a => | ||
a.averageHR.asInstanceOf[Double].round | ||
|
||
given Read[Gauge.StepPerMinute, js.Dynamic, Double] = Read: a => | ||
a.averageRunCadence.asInstanceOf[Double].round | ||
|
||
given Read[Distance, js.Dynamic, Double] = Read: a => | ||
a.distance.asInstanceOf[Double] | ||
|
||
given Read[Duration, js.Dynamic, Double] = Read: a => | ||
a.duration.asInstanceOf[Double] | ||
|
||
given Read[Timestamp, js.Dynamic, String] = Read: a => | ||
a.startTimeGMT.asInstanceOf[String] | ||
|
||
given [A](using | ||
Read[Distance, A, Double], | ||
Read[Duration, A, Double], | ||
Read[Gauge.BeatPerMinute, A, Double] | ||
): Read[Gauge.MeterPerBeat, A, Double] = Read: a => | ||
val speed = Read[Distance, A, Double](a) / Read[Duration, A, Double](a) | ||
val hr = Read[Gauge.BeatPerMinute, A, Double](a) | ||
speed * 60 / hr | ||
end given | ||
|
||
given [A](using | ||
Read[Distance, A, Double], | ||
Read[Duration, A, Double] | ||
): Read[Gauge.Pace, A, js.Date] = Read: a => | ||
inline val minute = 60 | ||
inline val hour = (60 * minute) | ||
inline def spm = Read[Duration, A, Double](a) / Read[Distance, A, Double](a) | ||
inline def spkm = Math.round(spm * 1000).intValue | ||
new js.Date(0, 0, 0, spkm / hour, spkm / minute, spkm % minute) | ||
end given | ||
|
||
extension (d: Double) private inline def round = js.Math.round(d) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package plotly | ||
|
||
import scala.scalajs.js | ||
|
||
import typings.plotlyJs.anon.PartialLayoutAxis | ||
import typings.plotlyJs.plotlyJsStrings.array | ||
import typings.plotlyJs.plotlyJsStrings.reversed | ||
import typings.plotlyJs.plotlyJsStrings.right | ||
import typings.plotlyJs.plotlyJsStrings.y2 | ||
|
||
import core.* | ||
|
||
opaque type Axis[T] = List[PartialLayoutAxis] | ||
object Axis: | ||
|
||
def apply[T](using a: Axis[T]): List[PartialLayoutAxis] = a | ||
|
||
given [A]: Axis[EmptyTuple] = Nil | ||
given [H, T <: Tuple](using h: Axis[H], t: Axis[T]): Axis[H *: T] = h ::: t | ||
|
||
given Axis[Gauge.MeterPerBeat] = PartialLayoutAxis() | ||
.setOverlaying(y2) | ||
.setTickformat(".2f") | ||
.setTickmodeSync | ||
:: Nil | ||
|
||
given Axis[Gauge.BeatPerMinute] = PartialLayoutAxis() | ||
.setSide(right) | ||
:: Nil | ||
|
||
given Axis[Gauge.StepPerMinute] = PartialLayoutAxis() | ||
.setSide(right) | ||
:: Nil | ||
|
||
given Axis[Gauge.Pace] = PartialLayoutAxis() | ||
.setSide(right) | ||
.setTickformat("%M:%S") | ||
.setAutorange(reversed) | ||
:: Nil | ||
|
||
given Axis[Distance] = PartialLayoutAxis() | ||
.setTickformat("~s") | ||
.setTicksuffix("m") | ||
.setTickmode(array) | ||
:: Nil | ||
|
||
given (using ColorPalette): Axis[Box] = PartialLayoutAxis() | ||
.setTickformat(".2f") | ||
.setColorIndex(0) | ||
:: Nil | ||
|
||
extension (a: PartialLayoutAxis) | ||
private inline def setTickmodeSync: PartialLayoutAxis = | ||
a.asInstanceOf[js.Dynamic].tickmode = "sync" | ||
a | ||
|
||
end Axis |
Oops, something went wrong.