aboutsummaryrefslogtreecommitdiff
path: root/src/state.ts
diff options
context:
space:
mode:
authorJoris2021-05-20 09:43:02 +0200
committerJoris2021-05-20 09:43:02 +0200
commitf9e7e819a0a673befb11b24404efeb9d6644bceb (patch)
tree07fdcc252964382568236647e74709980dc479d4 /src/state.ts
parentcde24cbf3fbc418af3c98d82e47dcd5df71e5b26 (diff)
downloadtabata-f9e7e819a0a673befb11b24404efeb9d6644bceb.tar.gz
tabata-f9e7e819a0a673befb11b24404efeb9d6644bceb.tar.bz2
tabata-f9e7e819a0a673befb11b24404efeb9d6644bceb.zip
Provide named exercices
Diffstat (limited to 'src/state.ts')
-rw-r--r--src/state.ts87
1 files changed, 0 insertions, 87 deletions
diff --git a/src/state.ts b/src/state.ts
deleted file mode 100644
index a0348f0..0000000
--- a/src/state.ts
+++ /dev/null
@@ -1,87 +0,0 @@
-import * as Config from 'config'
-
-export enum Step {
- WarmUp,
- Prepare,
- Work,
- Rest,
- End,
-}
-
-export function prettyPrintStep(step: Step): string {
- if (step === Step.WarmUp)
- return 'Warm Up'
- if (step === Step.Prepare)
- return 'Prepare'
- else if (step === Step.Work)
- return 'Work'
- else if (step === Step.Rest)
- return 'Rest'
- else
- return 'End'
-}
-
-export interface State {
- step: Step,
- remaining: number,
- info: string,
- elapsed: number,
-}
-
-export function getAt(config: Config.Config, elapsed: number): State {
- if (elapsed < config.warmup) {
- return {
- step: Step.WarmUp,
- remaining: config.warmup - elapsed,
- info: '',
- elapsed
- }
- }
-
- const tabataElapsed = elapsed - config.warmup
-
- const cycleDuration = config.work + config.rest
- const tabataDuration = config.prepare + (config.cycles * cycleDuration)
-
- if (tabataElapsed >= tabataDuration * config.tabatas) {
- return {
- step: Step.End,
- remaining: 0,
- info: '',
- elapsed
- }
- }
-
- const currentTabataElapsed = tabataElapsed % tabataDuration
- let step, remaining
- if (currentTabataElapsed < config.prepare) {
- step = Step.Prepare
- remaining = config.prepare - currentTabataElapsed
- } else {
- const currentCycleElapsed = (currentTabataElapsed - config.prepare) % cycleDuration
- if (currentCycleElapsed < config.work) {
- step = Step.Work
- remaining = config.work - currentCycleElapsed
- } else {
- step = Step.Rest
- remaining = config.work + config.rest - currentCycleElapsed
- }
- }
-
- const tabata = Math.floor(tabataElapsed / tabataDuration) + 1
- const cycle =
- currentTabataElapsed < config.prepare
- ? 1
- : Math.floor((currentTabataElapsed - config.prepare) / cycleDuration) + 1
- const info = stepCount(step, tabata, cycle)
-
- return { step, remaining, info, elapsed }
-}
-
-function stepCount(step: Step, tabata: number, cycle: number): string {
- if (step === Step.Work || step === Step.Rest) {
- return `#${tabata.toString()}.${cycle.toString()}`
- } else {
- return `#${tabata.toString()}`
- }
-}