Skip to content

Added database CSV exports for individual and/or research use#8402

Open
kelseyhuss wants to merge 23 commits intonightscout:masterfrom
kelseyhuss:master
Open

Added database CSV exports for individual and/or research use#8402
kelseyhuss wants to merge 23 commits intonightscout:masterfrom
kelseyhuss:master

Conversation

@kelseyhuss
Copy link
Copy Markdown

New Features:

Added CSV Export Buttons to Main Homescreen: Users can now export data directly from the main screen via the menu when Authenticated

  • Export Entries (CSV) - Blood glucose readings and CGM data
  • Export Treatments (CSV) - Insulin, carbs, and other treatment data
  • Export Profile (CSV) - Profile settings and configurations
  • Export DeviceStatus (CSV) - Device and uploader status information

Modified backend API endpoints to properly handle CSV formatting for all data types

kelseyhuss and others added 23 commits November 11, 2025 10:12
- Added export buttons to the main navigation menu (requires admin access)
- Implemented client-side exportData function with API_SECRET authentication
- Export buttons trigger CSV downloads for entries and treatments data
- Uses existing backend CSV export API endpoints with proper authentication
- Exports up to 10,000 records with timestamped filenames
- Only visible to authenticated admin users
- Added authenticatedExport() function to properly handle API secret validation
- Export buttons now check if user is authenticated before allowing data export
- If not authenticated, user is prompted to enter API secret via authentication dialog
- API secret hash is now properly appended to export URLs as query parameter
- Added proper URL encoding for all query parameters
- Improved code structure with reusable function for both entries and treatments exports

This fixes the issue where CSV exports were failing due to missing authentication,
ensuring that the API_SECRET is properly required and validated before allowing
data exports.
…ections

- Added export buttons for Profile, DeviceStatus, and Food to the reports page
- Implemented CSV format support in profile, devicestatus, and food API endpoints
- Added date range filtering support for all new exports
- All exports require API secret authentication
- Export buttons placed above 'Show' button for easy access
Add CSV Export for Profile, DeviceStatus, and Food Collections
Fixed multiple issues with CSV exports:

1. Entries CSV export:
   - Added header row to CSV output (dateString, date, sgv, direction, device)
   - Fixed incomplete data export by bypassing in-memory cache for large exports (count >= 10000)
   - Database is now queried directly for large exports to ensure all rows are included

2. Treatments CSV export:
   - Fixed incomplete data export by bypassing in-memory cache for large exports (count >= 10000)
   - Database is now queried directly for large exports to ensure all rows are included

3. Profile CSV export:
   - Changed /profile/ endpoint to use query_models function to support CSV format
   - Previously only returned JSON, now properly returns CSV when .csv extension is used

4. Devicestatus CSV export:
   - Fixed blank output by bypassing in-memory cache for large exports (count >= 10000)
   - Database is now queried directly for large exports to generate proper CSV with all data

5. Food CSV export:
   - Added null check to ensure empty array is returned when no results
   - Improved error handling for blank output scenarios

All exports now properly query the database when count parameter is 10000 or higher,
ensuring complete data export rather than being limited by in-memory cache size.
Fix CSV export functionality for all data types
Move CSV export buttons from reports view to main homescreen
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.

1 participant