aboutsummaryrefslogtreecommitdiff
path: root/src/Model/step.ml
diff options
context:
space:
mode:
authorJoris2020-03-03 10:44:35 +0100
committerJoris2020-03-03 10:44:35 +0100
commit5c636f11cdfed82634ee572645d765b704941b68 (patch)
tree51e11a0cfbbab284985e98fcb558d2975209a9b2 /src/Model/step.ml
parenta2880850a78fc36e2612215c83cbdeac0c980a5b (diff)
Initialize views from JavaScript
Diffstat (limited to 'src/Model/step.ml')
-rw-r--r--src/Model/step.ml40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/Model/step.ml b/src/Model/step.ml
new file mode 100644
index 0000000..02a110e
--- /dev/null
+++ b/src/Model/step.ml
@@ -0,0 +1,40 @@
+type step = Prepare | Work | Rest | End
+
+let prettyPrint step =
+ match step with
+ | Prepare -> "Prepare"
+ | Work -> "Work"
+ | Rest -> "Rest"
+ | End -> "End"
+
+type state = { step : step; remaining : int; tabata : int; cycle : int }
+
+let getAt (config : Config.config) elapsed =
+ let cycleDuration = config.work + config.rest in
+ let tabataDuration = config.prepare + (config.cycles * cycleDuration) in
+ if elapsed >= tabataDuration * config.tabatas then
+ {
+ step = End;
+ remaining = 0;
+ tabata = config.tabatas;
+ cycle = config.cycles;
+ }
+ else
+ let currentTabataElapsed = elapsed mod tabataDuration in
+ let step, remaining =
+ if currentTabataElapsed < config.prepare then
+ (Prepare, config.prepare - currentTabataElapsed)
+ else
+ let currentCycleElapsed =
+ (currentTabataElapsed - config.prepare) mod cycleDuration
+ in
+ if currentCycleElapsed < config.work then
+ (Work, config.work - currentCycleElapsed)
+ else (Rest, config.work + config.rest - currentCycleElapsed)
+ in
+ let tabata = (elapsed / tabataDuration) + 1 in
+ let cycle =
+ if currentTabataElapsed < config.prepare then 1
+ else ((currentTabataElapsed - config.prepare) / cycleDuration) + 1
+ in
+ { step; remaining; tabata; cycle }