Browse Source

Fix?

main 2.0.4
Stian Fredrik Aune 2 years ago
parent
commit
255349fc95
  1. 4
      webui-react/src/models/Programs.ts
  2. 2
      webui-react/src/pages/EditProgramPage.tsx
  3. 4
      webui-react/src/pages/PlayPage.tsx
  4. 13
      webui-react/src/pages/WorkoutPage.tsx
  5. 49
      webui-react/src/pages/runtime/ProgramBoi.tsx
  6. 2
      webui-react/vite.config.ts
  7. 2
      ykonsole-exporter/src/main/kotlin/net/aiterp/git/ykonsole2/infrastructure/WorkoutExporter.kt
  8. 28
      ykonsole-iconsole/src/main/kotlin/net/aiterp/git/ykonsole2/infrastructure/IConsole.kt

4
webui-react/src/models/Programs.ts

@ -15,9 +15,9 @@ export interface ProgramStep {
export function weighting(step: ProgramStep) {
if (step.duration) {
if (step.duration.time) {
return 8 * step.duration.time;
return 4 * step.duration.time;
} else if (step.duration.calories) {
return 4 * step.duration.calories;
return 8 * step.duration.calories;
} else if (step.duration.distance) {
return step.duration.distance;
}

2
webui-react/src/pages/EditProgramPage.tsx

@ -56,7 +56,7 @@ export default function EditProgramPage() {
programRepo().save({id, name, steps: newSteps})
.then(res => {
if (res) {
navigate(program ? `/programs/${program.id}` : "/");
navigate(program ? `/programs/${program.id}` : "/", {replace: !!program});
refreshPrograms();
} else {
setWait(false);

4
webui-react/src/pages/PlayPage.tsx

@ -183,7 +183,9 @@ function RunPlayPage(): JSX.Element {
<ControlsBoi/>
{lastState && (
<Boi vertical="center" horizontal="left" style={{padding: "0.5vmax", paddingBottom: "0"}}>
<Value raw={lastState} valueKey="time"/>
<span style={{fontSize: "125%"}}>
<Value raw={lastState} valueKey="time"/>
</span>
<br/>
<Value raw={lastState} valueKey="calories"/>
<br/>

13
webui-react/src/pages/WorkoutPage.tsx

@ -32,9 +32,18 @@ export default function WorkoutPage(): JSX.Element {
const states = useMemo(() => getStates(id || "random"), [getStates, id]);
const [expanded, setExpanded] = useState(false);
const ratio = useMemo(() => {
if (expanded || !states) return 1;
if (states.length > 1800) return 300;
if (states.length > 900) return 60;
if (states.length > 300) return 30;
return 15;
}, [expanded, states]);
const wsFilter = useCallback((ws: WorkoutState, index: number, arr: WorkoutState[]) => {
return expanded || (ws.time % 15 === 0) || index === arr.length - 1;
}, [expanded]);
return (ws.time % ratio === 0) || index === arr.length - 1;
}, [ratio]);
useEffect(() => {
fetchWorkout(id || "random");

49
webui-react/src/pages/runtime/ProgramBoi.tsx

@ -16,15 +16,47 @@ interface ProgressState {
currentIndex: number
lastTransition: WorkoutState
lastValue: WorkoutState
toNext: { current: number, max: number }
toNext: ToNext
stopped: boolean
}
interface ToNext {
current: number,
max: number,
}
interface ProgressChange {
skip?: boolean
workoutState?: WorkoutState
}
function calculateToNext(
step: ProgramStep & StepMeta,
lastValue: WorkoutState,
lastTransition: WorkoutState,
): ToNext {
if (step.duration) {
if (step.duration.time) {
return {
current: lastValue.time - lastTransition.time,
max: step.duration.time,
};
} else if (step.duration.calories && lastTransition.calories !== undefined && lastValue.calories !== undefined) {
return {
current: lastValue.calories - lastTransition.calories,
max: step.duration.calories,
};
} else if (step.duration.distance && lastTransition.distance !== undefined && lastValue.distance !== undefined) {
return {
current: lastValue.distance - lastTransition.distance,
max: step.duration.distance,
};
}
}
throw new Error("Illegal state");
}
function programReducer(state: ProgressState, change: ProgressChange) {
let {steps, currentIndex, lastTransition, lastValue, toNext, stopped} = state;
@ -53,21 +85,16 @@ function programReducer(state: ProgressState, change: ProgressChange) {
const step = steps[currentIndex];
if (step.duration) {
if (step.duration.time) {
toNext.current = lastValue.time - lastTransition.time;
toNext.max = step.duration.time;
} else if (step.duration.calories && lastTransition.calories !== undefined && lastValue.calories !== undefined) {
toNext.current = lastValue.calories - lastTransition.calories;
toNext.max = step.duration.calories;
} else if (step.duration.distance && lastTransition.distance !== undefined && lastValue.distance !== undefined) {
toNext.current = lastValue.distance - lastTransition.distance;
toNext.max = step.duration.distance;
}
toNext = calculateToNext(step, lastValue, lastTransition);
if (toNext.current >= toNext.max) {
steps[currentIndex].actualDuration = diffLinearValues(lastValue, lastTransition);
currentIndex += 1;
lastTransition = lastValue;
if (currentIndex < steps.length) {
toNext = calculateToNext(steps[currentIndex], lastValue, lastTransition);
}
}
}
}

2
webui-react/vite.config.ts

@ -15,7 +15,7 @@ export default ({mode}) => {
server: {
proxy: {
"/api": {
target: 'http://localhost:8080',
target: 'http://localhost:9301',
changeOrigin: true,
},
}

2
ykonsole-exporter/src/main/kotlin/net/aiterp/git/ykonsole2/infrastructure/WorkoutExporter.kt

@ -29,7 +29,7 @@ class WorkoutExporter(
override suspend fun start(input: FlowBus<Command>, output: FlowBus<Event>) {
log.info("Checking recent workouts...")
val yesterday = Instant.now().minus(24, ChronoUnit.HOURS)
val yesterday = Instant.now().minus(1, ChronoUnit.HOURS)
for (workout in workoutRepo.fetchAll().filter { it.createdAt > yesterday }) {
export(workout)
}

28
ykonsole-iconsole/src/main/kotlin/net/aiterp/git/ykonsole2/infrastructure/IConsole.kt

@ -8,6 +8,7 @@ import net.aiterp.git.ykonsole2.domain.runtime.*
import net.aiterp.git.ykonsole2.infrastructure.drivers.abstracts.ActiveDriver
import net.aiterp.git.ykonsole2.infrastructure.iconsole.*
import net.aiterp.git.ykonsole2.application.logging.log
import java.time.Instant
import java.util.*
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds
@ -20,7 +21,11 @@ class IConsole : ActiveDriver() {
private var running = false
private var connected = false
private var tryingSince: Instant? = null
private var maxLevel = 20
private var lastCals = 0
private var lastMeters = 0
private val queue = Collections.synchronizedSet<Request?>(LinkedHashSet())
@ -30,6 +35,8 @@ class IConsole : ActiveDriver() {
private var btCommandInput: BluetoothGattCharacteristic? = null
private fun onConnect(device: Device, output: FlowBus<Event>) {
tryingSince = Instant.now()
if (!device.connectionString.startsWith("iconsole:")) {
logger.info("Ignoring non-iConsole $device")
return
@ -112,10 +119,13 @@ class IConsole : ActiveDriver() {
if (currentTime > lastTime) {
lastTime = currentTime
lastCals = maxOf(res.calories, lastCals)
lastMeters = maxOf((res.distance * 1000).toInt(), lastMeters)
output.emitBlocking(ValuesReceived(listOf(
Time(lastTime),
Calories(res.calories),
Distance((res.distance * 1000).toInt()),
Calories(lastCals),
Distance(lastMeters),
Level(res.level),
)))
}
@ -130,11 +140,23 @@ class IConsole : ActiveDriver() {
override fun onScanStopped() {
logger.info("Scan stopped")
tryingSince?.let { ts ->
if (ts.isBefore(Instant.now().minusSeconds(20))) {
central?.stopScan()
tryingSince = null
runBlocking {
output.emit(ErrorOccurred("Connection timeout after 20 seconds"))
output.emit(Disconnected)
}
}
}
}
override fun onDiscoveredPeripheral(peripheral: BluetoothPeripheral, scanResult: ScanResult) {
logger.info("Connecting to ${peripheral.name} (${peripheral.address})...")
tryingSince = null
central?.connectPeripheral(peripheral, cbPeripheral)
central?.stopScan()
}
@ -154,6 +176,8 @@ class IConsole : ActiveDriver() {
private fun onDisconnect() {
lastTime = 0
lastCals = 0
lastMeters = 0
running = false
connected = false

Loading…
Cancel
Save