From c41b8438d30f2708998b233d9cb01d328ac069b3 Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Fri, 30 Sep 2022 13:00:12 +1300 Subject: [PATCH] Prevent counting hidden sets for prediction Closes #71 --- SetList.tsx | 6 +++++- best.service.ts | 4 ++-- set.service.ts | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/SetList.tsx b/SetList.tsx index da50094..e316076 100644 --- a/SetList.tsx +++ b/SetList.tsx @@ -35,16 +35,20 @@ export default function SetList() { setSet({...defaultSet}); if (settings.newSet === 'empty') return; const todaysSet = await getToday(); + console.log(`${SetList.name}.predict:`, {todaysSet}); if (!settings.newSet && todaysSet) return setSet({...todaysSet}); const todaysPlan = await getTodaysPlan(); + console.log(`${SetList.name}.predict:`, {todaysPlan}); if (todaysPlan.length === 0) return; const todaysWorkouts = todaysPlan[0].workouts.split(','); setWorkouts(todaysWorkouts); let workout = todaysWorkouts[0]; let best = await getBestSet(workout); + console.log(`${SetList.name}.predict:`, {workout, best}); if (!todaysSet || !todaysWorkouts.includes(todaysSet.name)) return setSet(best); let _count = await countToday(todaysSet.name); + console.log(`${SetList.name}.predict:`, {_count}); workout = todaysSet.name; best = await getBestSet(workout); const index = todaysWorkouts.indexOf(todaysSet.name) + 1; @@ -113,7 +117,7 @@ export default function SetList() { }, [search, end, offset, sets]); const onAdd = useCallback(async () => { - console.log(`${SetList.name}.onAdd`, {set, defaultSet, workouts}); + console.log(`${SetList.name}.onAdd`, {set, workouts}); navigation.navigate('EditSet', { set: set || {...defaultSet}, workouts, diff --git a/best.service.ts b/best.service.ts index 4b60533..f83ffe7 100644 --- a/best.service.ts +++ b/best.service.ts @@ -8,13 +8,13 @@ export const getBestSet = async (name: string): Promise => { const bestWeight = ` SELECT name, reps, unit, MAX(weight) AS weight FROM sets - WHERE name = ? AND NOT hidden + WHERE name = ? GROUP BY name; `; const bestReps = ` SELECT name, MAX(reps) as reps, unit, weight, sets, minutes, seconds FROM sets - WHERE name = ? AND weight = ? AND NOT hidden + WHERE name = ? AND weight = ? GROUP BY name; `; const [weightResult] = await db.executeSql(bestWeight, [name]); diff --git a/set.service.ts b/set.service.ts index d6d6d8c..01352ff 100644 --- a/set.service.ts +++ b/set.service.ts @@ -124,7 +124,7 @@ export const getNames = async (): Promise => { export const getToday = async (): Promise => { const select = ` - SELECT * FROM sets + SELECT name, reps, weight, sets, minutes, seconds, unit, image FROM sets WHERE NOT hidden AND created LIKE strftime('%Y-%m-%d%%', 'now', 'localtime') ORDER BY created DESC @@ -138,7 +138,7 @@ export const countToday = async (name: string): Promise => { const select = ` SELECT COUNT(*) as total FROM sets WHERE created LIKE strftime('%Y-%m-%d%%', 'now', 'localtime') - AND name = ? + AND name = ? AND NOT hidden `; const [result] = await db.executeSql(select, [name]); return Number(result.rows.item(0)?.total);