From 7ea91eeca9ab119458c03eb656901b4dd5889f2a Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Thu, 26 Oct 2023 21:34:50 +1300 Subject: [PATCH] =?UTF-8?q?Add=20most=20active=20hours=20of=20the=20day=20?= =?UTF-8?q?to=20insights=20-=201.166=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- InsightsPage.tsx | 156 +++++++++++++++++++++++++++++---------- android/app/build.gradle | 4 +- package.json | 2 +- 3 files changed, 121 insertions(+), 41 deletions(-) diff --git a/InsightsPage.tsx b/InsightsPage.tsx index 8f38fd7..c86e19a 100644 --- a/InsightsPage.tsx +++ b/InsightsPage.tsx @@ -1,6 +1,6 @@ import { useFocusEffect } from "@react-navigation/native"; -import { useCallback, useState } from "react"; -import { View } from "react-native"; +import { useCallback, useEffect, useState } from "react"; +import { ScrollView, View } from "react-native"; import { IconButton, Text } from "react-native-paper"; import AppBarChart from "./AppBarChart"; import { MARGIN, PADDING } from "./constants"; @@ -10,16 +10,24 @@ import { DAYS } from "./time"; import Select from "./Select"; import { Periods } from "./periods"; import ConfirmDialog from "./ConfirmDialog"; +import Chart from "./Chart"; -export interface WeekCounts { - week: number; +interface WeekCount { + week: string; + count: number; +} + +interface HourCount { + hour: string; count: number; } export default function InsightsPage() { - const [weekCounts, setWeekCounts] = useState([]); + const [weekCounts, setWeekCounts] = useState([]); + const [hourCounts, setHourCounts] = useState([]); const [period, setPeriod] = useState(Periods.Monthly); - const [showActive, setShowActive] = useState(false); + const [showWeek, setShowWeek] = useState(false); + const [showHour, setShowHour] = useState(false); useFocusEffect( useCallback(() => { @@ -27,27 +35,57 @@ export default function InsightsPage() { if (period === Periods.TwoMonths) difference = "-2 months"; if (period === Periods.ThreeMonths) difference = "-3 months"; if (period === Periods.SixMonths) difference = "-6 months"; - const select = ` - SELECT strftime('%w', created) as week, COUNT(*) as count - FROM sets - WHERE DATE(created) >= DATE('now', 'weekday 0', '${difference}') - GROUP BY week - HAVING week IS NOT NULL - ORDER BY count DESC; - `; - AppDataSource.manager.query(select).then(setWeekCounts); + const selectWeeks = ` + SELECT strftime('%w', created) as week, COUNT(*) as count + FROM sets + WHERE DATE(created) >= DATE('now', 'weekday 0', '${difference}') + GROUP BY week + HAVING week IS NOT NULL + ORDER BY count DESC; + `; + const selectHours = ` + SELECT strftime('%H', created) AS hour, COUNT(*) AS count + FROM sets + WHERE DATE(created) >= DATE('now', 'weekday 0', '${difference}') + GROUP BY hour + having hour is not null + ORDER BY hour + `; + AppDataSource.manager.query(selectWeeks).then(setWeekCounts); + AppDataSource.manager.query(selectHours).then(setHourCounts); }, [period]) ); + const hourLabel = (hour: string) => { + let twelveHour = Number(hour); + if (twelveHour === 0) return "12AM"; + let amPm = "AM"; + if (twelveHour >= 12) amPm = "PM"; + if (twelveHour > 12) twelveHour -= 12; + return `${twelveHour} ${amPm}`; + }; + return ( <> - + setPeriod(value as Periods)} - /> - ({ - label: DAYS[weekCount.week], - value: weekCount.count, - }))} - /> - + {weekCounts.length > 0 ? ( + ({ + label: DAYS[weekCount.week], + value: weekCount.count, + }))} + /> + ) : ( + + No entries yet! Start recording sets to see your most active days of + the week. + + )} + + + + Most active hours of the day + + setShowHour(true)} + /> + + + {hourCounts.length > 0 ? ( + hc.count)} + labels={hourCounts.map((hc) => hourLabel(hc.hour))} + /> + ) : ( + + No entries yet! Start recording sets to see your most active hours + of the day. + + )} + + setShowActive(false)} + show={showWeek} + setShow={setShowWeek} + onOk={() => setShowWeek(false)} > If your plan expects an equal # of sets each day of the week, then this pie graph should be evenly sliced. + + setShowHour(false)} + > + If you find yourself giving up on the gym after 5pm, consider starting + earlier! Or vice-versa. + ); } diff --git a/android/app/build.gradle b/android/app/build.gradle index 840dd4f..2a879a4 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -85,8 +85,8 @@ android { applicationId "com.massive" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 36191 - versionName "1.165" + versionCode 36192 + versionName "1.166" } signingConfigs { release { diff --git a/package.json b/package.json index 41af103..0ee5c78 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "massive", - "version": "1.165", + "version": "1.166", "private": true, "license": "GPL-3.0-only", "scripts": {