diff --git a/Stronger.xcodeproj/project.pbxproj b/Stronger.xcodeproj/project.pbxproj index 70aa2e7..625e3c6 100644 --- a/Stronger.xcodeproj/project.pbxproj +++ b/Stronger.xcodeproj/project.pbxproj @@ -84,6 +84,7 @@ 38756AB22B946D0E00FDF599 /* ExerciseInfo.json in Resources */ = {isa = PBXBuildFile; fileRef = 38756AB12B946D0E00FDF599 /* ExerciseInfo.json */; }; 38C4563E2B96CF3B009D69AA /* WorkoutHomeButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38C4563D2B96CF3B009D69AA /* WorkoutHomeButton.swift */; }; 38FE1D022B716A42008F8BE0 /* WorkoutVideoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38FE1D012B7169DF008F8BE0 /* WorkoutVideoView.swift */; }; + 4002F0AC2B9AFC4D00AD3D47 /* MissedWorkoutTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4002F0AB2B9AFC4D00AD3D47 /* MissedWorkoutTest.swift */; }; 4011141A2B7EE59A000083A2 /* ProgressCircle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 401114192B7EE59A000083A2 /* ProgressCircle.swift */; }; 4011141D2B83FCD1000083A2 /* SummaryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4011141C2B83FCD1000083A2 /* SummaryView.swift */; }; 401114232B8489D1000083A2 /* GoalResist.swift in Sources */ = {isa = PBXBuildFile; fileRef = 401114222B8489D1000083A2 /* GoalResist.swift */; }; @@ -218,6 +219,7 @@ 38756AB12B946D0E00FDF599 /* ExerciseInfo.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = ExerciseInfo.json; sourceTree = ""; }; 38C4563D2B96CF3B009D69AA /* WorkoutHomeButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WorkoutHomeButton.swift; sourceTree = ""; }; 38FE1D012B7169DF008F8BE0 /* WorkoutVideoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorkoutVideoView.swift; sourceTree = ""; }; + 4002F0AB2B9AFC4D00AD3D47 /* MissedWorkoutTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MissedWorkoutTest.swift; sourceTree = ""; }; 401114192B7EE59A000083A2 /* ProgressCircle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressCircle.swift; sourceTree = ""; }; 4011141C2B83FCD1000083A2 /* SummaryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SummaryView.swift; sourceTree = ""; }; 401114222B8489D1000083A2 /* GoalResist.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GoalResist.swift; sourceTree = ""; }; @@ -566,6 +568,7 @@ 40D4E47E2B97CB9900261632 /* HomeTest.swift */, 40D4E4812B97CBB800261632 /* TapSwitchTest.swift */, 40D4E4832B97CD0A00261632 /* WorkoutTest.swift */, + 4002F0AB2B9AFC4D00AD3D47 /* MissedWorkoutTest.swift */, ); path = StrongerUITests; sourceTree = ""; @@ -920,6 +923,7 @@ 40D4E47F2B97CB9900261632 /* HomeTest.swift in Sources */, 2F4E237E2989A2FE0013F3D9 /* LaunchTests.swift in Sources */, 40D4E4822B97CBB800261632 /* TapSwitchTest.swift in Sources */, + 4002F0AC2B9AFC4D00AD3D47 /* MissedWorkoutTest.swift in Sources */, 40D4E4842B97CD0A00261632 /* WorkoutTest.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Stronger/Account/Height.swift b/Stronger/Account/Height.swift index e1a68dd..8b88379 100644 --- a/Stronger/Account/Height.swift +++ b/Stronger/Account/Height.swift @@ -60,7 +60,7 @@ extension HeightKey { @Binding private var height: Int public var body: some View { HStack { - Text(HeightKey.name) + Text("\(HeightKey.name): inches") Spacer() TextField("Height", value: $height, formatter: NumberFormatter()) .frame(width: 120) // set frame width to enable more spaces. diff --git a/Stronger/Account/StartDate.swift b/Stronger/Account/StartDate.swift index be2114a..3394f19 100644 --- a/Stronger/Account/StartDate.swift +++ b/Stronger/Account/StartDate.swift @@ -23,8 +23,11 @@ public struct StartDateKey: AccountKey { public static let category: AccountKeyCategory = .personalDetails public static var initialValue: InitialValue { - .empty(Date()) + .default(Date()) } +// public static var initialValue: Date { +// Date() +// } } extension AccountKeys { diff --git a/Stronger/Account/StartDatePicker.swift b/Stronger/Account/StartDatePicker.swift index eedfe71..18bf849 100644 --- a/Stronger/Account/StartDatePicker.swift +++ b/Stronger/Account/StartDatePicker.swift @@ -30,7 +30,10 @@ public struct StartDatePicker: DataEntryView { private var dateRange: ClosedRange { let calendar = Calendar.current let startDateComponents = DateComponents(year: 1800, month: 1, day: 1) - let endDate = Date.now + let curDate = Date.now + guard let endDate = Calendar.current.date(byAdding: .day, value: 1, to: curDate) else { + fatalError("Could not translate \(startDateComponents) to a valid date.") + } guard let startDate = calendar.date(from: startDateComponents) else { fatalError("Could not translate \(startDateComponents) to a valid date.") diff --git a/Stronger/Account/Weight.swift b/Stronger/Account/Weight.swift index ee7972d..1f4c4bc 100644 --- a/Stronger/Account/Weight.swift +++ b/Stronger/Account/Weight.swift @@ -64,7 +64,7 @@ extension WeightKey { public var body: some View { HStack { - Text(WeightKey.name) + Text("\(WeightKey.name): lbs") Spacer() Button(action: { showAlert.toggle() // Toggle alert visibility @@ -81,7 +81,7 @@ extension WeightKey { ) } - TextField("Weight", value: $weight, formatter: NumberFormatter()) + TextField("Weight: lbs", value: $weight, formatter: NumberFormatter()) .frame(width: 120) // set frame width to enable more spaces. } } diff --git a/Stronger/Exercise/WorkoutHome.swift b/Stronger/Exercise/WorkoutHome.swift index 13a5244..edfe95e 100644 --- a/Stronger/Exercise/WorkoutHome.swift +++ b/Stronger/Exercise/WorkoutHome.swift @@ -56,8 +56,8 @@ struct WorkoutHome: View { NavigationLink( destination: WorkoutSelections( presentingAccount: $presentingAccount, - selectedWeek: selectedWeek, - selectedDay: selectedDay + selectedWeek: selectedWeek + 1, + selectedDay: selectedDay + 1 ) ) { Text("Enter Workout Information\n for Week \(selectedWeek + 1) Day \(selectedDay + 1).") diff --git a/Stronger/Exercise/WorkoutSelection.swift b/Stronger/Exercise/WorkoutSelection.swift index c95b634..d333b1f 100644 --- a/Stronger/Exercise/WorkoutSelection.swift +++ b/Stronger/Exercise/WorkoutSelection.swift @@ -160,20 +160,6 @@ struct WorkoutSelection: View { // Ensure the width does not exceed the screen width return min(desiredWidth, geometry.size.width * 0.5) // Set width as 50% of screen width } -// private func adjustSelectedWeek(_ week: Int) -> Int { -// switch week { -// case 1...3: -// return 1 -// case 4...6: -// return 4 -// case 7...9: -// return 7 -// case 10...12: -// return 10 -// default: -// return week // Return the original value for any other cases -// } -// } private func parseExercises(week: Int, day: Int) -> Workout? { // Get the URL of the JSON file in the app bundle @@ -255,6 +241,19 @@ struct WorkoutSelection: View { } } + private func populateUniqueValuesSet(from documents: [QueryDocumentSnapshot] = []) -> Set { + var uniqueValuesSet = Set() + + // Iterate over documents to populate the set + documents.forEach { document in + if let exercise = document["exercise"] as? String { + uniqueValuesSet.insert(exercise) + } + } + + return uniqueValuesSet + } + private func updateExerciseDate() async throws { // Get current user ID guard let userID = try await getCurrentUserID() else { @@ -266,14 +265,18 @@ struct WorkoutSelection: View { let dbe = Firestore.firestore() let userDocRef = dbe.collection("users").document(userID).collection("exerciseLog") - let query = userDocRef.whereField("week", isEqualTo: self.selectedWeek) + let query = userDocRef.whereField("week", isEqualTo: self.selectedWeek ?? 1) query.getDocuments { querySnapshot, error in if let error = error { print("Error fetching documents: \(error)") } else { + guard let querySnapshot = querySnapshot else { + print("querySnapshot is nil") + return + } // Get the count of documents - let documentCount = querySnapshot?.documents.count ?? 0 + let documentCount = querySnapshot.documents.count print("Number of documents returned: \(documentCount)") @@ -283,14 +286,16 @@ struct WorkoutSelection: View { self.selectedDay = 1 } else { // Check if there are documents with selectedDay equal to 1 - let selectedDay1Count = querySnapshot?.documents.filter { $0["exerciseDay"] as? Int == 2 }.count ?? 0 - if selectedDay1Count > 3 { + let selectedDay2Count = populateUniqueValuesSet(from: querySnapshot.documents.filter { $0["exerciseDay"] as? Int == 2 }).count + if selectedDay2Count > 3 { print("Documents found with selectedDay equal to 2. Setting selectedDay to 3.") self.selectedDay = 3 } else { // Check if there are documents with selectedDay equal to 2 - let selectedDay2Count = querySnapshot?.documents.filter { $0["exerciseDay"] as? Int == 1 }.count ?? 0 - if selectedDay2Count > 3 { + let selectedDay1Count = populateUniqueValuesSet( + from: querySnapshot.documents.filter { $0["exerciseDay"] as? Int == 1 } + ).count + if selectedDay1Count > 3 { print("Documents found with selectedDay equal to 1. Setting selectedDay to 2.") self.selectedDay = 2 } else { @@ -313,54 +318,11 @@ struct WorkoutSelection: View { return details.accountId } -// private func calculateWeeksElapsed(completion: @escaping (Int) -> Void) { -// // Get current user ID -// guard let userID = try await getCurrentUserID() else { -// completion(1) // Return default value if user ID cannot be retrieved -// return -// } -// -// // Reference to Firestore database -// let dbe = Firestore.firestore() -// -// // Reference to document for current user -// let userDocRef = dbe.collection("users").document(userID) -// -// // Get snapshot of document -// userDocRef.getDocument { userDocSnapshot, error in -// guard let userData = userDocSnapshot?.data(), -// let startDayTimestamp = userData["StartDateKey"] as? Timestamp else { -// print("Error retrieving start day timestamp:", error?.localizedDescription ?? "Unknown error") -// completion(1) // Return default value if start day timestamp cannot be retrieved -// return -// } -// -// // Get start date from Timestamp -// var startDayDate = startDayTimestamp.dateValue() -// -// // Get current date -// let currentDate = Date() -// -// // Get Calendar instance -// let calendar = Calendar.current -// -// // Move start day to closest Monday -// let weekday = calendar.component(.weekday, from: startDayDate) -// let daysToMonday = (7 - weekday + 2) % 7 // +2 because Sunday is 1-based in `weekday` but we want Monday to be 0-based -// startDayDate = calendar.date(byAdding: .day, value: -daysToMonday, to: startDayDate) ?? startDayDate -// -// // Calculate difference in weeks between start day and current date -// let weeksElapsed = calendar.dateComponents([.weekOfYear], from: startDayDate, to: currentDate).weekOfYear ?? 0 -// let roundedWeeksElapsed = max(weeksElapsed, 0) // Ensure weeksElapsed is non-negative -// completion(roundedWeeksElapsed) -// } -// } - // Function to retrieve start day field and calculate weeks elapsed - private func calculateWeeksElapsed() async throws -> Int { + private func calculateWeeksElapsed() async throws -> Int? { // Get current user ID guard let userID = try await getCurrentUserID() else { - return 1 + return nil } // Reference to Firestore database @@ -375,13 +337,12 @@ struct WorkoutSelection: View { // Check if document exists and contains start day field guard let userData = userDocSnapshot.data(), let startDayTimestamp = userData["StartDateKey"] as? Timestamp else { - print("did not find start day key", userID) - return 1 - } - - print("Found start date key", userID) + return nil + } + // Get start date from Timestamp - var startDayDate = startDayTimestamp.dateValue() + // Adjust time zones apparently + var startDayDate = startDayTimestamp.dateValue().addingTimeInterval(TimeInterval(TimeZone.current.secondsFromGMT())) // Get current date let currentDate = Date() @@ -390,37 +351,17 @@ struct WorkoutSelection: View { let calendar = Calendar.current // Move start day to closest Monday - let weekday = calendar.component(.weekday, from: startDayDate) - let daysToMonday = (7 - weekday + 2) % 7 // +2 because Sunday is 1-based in `weekday` but we want Monday to be 0-based - print("daysTOMonday \(daysToMonday)") - startDayDate = calendar.date(byAdding: .day, value: -daysToMonday, to: startDayDate) ?? startDayDate - print("startDayDate \(startDayDate)") - + // If startDayDate is Monday, keep it as is, otherwise move it to the previous Monday + if calendar.component(.weekday, from: startDayDate) != 2 { + // Calculate days to Monday + let weekday = calendar.component(.weekday, from: startDayDate) + let daysToMonday = (weekday - 2) % 7 + startDayDate = calendar.date(byAdding: .day, value: -daysToMonday, to: startDayDate) ?? startDayDate + } // Calculate difference in weeks between start day and current date let weeksElapsed = calendar.dateComponents([.weekOfYear], from: startDayDate, to: currentDate).weekOfYear ?? 0 - print("weeksElapsed \(weeksElapsed)") let roundedWeeksElapsed = weeksElapsed > 0 ? weeksElapsed : 0 // Ensure weeksElapsed is non-negative - print("rounded weeks elapsed \(roundedWeeksElapsed)") - return weeksElapsed - } - - private func uploadUserData() { - let dbe = Firestore.firestore() - - // Data to be uploaded - let userData: [String: Any] = [ - "name": "Rohan Gondor", - "role": "admin" - ] - - // Upload data to Firestore - dbe.collection("users").document("admin").setData(userData) { error in - if let error = error { - print("Error uploading user data: \(error.localizedDescription)") - } else { - print("User data uploaded successfully!") - } - } + return weeksElapsed + 1 // as we are using 1 based for selected week. } } diff --git a/Stronger/Exercise/WorkoutSelections.swift b/Stronger/Exercise/WorkoutSelections.swift index bba6056..fd9f044 100644 --- a/Stronger/Exercise/WorkoutSelections.swift +++ b/Stronger/Exercise/WorkoutSelections.swift @@ -22,8 +22,8 @@ struct WorkoutSelections: View { } @State private var menuItems: [MenuItem] = [] @Binding var presentingAccount: Bool - @State var selectedWeek: Int? - @State var selectedDay: Int? + @State var selectedWeek: Int + @State var selectedDay: Int @State private var geometry: CGSize = .zero @Environment(Account.self) var account @@ -75,8 +75,8 @@ struct WorkoutSelections: View { presentingAccount: $presentingAccount, item: menuItem.title, totalWidth: widthForMenuItems(in: geometry), - selectedWeek: selectedWeek ?? 1, - selectedDay: selectedDay ?? 1 + selectedWeek: selectedWeek, + selectedDay: selectedDay ) } @@ -101,17 +101,14 @@ struct WorkoutSelections: View { } } - init(presentingAccount: Binding, selectedWeek: Int?, selectedDay: Int?) { + init(presentingAccount: Binding, selectedWeek: Int, selectedDay: Int) { self._presentingAccount = presentingAccount self.selectedWeek = selectedWeek self.selectedDay = selectedDay } private func onAppearFunc() async throws { - selectedWeek = try? await calculateWeeksElapsed() - print("Selected Week: \(selectedWeek ?? 1)") - try await updateExerciseDate() - if let exercises = parseExercises(week: selectedWeek ?? 1, day: selectedDay ?? 1) { + if let exercises = parseExercises(week: selectedWeek, day: selectedDay) { buildMenuItem(workoutInst: exercises) } else { print("Error: Unable to parse exercises for the selected week and day.") @@ -202,8 +199,8 @@ struct WorkoutSelections: View { view: WorkoutInputForm( workoutName: exercise, presentingAccount: $presentingAccount, - selectedWeek: selectedWeek ?? 1, - selectedDay: selectedDay ?? 1 + selectedWeek: selectedWeek, + selectedDay: selectedDay ), title: exercise, video: video @@ -212,54 +209,6 @@ struct WorkoutSelections: View { } } - private func updateExerciseDate() async throws { - // Get current user ID - guard let userID = try await getCurrentUserID() else { - print("Error getting user id") - return - } - - // Reference to Firestore database - let dbe = Firestore.firestore() - - let userDocRef = dbe.collection("users").document(userID).collection("exerciseLog") - let query = userDocRef.whereField("week", isEqualTo: self.selectedWeek) - - query.getDocuments { querySnapshot, error in - if let error = error { - print("Error fetching documents: \(error)") - } else { - // Get the count of documents - let documentCount = querySnapshot?.documents.count ?? 0 - - // Check if there are no documents - if documentCount == 0 { - print("No documents found. Setting selectedDay to 1.") - selectedDay = 1 - } else { - // Check if there are documents with selectedDay equal to 1 - let selectedDay1Count = querySnapshot?.documents.filter { $0["exerciseDay"] as? Int == 2 }.count ?? 0 - if selectedDay1Count > 3 { - print("Documents found with selectedDay equal to 2. Setting selectedDay to 3.") - selectedDay = 3 - } else { - // Check if there are documents with selectedDay equal to 2 - let selectedDay2Count = querySnapshot?.documents.filter { $0["exerciseDay"] as? Int == 1 }.count ?? 0 - if selectedDay2Count > 3 { - print("Documents found with selectedDay equal to 1. Setting selectedDay to 2.") - selectedDay = 2 - } else { - // If no documents have selectedDay equal to 1 or 2, set selectedDay to 1 - print("No documents found with selectedDay equal to 1 or 2. Setting selectedDay to 1.") - selectedDay = 1 - } - } - } - } - } - } - - // Function to get the current user ID private func getCurrentUserID() async throws -> String? { guard let details = try? await account.details else { @@ -267,73 +216,6 @@ struct WorkoutSelections: View { } return details.accountId } - - // Function to retrieve start day field and calculate weeks elapsed - private func calculateWeeksElapsed() async throws -> Int { - // Get current user ID - guard let userID = try await getCurrentUserID() else { - return 1 - } - - // Reference to Firestore database - let dbe = Firestore.firestore() - - // Reference to document for current user - let userDocRef = dbe.collection("users").document(userID) - - // Get snapshot of document - let userDocSnapshot = try await userDocRef.getDocument() - - // Check if document exists and contains start day field - guard let userData = userDocSnapshot.data(), - let startDayTimestamp = userData["StartDateKey"] as? Timestamp else { - print("did not find start day key", userID) - return 1 - } - - print("Found start date key", userID) - // Get start date from Timestamp - var startDayDate = startDayTimestamp.dateValue() - - // Get current date - let currentDate = Date() - - // Get Calendar instance - let calendar = Calendar.current - - // Move start day to closest Monday - let weekday = calendar.component(.weekday, from: startDayDate) - let daysToMonday = (7 - weekday + 2) % 7 // +2 because Sunday is 1-based in `weekday` but we want Monday to be 0-based - print("daysTOMonday \(daysToMonday)") - startDayDate = calendar.date(byAdding: .day, value: -daysToMonday, to: startDayDate) ?? startDayDate - print("startDayDate \(startDayDate)") - - // Calculate difference in weeks between start day and current date - let weeksElapsed = calendar.dateComponents([.weekOfYear], from: startDayDate, to: currentDate).weekOfYear ?? 0 - print("weeksElapsed \(weeksElapsed)") - let roundedWeeksElapsed = weeksElapsed > 0 ? weeksElapsed : 0 // Ensure weeksElapsed is non-negative - print("rounded weeks elapsed \(roundedWeeksElapsed)") - return weeksElapsed - } - - private func uploadUserData() { - let dbe = Firestore.firestore() - - // Data to be uploaded - let userData: [String: Any] = [ - "name": "Rohan Gondor", - "role": "admin" - ] - - // Upload data to Firestore - dbe.collection("users").document("admin").setData(userData) { error in - if let error = error { - print("Error uploading user data: \(error.localizedDescription)") - } else { - print("User data uploaded successfully!") - } - } - } } struct Preview: PreviewProvider { diff --git a/Stronger/Info/ExerciseWeek.swift b/Stronger/Info/ExerciseWeek.swift index 77d1120..4f6ad5c 100644 --- a/Stronger/Info/ExerciseWeek.swift +++ b/Stronger/Info/ExerciseWeek.swift @@ -117,52 +117,6 @@ struct ExerciseWeek: View { } } - -// // Function to retrieve start day field and calculate weeks elapsed -// private func calculateWeeksElapsed() async throws -> Int? { -// // Get current user ID -// guard let userID = try await getCurrentUserID() else { -// return nil -// } -// -// // Reference to Firestore database -// let dbe = Firestore.firestore() -// -// // Reference to document for current user -// let userDocRef = dbe.collection("users").document(userID) -// -// // Get snapshot of document -// let userDocSnapshot = try await userDocRef.getDocument() -// -// // Check if document exists and contains start day field -// guard let userData = userDocSnapshot.data(), -// let startDayTimestamp = userData["StartDateKey"] as? Timestamp else { -// print("did not find start day key", userID) -// return nil -// } -// -// print("Found start date key", userID) -// // Get start date from Timestamp -// var startDayDate = startDayTimestamp.dateValue() -// -// // Get current date -// let currentDate = Date() -// -// // Get Calendar instance -// let calendar = Calendar.current -// -// // Move start day to closest Monday -// let weekday = calendar.component(.weekday, from: startDayDate) -// let daysToMonday = (7 - weekday + 2) % 7 // +2 because Sunday is 1-based in `weekday` but we want Monday to be 0-based -// startDayDate = calendar.date(byAdding: .day, value: -daysToMonday, to: startDayDate) ?? startDayDate -// -// -// // Calculate difference in weeks between start day and current date -// let weeksElapsed = calendar.dateComponents([.weekOfYear], from: startDayDate, to: currentDate).weekOfYear ?? 0 -// let roundedWeeksElapsed = weeksElapsed > 0 ? weeksElapsed : 0 // Ensure weeksElapsed is non-negative -// -// return weeksElapsed -// } // Function to process queried documents and calculate average difficulty private func processDocuments(_ documents: [QueryDocumentSnapshot], forWeek week: Int, andDay day: Int) async throws { @@ -206,15 +160,15 @@ struct ExerciseWeek: View { let averageDifficulty = averageDifficulties[button - 1] print("button: \(button), averageDifficulty: \(averageDifficulty)") switch averageDifficulty { - case 0..<1: + case 0..<1.01: dayOne = button == 1 ? "Easy" : dayOne dayTwo = button == 2 ? "Easy" : dayTwo dayThree = button == 3 ? "Easy" : dayThree - case 1..<2: + case 1.01..<2.01: dayOne = button == 1 ? "Medium" : dayOne dayTwo = button == 2 ? "Medium" : dayTwo dayThree = button == 3 ? "Medium" : dayThree - case 2..<3: + case 2.01..<4: dayOne = button == 1 ? "Hard" : dayOne dayTwo = button == 2 ? "Hard" : dayTwo dayThree = button == 3 ? "Hard" : dayThree diff --git a/Stronger/Info/SummaryView.swift b/Stronger/Info/SummaryView.swift index 5f9ffc1..7d0cb94 100644 --- a/Stronger/Info/SummaryView.swift +++ b/Stronger/Info/SummaryView.swift @@ -56,9 +56,11 @@ struct SummaryView: View { ExerciseWeek(value: selectedWeek ?? 3, presentingAccount: $presentingAccount, difficulty: "Hard") .padding(.bottom, 20) Spacer() - Text("Last Week's Fitness Progress\n") - .padding(.top, 10) - ExerciseWeek(value: (selectedWeek ?? 1) - 1, presentingAccount: $presentingAccount, difficulty: "Medium") + if selectedWeek != 1 { + Text("Last Week's Fitness Progress\n") + .padding(.top, 10) + ExerciseWeek(value: (selectedWeek ?? 1) - 1, presentingAccount: $presentingAccount, difficulty: "Medium") + } } .onAppear { Task { @@ -115,13 +117,12 @@ struct SummaryView: View { // Check if document exists and contains start day field guard let userData = userDocSnapshot.data(), let startDayTimestamp = userData["StartDateKey"] as? Timestamp else { - print("did not find start day key", userID) - return nil - } - - print("Found start date key", userID) + return nil + } + // Get start date from Timestamp - var startDayDate = startDayTimestamp.dateValue() + // Adjust time zones apparently + var startDayDate = startDayTimestamp.dateValue().addingTimeInterval(TimeInterval(TimeZone.current.secondsFromGMT())) // Get current date let currentDate = Date() @@ -130,18 +131,17 @@ struct SummaryView: View { let calendar = Calendar.current // Move start day to closest Monday - let weekday = calendar.component(.weekday, from: startDayDate) - let daysToMonday = (7 - weekday + 2) % 7 // +2 because Sunday is 1-based in `weekday` but we want Monday to be 0-based - print("daysTOMonday \(daysToMonday)") - startDayDate = calendar.date(byAdding: .day, value: -daysToMonday, to: startDayDate) ?? startDayDate - print("startDayDate \(startDayDate)") - + // If startDayDate is Monday, keep it as is, otherwise move it to the previous Monday + if calendar.component(.weekday, from: startDayDate) != 2 { + // Calculate days to Monday + let weekday = calendar.component(.weekday, from: startDayDate) + let daysToMonday = (weekday - 2) % 7 + startDayDate = calendar.date(byAdding: .day, value: -daysToMonday, to: startDayDate) ?? startDayDate + } // Calculate difference in weeks between start day and current date let weeksElapsed = calendar.dateComponents([.weekOfYear], from: startDayDate, to: currentDate).weekOfYear ?? 0 - print("weeksElapsed \(weeksElapsed)") let roundedWeeksElapsed = weeksElapsed > 0 ? weeksElapsed : 0 // Ensure weeksElapsed is non-negative - print("rounded weeks elapsed \(roundedWeeksElapsed)") - return weeksElapsed + return weeksElapsed + 1 // as we are using 1 based for selected week. } } diff --git a/Stronger/ProteinTracker/ChatWindow.swift b/Stronger/ProteinTracker/ChatWindow.swift index b9edc4b..533224b 100644 --- a/Stronger/ProteinTracker/ChatWindow.swift +++ b/Stronger/ProteinTracker/ChatWindow.swift @@ -19,7 +19,7 @@ import SpeziLLMOpenAI import SwiftUI func get_protein_content(for foodItem: String, defaultProtein: Double = 0.0) -> Double { - let apiKey = "jUBpE8JHsjp7aMjpvrauVMuLNdC3DR5pnvW18Lej" + let apiKey = "W03syDuGkdxiRoLFMPr9Yg==kg7WNYBWJUl9IBKt" let urlString = "https://api.api-ninjas.com/v1/nutrition?&query=\(foodItem)&x-api-key=\(apiKey)" guard let url = URL(string: urlString) else { diff --git a/Stronger/Resources/Localizable.xcstrings b/Stronger/Resources/Localizable.xcstrings index d835229..f4560d8 100644 --- a/Stronger/Resources/Localizable.xcstrings +++ b/Stronger/Resources/Localizable.xcstrings @@ -29,6 +29,12 @@ } } } + }, + "%@: inches" : { + + }, + "%@: lbs" : { + }, "%@." : { @@ -94,7 +100,14 @@ } }, "ADD_DATE" : { - + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Please Add Date" + } + } + } }, "Are you logging a new or saved meal?" : { @@ -824,18 +837,26 @@ }, "Weekly Stats" : { - }, - "Weight" : { - }, "WEIGHT" : { - + "extractionState" : "manual", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Weight" + } + } + } }, "Weight Information" : { }, "Weight is gathered to determine protein intake." : { + }, + "Weight: lbs" : { + }, "WELCOME_AREA1_DESCRIPTION" : { "localizations" : { diff --git a/Stronger/SharedContext/FeatureFlags.swift b/Stronger/SharedContext/FeatureFlags.swift index b484488..4284ead 100644 --- a/Stronger/SharedContext/FeatureFlags.swift +++ b/Stronger/SharedContext/FeatureFlags.swift @@ -16,7 +16,8 @@ enum FeatureFlags { static let disableFirebase = CommandLine.arguments.contains("--disableFirebase") #if targetEnvironment(simulator) /// Defines if the application should connect to the local firebase emulator. Always set to true when using the iOS simulator. - static let useFirebaseEmulator = CommandLine.arguments.contains("--useFirebaseEmulator") + static let useFirebaseEmulator = true + // static let useFirebaseEmulator = CommandLine.arguments.contains("--useFirebaseEmulator") #else /// Defines if the application should connect to the local firebase emulator. Always set to true when using the iOS simulator. static let useFirebaseEmulator = CommandLine.arguments.contains("--useFirebaseEmulator") diff --git a/StrongerUITests/MissedWorkoutTest.swift b/StrongerUITests/MissedWorkoutTest.swift new file mode 100644 index 0000000..4305451 --- /dev/null +++ b/StrongerUITests/MissedWorkoutTest.swift @@ -0,0 +1,39 @@ +//// +//// This source file is part of the Stronger based on the Stanford Spezi Template Application project +//// +//// SPDX-FileCopyrightText: 2023 Stanford University +//// +//// SPDX-License-Identifier: MIT +//// +// +// import XCTest +// +// +// class MissedWorkoutTests: XCTestCase { +// override func setUpWithError() throws { +// try super.setUpWithError() +// +// continueAfterFailure = false +// +// let app = XCUIApplication() +// app.launchArguments = ["--skipOnboarding"] +// app.launch() +// } +// +// +// func testApplicationMissedWorkouts() throws { +// let app = XCUIApplication() +// XCTAssertEqual(app.state, .runningForeground) +// +// XCTAssertTrue(app.tabBars["Tab Bar"].buttons["Workout"].waitForExistence(timeout: 2)) +// app.tabBars["Tab Bar"].buttons["Workout"].tap() +// +// XCTAssertTrue(app.buttons["Enter Missed Workout"].waitForExistence(timeout: 2)) +// app.buttons["Enter Missed Workout"].tap() +// +// +// XCTAssertTrue(app.buttons["Week 1"].waitForExistence(timeout: 2)) +// app.buttons["Week1 1"].tap() +// XCTAssertTrue(app.buttons["Week 1"].waitForExistence(timeout: 2)) +// } +// }