generated from StanfordSpezi/SpeziTemplateApplication
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cough Report ## ♻️ Current situation & Problem The current app is lacking a cough report to provide trend summaries and insights for both user and doctors. This implements a new tab to view weekly monthly changes in cough with a graph interface to view cough frequency. ## ⚙️ Release Notes - Created daily, monthly, and weekly cough report cards - Increase/decrease in cough, peak times in coughs - Added button to view graph trends of daily weekly monthly coughs *Note: Currently uses fake cough data ## ✅ Testing N/A ## 📝 Code of Conduct & Contributing Guidelines By submitting creating this pull request, you agree to follow our [Code of Conduct](https://github.com/CS342/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/CS342/.github/blob/main/CONTRIBUTING.md): - [x] I agree to follow the [Code of Conduct](https://github.com/CS342/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/CS342/.github/blob/main/CONTRIBUTING.md). --------- Co-authored-by: MiguelAFH <[email protected]>
- Loading branch information
Showing
9 changed files
with
271 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// This source file is part of the CoughSync based on the Stanford Spezi Template Application project | ||
// | ||
// SPDX-FileCopyrightText: 2025 Stanford University | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import Foundation | ||
|
||
enum CoughReportData { | ||
// Fake data for now (replace with actual logic later) | ||
static func getDailyCoughs() -> [Int] { | ||
(0..<7).map { _ in Int.random(in: 10...50) } // 7 days of cough counts | ||
} | ||
|
||
static func getWeeklyCoughs() -> [Int] { | ||
(0..<4).map { _ in Int.random(in: 50...200) } // 4 weeks of cough counts | ||
} | ||
|
||
static func getMonthlyCoughs() -> [Int] { | ||
(0..<12).map { _ in Int.random(in: 200...800) } // 12 months of cough counts | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// This source file is part of the CoughSync based on the Stanford Spezi Template Application project | ||
// | ||
// SPDX-FileCopyrightText: 2025 Stanford University | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import Charts | ||
import SwiftUI | ||
|
||
struct FrequencyView: View { | ||
let dailyCoughs = CoughReportData.getDailyCoughs() | ||
let weeklyCoughs = CoughReportData.getWeeklyCoughs() | ||
let monthlyCoughs = CoughReportData.getMonthlyCoughs() | ||
|
||
var body: some View { | ||
NavigationStack { | ||
GeometryReader { geometry in | ||
ScrollView { | ||
VStack(spacing: 15) { | ||
Text("Cough Trends") | ||
.font(.largeTitle.bold()) | ||
.padding(.top) | ||
|
||
CoughTrendChart( | ||
title: "Daily Coughs (Past Week)", | ||
data: dailyCoughs, | ||
xLabels: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"], | ||
chartHeight: geometry.size.height * 0.3 // Limits chart height | ||
) | ||
|
||
CoughTrendChart( | ||
title: "Weekly Coughs (Past Month)", | ||
data: weeklyCoughs, | ||
xLabels: ["Week 1", "Week 2", "Week 3", "Week 4"], | ||
chartHeight: geometry.size.height * 0.3 | ||
) | ||
|
||
CoughTrendChart( | ||
title: "Monthly Coughs (Past Year)", | ||
data: monthlyCoughs, | ||
xLabels: [ | ||
"Jan", "Feb", "Mar", "Apr", "May", "Jun", | ||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" | ||
], | ||
chartHeight: geometry.size.height * 0.3 | ||
) | ||
} | ||
.padding() | ||
} | ||
.safeAreaInset(edge: .bottom) { Color.clear.frame(height: 60) } // Prevents tab bar overlap | ||
} | ||
.navigationBarTitleDisplayMode(.inline) | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
FrequencyView() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// This source file is part of the CoughSync based on the Stanford Spezi Template Application project | ||
// | ||
// SPDX-FileCopyrightText: 2025 Stanford University | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
// ReportCard.swift | ||
// CoughSync | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct ReportCard: View { | ||
let title: String | ||
let percentage: Double | ||
let peakTime: String | ||
|
||
private var percentageText: String { | ||
percentage >= 0 ? "+\(String(format: "%.1f", percentage))%" : "\(String(format: "%.1f", percentage))%" | ||
} | ||
|
||
private var percentageColor: Color { | ||
percentage >= 0 ? .orange : .blue | ||
} | ||
|
||
var body: some View { | ||
VStack(alignment: .leading, spacing: 10) { | ||
Text(title) | ||
.font(.title2.bold()) | ||
.foregroundColor(.primary) | ||
|
||
HStack { | ||
Text("Coughs Change: ") | ||
.foregroundColor(.primary) | ||
Text(percentageText) | ||
.fontWeight(.bold) | ||
.foregroundColor(percentageColor) | ||
} | ||
|
||
HStack { | ||
Image(systemName: "clock.fill") | ||
.foregroundColor(.gray) | ||
.accessibilityLabel("Clock icon") | ||
Text("Peak Time: \(peakTime)") | ||
.font(.body) | ||
.foregroundColor(.primary) | ||
} | ||
} | ||
.padding() | ||
.frame(maxWidth: .infinity, alignment: .leading) | ||
.background(RoundedRectangle(cornerRadius: 14).fill(.ultraThinMaterial)) | ||
|
||
.padding(.horizontal) | ||
} | ||
} | ||
|
||
#Preview { | ||
ReportCard(title: "Daily Report", percentage: 12.5, peakTime: "8:00 PM - 10:00 PM") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// This source file is part of the CoughSync based on the Stanford Spezi Template Application project | ||
// | ||
// SPDX-FileCopyrightText: 2025 Stanford University | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct CoughReportView: View { | ||
var body: some View { | ||
NavigationStack { | ||
VStack(spacing: 20) { | ||
Text("Cough Report") | ||
.font(.largeTitle.bold()) | ||
|
||
ScrollView { | ||
VStack(spacing: 15) { | ||
ReportCard(title: "Daily Report", percentage: 12.5, peakTime: "8:00 PM - 10:00 PM") | ||
ReportCard(title: "Weekly Report", percentage: -8.3, peakTime: "Wednesday 9:00 AM - 11:00 AM") | ||
ReportCard(title: "Monthly Report", percentage: 5.2, peakTime: "January 15 at 7:00 PM - 9:00 PM") | ||
|
||
NavigationLink(destination: FrequencyView()) { | ||
Text("View Cough Frequency Trends →") | ||
.font(.headline) | ||
.foregroundColor(.blue) | ||
} | ||
.padding(.top, 10) | ||
} | ||
.padding() | ||
} | ||
} | ||
.navigationBarTitleDisplayMode(.inline) | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
CoughReportView() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// This source file is part of the CoughSync based on the Stanford Spezi Template Application project | ||
// | ||
// SPDX-FileCopyrightText: 2025 Stanford University | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import Charts | ||
import SwiftUI | ||
|
||
|
||
struct CoughTrendChart: View { | ||
let title: String | ||
let data: [Int] | ||
let xLabels: [String] | ||
let chartHeight: CGFloat // New parameter for dynamic height | ||
|
||
var body: some View { | ||
VStack(alignment: .leading, spacing: 10) { | ||
Text(title) | ||
.font(.title2.bold()) | ||
|
||
Chart { | ||
ForEach(Array(data.enumerated()), id: \.offset) { index, value in | ||
LineMark( | ||
x: .value("Time", xLabels[index]), | ||
y: .value("Coughs", value) | ||
) | ||
.interpolationMethod(.catmullRom) | ||
.foregroundStyle(.blue) | ||
} | ||
} | ||
.frame(height: chartHeight) // Use dynamic height | ||
.chartYAxis { | ||
AxisMarks(position: .leading) | ||
} | ||
} | ||
.padding() | ||
.background(RoundedRectangle(cornerRadius: 14).fill(.ultraThinMaterial)) | ||
.padding(.horizontal) | ||
} | ||
} | ||
|
||
#Preview { | ||
CoughTrendChart( | ||
title: "Daily Coughs (Past Week)", | ||
data: [10, 20, 30, 40, 50, 30, 20], | ||
xLabels: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"], | ||
chartHeight: 200 | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters