-
Notifications
You must be signed in to change notification settings - Fork 815
feat: added csv functionalities in soundmeter screen. #2796
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
base: flutter
Are you sure you want to change the base?
Conversation
Reviewer's GuideThis PR adds full CSV recording support to the sound meter feature by integrating a CsvService into the UI, extending the state provider to track and export readings, refactoring the chart display to use timestamped data with formatted axis labels, and ensuring consistent CSV headers and localization across both sound and lux meter screens. Sequence diagram for sound meter CSV recording and save flowsequenceDiagram
actor User
participant SoundMeterScreen
participant SoundMeterStateProvider
participant CsvService
User->>SoundMeterScreen: Tap record button
SoundMeterScreen->>SoundMeterStateProvider: startRecording()
SoundMeterStateProvider-->>SoundMeterScreen: isRecording = true
User->>SoundMeterScreen: Tap stop record button
SoundMeterScreen->>SoundMeterStateProvider: stopRecording()
SoundMeterStateProvider-->>SoundMeterScreen: recordedData
SoundMeterScreen->>User: Show save dialog
User->>SoundMeterScreen: Enter file name
SoundMeterScreen->>CsvService: saveCsvFile('soundmeter', fileName, data)
CsvService-->>SoundMeterScreen: File saved
SoundMeterScreen->>User: Show success/failure message
Sequence diagram for sensor error handling in sound metersequenceDiagram
participant SoundMeterScreen
participant SoundMeterStateProvider
participant User
SoundMeterScreen->>SoundMeterStateProvider: initializeSensors(onError)
SoundMeterStateProvider-->>SoundMeterScreen: onSensorError callback (if error)
SoundMeterScreen->>User: Show snackbar with error message
ER diagram for CSV data structure for sound and lux metererDiagram
CSV_FILE {
string Timestamp
string DateTime
string Readings
string Latitude
string Longitude
}
SOUND_METER ||--o{ CSV_FILE : records
LUX_METER ||--o{ CSV_FILE : records
Class diagram for updated LuxMeterStateProvider CSV header structureclassDiagram
class LuxMeterStateProvider {
- bool _isRecording
- List<List<dynamic>> _recordedData
+ bool get isRecording
+ void startRecording()
}
%% CSV header now: ['Timestamp', 'DateTime', 'Readings', 'Latitude', 'Longitude']
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Yugesh-Kumar-S - I've reviewed your changes - here's some feedback:
- The
_showSaveFileDialog
method mixes UI and CSV logic—consider extracting the file‐dialog UI and CSV operations into separate helpers or widgets to keep the screen code concise and testable. - Currently the filename input defaults to an empty string—pre-populating it with a timestamp-based default (e.g. “soundmeter_20240612_1530”) would improve the UX.
- The
TextEditingController
in_showSaveFileDialog
isn’t disposed; consider managing it at the widget level or disposing it after the dialog closes to prevent potential memory leaks.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `_showSaveFileDialog` method mixes UI and CSV logic—consider extracting the file‐dialog UI and CSV operations into separate helpers or widgets to keep the screen code concise and testable.
- Currently the filename input defaults to an empty string—pre-populating it with a timestamp-based default (e.g. “soundmeter_20240612_1530”) would improve the UX.
- The `TextEditingController` in `_showSaveFileDialog` isn’t disposed; consider managing it at the widget level or disposing it after the dialog closes to prevent potential memory leaks.
## Individual Comments
### Comment 1
<location> `lib/view/soundmeter_screen.dart:135` </location>
<code_context>
+
+ Future<void> _showSaveFileDialog(List<List<dynamic>> data) async {
+ final TextEditingController filenameController = TextEditingController();
+ final String defaultFilename = '';
+ filenameController.text = defaultFilename;
+
</code_context>
<issue_to_address>
Default filename is set to an empty string, which may lead to invalid file names.
An empty default filename may cause issues on some platforms. Please use a meaningful default, like a timestamp or instrument name.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
Future<void> _showSaveFileDialog(List<List<dynamic>> data) async {
final TextEditingController filenameController = TextEditingController();
final String defaultFilename = '';
filenameController.text = defaultFilename;
=======
Future<void> _showSaveFileDialog(List<List<dynamic>> data) async {
final TextEditingController filenameController = TextEditingController();
final String defaultFilename = 'soundmeter_${DateTime.now().toIso8601String().replaceAll(":", "").replaceAll("-", "").replaceAll(".", "").substring(0, 15)}.csv';
filenameController.text = defaultFilename;
>>>>>>> REPLACE
</suggested_fix>
### Comment 2
<location> `lib/view/soundmeter_screen.dart:167` </location>
<code_context>
+ );
+
+ if (fileName != null) {
+ _csvService.writeMetaData('soundmeter', data);
+ final file = await _csvService.saveCsvFile('soundmeter', fileName, data);
+ if (mounted) {
</code_context>
<issue_to_address>
writeMetaData is called before saveCsvFile, but its necessity is unclear.
If writeMetaData isn't always needed or may fail, handle its result or errors. Otherwise, clarify its purpose in the save process.
</issue_to_address>
### Comment 3
<location> `lib/providers/soundmeter_state_provider.dart:105` </location>
<code_context>
void _updateData() {
final db = _currentDb;
final time = _currentTime;
+ if (_isRecording) {
+ final relativeTime = time - _recordingStartTime;
+ final now = DateTime.now();
</code_context>
<issue_to_address>
Recording data includes formatted date and relative time, but may grow unbounded.
Long recording sessions may cause _recordedData to consume excessive memory. Consider limiting recording duration or implementing data chunking.
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Build successful. APKs to test: https://github.com/fossasia/pslab-app/actions/runs/16756009655/artifacts/3693200567 |
@sourcery-ai review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Yugesh-Kumar-S - I've reviewed your changes - here's some feedback:
- CSV header definitions are duplicated in each provider; consider defining them in a shared constant or in CsvService to avoid repetition.
- The save-file dialog and snackbar UI logic could be factored out into helper methods or widgets to DRY up the sound meter screen.
- The sensor error handling strategy is only applied during initialization; consider unifying error callbacks for runtime sensor failures to ensure consistent reporting.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- CSV header definitions are duplicated in each provider; consider defining them in a shared constant or in CsvService to avoid repetition.
- The save-file dialog and snackbar UI logic could be factored out into helper methods or widgets to DRY up the sound meter screen.
- The sensor error handling strategy is only applied during initialization; consider unifying error callbacks for runtime sensor failures to ensure consistent reporting.
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Fixes #2795
Changes
2025-07-22_08-20-03.csv
2025-07-22_08-20-57.csv
Screenshots / Recordings
screen-20250720-130234.mp4
Checklist:
strings.xml
,dimens.xml
andcolors.xml
without hard coding any value.strings.xml
,dimens.xml
orcolors.xml
.Summary by Sourcery
Implement CSV data recording in the sound meter screen, providing UI controls to start/stop recording, save data files, and view logged recordings, while enhancing state management and error handling.
New Features:
Enhancements:
Documentation:
Summary by Sourcery
Add CSV recording and viewing capabilities to the sound meter screen, including controls to start/stop recordings, save CSV files with headers, and navigate to previously logged data
New Features:
Enhancements:
Documentation: