Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graphdataconnection #39

Merged
merged 19 commits into from
Mar 9, 2025
Merged

Graphdataconnection #39

merged 19 commits into from
Mar 9, 2025

Conversation

aajain2
Copy link
Contributor

@aajain2 aajain2 commented Mar 8, 2025

Firebase <> UI Data Connections

♻️ Current situation & Problem

The CoughSync app currently displays hardcoded placeholder values rather than actual user cough data in both the Dashboard and Cough Tracker views. This prevents users from tracking their health metrics accurately and provides a misleading user experience. This PR connects these views to Firebase/Firestore to display real-time cough statistics and visual representations of cough patterns.

⚙️ Release Notes

  • Added Firebase integration for real-time cough metrics visualization across the app
  • Implemented today's cough count from Firestore data
  • Added weekly and monthly average coughs per day calculations for dashboard
  • Created hourly cough tracking chart for the current day
  • Added daily cough tracking chart showing the past 7 days of cough data
  • Implemented loading indicators and pull-to-refresh functionality
  • Enhanced error handling for network connectivity issues

Example usage:

// Fetching cough data for visualization
private func loadCoughData() {
    isLoadingData = true
    viewModel?.fetchCoughData { success in
        isLoadingData = false
        if !success {
            print("Failed to load cough data")
        }
    }
}

📚 Documentation

Our solution implements Firebase data integration for the CoughSync app using a clean architecture approach. All Firebase interactions are contained within the CoughSyncStandard class, with ViewModels serving as intermediaries between the data layer and UI.

We've added methods to CoughSyncStandard for fetching various types of cough data:

  • fetchTodayCoughCount() for current day totals
  • fetchWeeklyAverageCoughCount() for weekly averages
  • fetchMonthlyAverageCoughCount() for monthly averages
  • fetchCoughEventsInRange() for date-specific queries
  • Helper methods for date filtering and data aggregation

The CoughDetectionViewModel has been expanded to include properties for cough metrics and methods to retrieve data from Firebase. We've extended CoughCollection with resetCoughs() and setCount() methods to support data synchronization.

In addition to the Dashboard enhancements, we've implemented the Cough Tracker view with:

  1. An hourly chart showing today's cough distribution throughout the day
  2. A daily chart showing cough counts for the past 7 days
  3. Dynamic labels that update with the current data

✅ Testing

We've added comprehensive tests for the new functionality, including unit tests for:

  1. CoughCollection's reset and setCount methods
  2. CoughDetectionViewModel's data fetching capabilities
  3. The CoughEvent model creation and validation
  4. Date-based filtering for hourly and daily cough tracking
  5. Chart data generation for visualization components

Testing strategy includes:

  • Testing CoughCollection functionality with various counts and reset operations
  • Testing date-based filtering for different time granularities (hourly, daily, weekly)
  • Testing ViewModel property updates and data fetching with Firebase disabled
  • Testing chart data formatting and aggregation logic

All tests pass successfully with Firebase disabled for testing purposes. The implementation gracefully handles edge cases such as empty data sets and ensures loading states transition properly during data retrieval.

📝 Code of Conduct & Contributing Guidelines

By submitting creating this pull request, you agree to follow our Code of Conduct and Contributing Guidelines:

@aajain2 aajain2 requested a review from MiguelAFH March 8, 2025 19:18
Copy link
Contributor

@MiguelAFH MiguelAFH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look fine. Great work on the refresh data. We might need to take care of the refresh speed

Copy link

codecov bot commented Mar 8, 2025

Codecov Report

Attention: Patch coverage is 86.39706% with 37 lines in your changes missing coverage. Please review.

Project coverage is 68.07%. Comparing base (ad9f304) to head (c044e93).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
CoughSync/CoughSyncStandard.swift 78.69% 26 Missing ⚠️
...oughSync/CoughVisualization/CoughTrackerView.swift 91.23% 5 Missing ⚠️
CoughSync/CoughVisualization/CoughTracker.swift 77.78% 4 Missing ⚠️
CoughSync/Summary/SummaryView.swift 94.74% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #39      +/-   ##
==========================================
+ Coverage   66.44%   68.07%   +1.63%     
==========================================
  Files          37       36       -1     
  Lines        1436     1647     +211     
==========================================
+ Hits          954     1121     +167     
- Misses        482      526      +44     
Files with missing lines Coverage Δ
CoughSync/CoughDetection/CoughClass.swift 100.00% <100.00%> (ø)
...hSync/CoughDetection/CoughDetectionViewModel.swift 41.67% <100.00%> (+23.34%) ⬆️
CoughSync/Summary/SummaryView.swift 96.83% <94.74%> (-1.09%) ⬇️
CoughSync/CoughVisualization/CoughTracker.swift 80.96% <77.78%> (-19.04%) ⬇️
...oughSync/CoughVisualization/CoughTrackerView.swift 88.24% <91.23%> (-11.76%) ⬇️
CoughSync/CoughSyncStandard.swift 65.22% <78.69%> (+15.22%) ⬆️

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ad9f304...c044e93. Read the comment docs.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aajain2 aajain2 enabled auto-merge (squash) March 9, 2025 01:35
@aajain2 aajain2 merged commit 9fb2aa4 into main Mar 9, 2025
10 checks passed
@aajain2 aajain2 deleted the graphdataconnection branch March 9, 2025 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants