Skip to content

Commit ec60226

Browse files
authored
Merge branch 'main' into jiayu-chang/delete-LLM-memory-limit
2 parents ba85793 + 1bcc8d0 commit ec60226

File tree

11 files changed

+102
-95
lines changed

11 files changed

+102
-95
lines changed

Stanford360.xcodeproj/project.pbxproj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
2FE5DCB129EE6107004B9AB4 /* AccountOnboarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FE5DCAC29EE6107004B9AB4 /* AccountOnboarding.swift */; };
5151
2FF53D8D2A8729D600042B76 /* Stanford360Standard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FF53D8C2A8729D600042B76 /* Stanford360Standard.swift */; };
5252
45E038232D503C0F009D07E2 /* HydrationViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45E038222D503BFA009D07E2 /* HydrationViewTests.swift */; };
53-
45E2EB9D2D7F059A0097C339 /* HydrationManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45E2EB9C2D7F05910097C339 /* HydrationManagerTests.swift */; };
5453
4D2965D82D7A8084000664B4 /* SpeziLLM in Frameworks */ = {isa = PBXBuildFile; productRef = 4D2965D72D7A8084000664B4 /* SpeziLLM */; };
5554
4D2965DA2D7A8084000664B4 /* SpeziLLMFog in Frameworks */ = {isa = PBXBuildFile; productRef = 4D2965D92D7A8084000664B4 /* SpeziLLMFog */; };
5655
4D2965DC2D7A8084000664B4 /* SpeziLLMLocal in Frameworks */ = {isa = PBXBuildFile; productRef = 4D2965DB2D7A8084000664B4 /* SpeziLLMLocal */; };
@@ -138,7 +137,6 @@
138137
2FE5DCAC29EE6107004B9AB4 /* AccountOnboarding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountOnboarding.swift; sourceTree = "<group>"; };
139138
2FF53D8C2A8729D600042B76 /* Stanford360Standard.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Stanford360Standard.swift; sourceTree = "<group>"; };
140139
45E038222D503BFA009D07E2 /* HydrationViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HydrationViewTests.swift; sourceTree = "<group>"; };
141-
45E2EB9C2D7F05910097C339 /* HydrationManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HydrationManagerTests.swift; sourceTree = "<group>"; };
142140
4FC5EF032D78162800BFDFFD /* KidsOnboarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KidsOnboarding.swift; sourceTree = "<group>"; };
143141
4FCAD0582D5AAD20007324A6 /* ActivityViewUITest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActivityViewUITest.swift; sourceTree = "<group>"; };
144142
5680DD3D2AB8CD84004E6D4A /* ContributionsTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContributionsTest.swift; sourceTree = "<group>"; };
@@ -167,6 +165,7 @@
167165
/* End PBXFileReference section */
168166

169167
/* Begin PBXFileSystemSynchronizedRootGroup section */
168+
45E2F0FC2D82132B0097C339 /* HydrationTests */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = HydrationTests; sourceTree = "<group>"; };
170169
4DB472D62D80459F005E895E /* ProteinTest */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = ProteinTest; sourceTree = "<group>"; };
171170
4F8EA0B92D680A4400A94137 /* Activity */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = Activity; sourceTree = "<group>"; };
172171
4FF18DDD2D5FAB5E00E13832 /* ActivityTests */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = ActivityTests; sourceTree = "<group>"; };
@@ -354,7 +353,7 @@
354353
653A256028338800005D4D48 /* Stanford360Tests */ = {
355354
isa = PBXGroup;
356355
children = (
357-
45E2EB9C2D7F05910097C339 /* HydrationManagerTests.swift */,
356+
45E2F0FC2D82132B0097C339 /* HydrationTests */,
358357
4DB472D62D80459F005E895E /* ProteinTest */,
359358
4FF18DDD2D5FAB5E00E13832 /* ActivityTests */,
360359
653A256128338800005D4D48 /* Stanford360Tests.swift */,
@@ -490,6 +489,7 @@
490489
653A255F28338800005D4D48 /* PBXTargetDependency */,
491490
);
492491
fileSystemSynchronizedGroups = (
492+
45E2F0FC2D82132B0097C339 /* HydrationTests */,
493493
4DB472D62D80459F005E895E /* ProteinTest */,
494494
4FF18DDD2D5FAB5E00E13832 /* ActivityTests */,
495495
);
@@ -666,7 +666,6 @@
666666
buildActionMask = 2147483647;
667667
files = (
668668
653A256228338800005D4D48 /* Stanford360Tests.swift in Sources */,
669-
45E2EB9D2D7F059A0097C339 /* HydrationManagerTests.swift in Sources */,
670669
);
671670
runOnlyForDeploymentPostprocessing = 0;
672671
};

Stanford360/Activity/Model/ActivityManager.swift

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,29 @@ class ActivityManager: Module, EnvironmentAccessible {
3030
return activitiesByDate
3131
}
3232

33-
// Streak Calculation
3433
var streak: Int {
3534
let calendar = Calendar.current
3635
var streakCount = 0
37-
var currentDate = Date()
36+
var currentDate = calendar.date(byAdding: .day, value: -1, to: Date()) ?? Date()
3837

39-
while let activitiesForDate = activitiesByDate[calendar.startOfDay(for: currentDate)] {
40-
let totalMinutes = getTotalActivityMinutes(activitiesForDate)
41-
if totalMinutes >= 60 {
38+
let todayIntake = getTotalActivityMinutes(activitiesByDate[calendar.startOfDay(for: Date())] ?? [])
39+
let isTodayQualified = todayIntake >= 60
40+
41+
while true {
42+
let dailyIntake = getTotalActivityMinutes(activitiesByDate[calendar.startOfDay(for: currentDate)] ?? [])
43+
44+
if dailyIntake >= 60 {
4245
streakCount += 1
46+
guard let previousDate = calendar.date(byAdding: .day, value: -1, to: currentDate) else {
47+
break
48+
}
49+
currentDate = previousDate
4350
} else {
44-
break // Stop counting if the total minutes are not over 60
51+
break
4552
}
46-
// Move to the previous day
47-
currentDate = calendar.date(byAdding: .day, value: -1, to: currentDate) ?? currentDate
4853
}
4954

50-
return streakCount
55+
return isTodayQualified ? streakCount + 1 : streakCount
5156
}
5257

5358
// MARK: - Initialization
@@ -76,19 +81,6 @@ class ActivityManager: Module, EnvironmentAccessible {
7681
return milestoneManager.getLatestMilestone(total: totalIntake)
7782
}
7883

79-
/*
80-
func triggerMotivation() -> String {
81-
if getTodayTotalMinutes() >= 60 {
82-
return "🎉 Amazing! You've reached your daily goal of 60 minutes!"
83-
} else if getTodayTotalMinutes() > 0 {
84-
let remainingMinutes = 60 - getTodayTotalMinutes()
85-
return "Keep going! Only \(remainingMinutes) more minutes to reach today's goal! 🚀"
86-
} else {
87-
return "Start your activity today and move towards your goal! 💪"
88-
}
89-
}
90-
*/
91-
9284
func saveToStorage() {
9385
do {
9486
let data = try JSONEncoder().encode(activities)

Stanford360/Activity/View/AddActivitySheetView.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,14 @@ struct AddActivitySheet: View {
181181
let lastRecordedMilestone = activityManager.getLatestMilestone()
182182
activityManager.activities.append(newActivity)
183183
let activityMinutes = activityManager.getTodayTotalMinutes()
184+
let updatedStreak = activityManager.streak
184185
await standard.addActivityToFirestore(newActivity)
185186
await scheduler.handleNotificationsOnLoggedActivity(prevActivityMinutes: prevActivityMinutes, newActivityMinutes: activityMinutes)
186187
activityManager.milestoneManager.displayMilestoneMessage(
187188
newTotal: Double(activityManager.getTodayTotalMinutes()),
188189
lastMilestone: lastRecordedMilestone,
189-
unit: "minutes of activity"
190+
unit: "minutes of activity",
191+
streak: updatedStreak
190192
)
191193
}
192194

Stanford360/Hydration/Model/HydrationManager.swift

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,28 @@ class HydrationManager: Module, EnvironmentAccessible {
2424
}
2525

2626
var streak: Int {
27-
calculateStreak()
27+
let calendar = Calendar.current
28+
var streakCount = 0
29+
var currentDate = calendar.date(byAdding: .day, value: -1, to: Date()) ?? Date()
30+
31+
let todayIntake = getTotalHydrationOunces(hydrationByDate[calendar.startOfDay(for: Date())] ?? [])
32+
let isTodayQualified = todayIntake >= 60
33+
34+
while true {
35+
let dailyIntake = getTotalHydrationOunces(hydrationByDate[calendar.startOfDay(for: currentDate)] ?? [])
36+
37+
if dailyIntake >= 60 {
38+
streakCount += 1
39+
guard let previousDate = calendar.date(byAdding: .day, value: -1, to: currentDate) else {
40+
break
41+
}
42+
currentDate = previousDate
43+
} else {
44+
break
45+
}
46+
}
47+
48+
return isTodayQualified ? streakCount + 1 : streakCount
2849
}
2950

3051
init(hydration: [HydrationLog] = []) {
@@ -48,40 +69,6 @@ class HydrationManager: Module, EnvironmentAccessible {
4869
let totalIntake = getTodayTotalOunces()
4970
return milestoneManager.getLatestMilestone(total: totalIntake)
5071
}
51-
52-
/*
53-
func triggerMotivation() -> String {
54-
if getTodayTotalOunces() >= 60 {
55-
return "🎉 Amazing! You've reached your daily goal of 60 ounces!"
56-
} else if getTodayTotalOunces() > 0 {
57-
let remainingOunces = 60 - getTodayTotalOunces()
58-
return "Keep going! Only \(Int(remainingOunces)) more ounces to reach today's goal! 🚀"
59-
} else {
60-
return "Start your hydration today and move towards your goal! 💪"
61-
}
62-
}
63-
*/
64-
65-
func calculateStreak() -> Int {
66-
let calendar = Calendar.current
67-
var streakCount = 0
68-
var currentDate = calendar.startOfDay(for: Date())
69-
70-
while true {
71-
let dailyIntake = hydrationByDate[currentDate]?.reduce(0) { $0 + $1.hydrationOunces } ?? 0.0
72-
73-
if dailyIntake >= 60 {
74-
streakCount += 1
75-
guard let previousDate = calendar.date(byAdding: .day, value: -1, to: currentDate) else {
76-
break
77-
}
78-
currentDate = previousDate
79-
} else {
80-
break
81-
}
82-
}
83-
return streakCount
84-
}
8572

8673
func recallLastIntake() {
8774
let today = Calendar.current.startOfDay(for: Date())

Stanford360/Hydration/Model/HydrationScheduler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extension Stanford360Scheduler {
1919
try scheduler.createOrUpdateTask(
2020
id: "hydration-reminder",
2121
title: "💧 Stay Hydrated!",
22-
instructions: "You haven't logged any water intake in the last 4 hours. Drink up!",
22+
instructions: "It's been a while since you last logged water. Time to hydrate!",
2323
category: Task.Category(rawValue: "Hydration"),
2424
schedule: .daily(hour: 7, minute: 0, startingAt: .today), // First reminder at 7 AM
2525
scheduleNotifications: true

Stanford360/Hydration/View/HydrationControlPanel.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,16 @@ struct HydrationControlPanel: View {
9797
let hydrationLog = HydrationLog(hydrationOunces: amount, timestamp: Date())
9898
hydrationManager.hydration.append(hydrationLog)
9999
await standard.storeHydrationLog(hydrationLog)
100+
let updatedStreak = hydrationManager.streak
100101

101102
errorMessage = nil
102103
streak = hydrationManager.streak
103104
await scheduler.rescheduleHydrationNotifications()
104105
hydrationManager.milestoneManager.displayMilestoneMessage(
105106
newTotal: hydrationManager.getTodayTotalOunces(),
106107
lastMilestone: lastRecordedMilestone,
107-
unit: "oz of water"
108+
unit: "oz of water",
109+
streak: updatedStreak
108110
)
109111
selectedAmount = nil
110112
intakeAmount = ""

Stanford360/Protein/Model/ProteinManager.swift

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,29 @@ class ProteinManager: Module, EnvironmentAccessible {
2525
}
2626

2727

28-
// Streak Calculation
2928
var streak: Int {
3029
let calendar = Calendar.current
3130
var streakCount = 0
32-
var currentDate = Date()
31+
var currentDate = calendar.date(byAdding: .day, value: -1, to: Date()) ?? Date()
3332

34-
while let mealsByDate = mealsByDate[calendar.startOfDay(for: currentDate)] {
35-
let totalGrams = getTotalProteinGrams(mealsByDate)
36-
if totalGrams >= 60 {
33+
let todayIntake = getTotalProteinGrams(mealsByDate[calendar.startOfDay(for: Date())] ?? [])
34+
let isTodayQualified = todayIntake >= 60
35+
36+
while true {
37+
let dailyIntake = getTotalProteinGrams(mealsByDate[calendar.startOfDay(for: currentDate)] ?? [])
38+
39+
if dailyIntake >= 60 {
3740
streakCount += 1
41+
guard let previousDate = calendar.date(byAdding: .day, value: -1, to: currentDate) else {
42+
break
43+
}
44+
currentDate = previousDate
3845
} else {
39-
break // Stop counting if the total minutes are not over 60
46+
break
4047
}
41-
// Move to the previous day
42-
currentDate = calendar.date(byAdding: .day, value: -1, to: currentDate) ?? currentDate
4348
}
4449

45-
return streakCount
50+
return isTodayQualified ? streakCount + 1 : streakCount
4651
}
4752

4853
init(meals: [Meal] = []) {
@@ -68,20 +73,7 @@ class ProteinManager: Module, EnvironmentAccessible {
6873
let totalIntake = getTodayTotalGrams()
6974
return milestoneManager.getLatestMilestone(total: totalIntake)
7075
}
71-
72-
/*
73-
func triggerMotivation() -> String {
74-
if getTodayTotalGrams() >= 60 {
75-
return "🎉 Amazing! You've reached your daily goal of 60 grams!"
76-
} else if getTodayTotalGrams() > 0 {
77-
let remainingGrams = 60 - getTodayTotalGrams()
78-
return "Keep going! Only \(String(format: "%.f", remainingGrams)) more grams to reach today's goal! 🚀"
79-
} else {
80-
return "Eat your protein today and move towards your goal! 💪"
81-
}
82-
}
83-
*/
84-
76+
8577
// Add a new meal to the list
8678
// func addMeal(name: String, proteinGrams: Double, imageURL: String? = nil, timestamp: Date = Date()) {
8779
// let newMeal = Meal(name: name, proteinGrams: proteinGrams, imageURL: imageURL, timestamp: timestamp)

Stanford360/Protein/View/AddMealView.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,11 +392,13 @@ extension AddMealView {
392392
}
393393

394394
proteinManager.meals.append(meal)
395+
let updatedStreak = proteinManager.streak
395396
await standard.storeMeal(meal/*, selectedImage: selectedImage*/)
396397
proteinManager.milestoneManager.displayMilestoneMessage(
397398
newTotal: proteinManager.getTodayTotalGrams(),
398399
lastMilestone: lastRecordedMilestone,
399-
unit: "grams of protein"
400+
unit: "grams of protein",
401+
streak: updatedStreak
400402
)
401403
}
402404
}

Stanford360/Resources/Localizable.xcstrings

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,18 @@
333333
},
334334
"Hydration Recommendations" : {
335335

336+
},
337+
"image" : {
338+
339+
},
340+
"image" : {
341+
336342
},
337343
"image" : {
338344

345+
},
346+
"image" : {
347+
339348
},
340349
"Image Analysis Results:" : {
341350

@@ -826,9 +835,6 @@
826835
},
827836
"When did you do it?" : {
828837

829-
},
830-
"You haven't logged any water intake in the last 4 hours. Drink up!" : {
831-
832838
},
833839
"You need %@ %@ more to reach your goal!" : {
834840
"localizations" : {

Stanford360/Shared/Models/MilestoneManager.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class MilestoneManager: ObservableObject {
1818
newTotal: Double,
1919
lastMilestone: Double,
2020
unit: String,
21+
streak: Int,
2122
milestoneInterval: Double = 20,
2223
specialMilestone: Double = 60
2324
) -> (message: String?, isSpecial: Bool) {
@@ -26,7 +27,7 @@ class MilestoneManager: ObservableObject {
2627

2728
for milestone in stride(from: milestoneInterval, through: newTotal, by: milestoneInterval) where milestone > lastMilestone {
2829
if milestone == specialMilestone && lastMilestone < specialMilestone {
29-
latestMessage = "Amazing! You've reached \(Int(specialMilestone)) \(unit) today! Keep up the great work!"
30+
latestMessage = "Amazing! You've reached \(Int(specialMilestone)) \(unit) today! \(streak) days in a row! Keep it going!"
3031
isSpecial = true
3132
} else {
3233
latestMessage = "Great job! You've reached \(Int(milestone)) \(unit) today!"
@@ -42,13 +43,15 @@ class MilestoneManager: ObservableObject {
4243
newTotal: Double,
4344
lastMilestone: Double,
4445
unit: String,
46+
streak: Int,
4547
milestoneInterval: Double = 20,
4648
specialMilestone: Double = 60
4749
) {
4850
let milestoneData = checkMilestones(
4951
newTotal: newTotal,
5052
lastMilestone: lastMilestone,
5153
unit: unit,
54+
streak: streak,
5255
milestoneInterval: milestoneInterval,
5356
specialMilestone: specialMilestone
5457
)

0 commit comments

Comments
 (0)