-
Notifications
You must be signed in to change notification settings - Fork 21
Feature/shearwater cloud import #96
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f8c0d2e
add libdc_parse_raw_dive() for standalone dive data parsing
ericgriffin 0524faa
add parseRawDiveData Pigeon API method with platform bridges
ericgriffin 00a8cdc
Task 8: wire ShearwaterCloudParser into import system
ericgriffin 69a9c70
feat: add Shearwater Cloud parser, DB reader, filename parser, and va…
ericgriffin ad03748
fix: resolve Shearwater profile parsing - model=0 wildcard + richer s…
ericgriffin de45b22
test: increase Shearwater import coverage to 90%+
ericgriffin 0775d14
fix: handle Shearwater gzip streams with zeroed CRC trailers
ericgriffin 3a55f71
style: fix analyzer info-level issues for pre-push hook
ericgriffin bd39645
test: add unit and widget tests for debug log viewer feature
ericgriffin e8ff9f5
fix: improve Shearwater import error handling for FFI unavailability
ericgriffin 1698673
style: remove unnecessary dart:typed_data import in profile test
ericgriffin 6b2ab0c
fix: gate ceiling and ndl fields by decoType in Shearwater profile ma…
ericgriffin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
125 changes: 125 additions & 0 deletions
125
lib/features/universal_import/data/parsers/shearwater_cloud_parser.dart
This file contains hidden or 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,125 @@ | ||
| import 'package:flutter/services.dart'; | ||
|
|
||
| import 'package:submersion/features/universal_import/data/models/import_enums.dart'; | ||
| import 'package:submersion/features/universal_import/data/models/import_options.dart'; | ||
| import 'package:submersion/features/universal_import/data/models/import_payload.dart'; | ||
| import 'package:submersion/features/universal_import/data/models/import_warning.dart'; | ||
| import 'package:submersion/features/universal_import/data/parsers/import_parser.dart'; | ||
| import 'package:submersion/features/universal_import/data/services/shearwater_db_reader.dart'; | ||
| import 'package:submersion/features/universal_import/data/services/shearwater_dive_mapper.dart'; | ||
|
|
||
| /// Parses a Shearwater Cloud SQLite database file into an [ImportPayload]. | ||
| /// | ||
| /// Orchestrates the full Shearwater Cloud import flow: | ||
| /// 1. Validates the database structure. | ||
| /// 2. Reads raw dives from [ShearwaterDbReader]. | ||
| /// 3. Maps each dive via [ShearwaterDiveMapper.mapDive]. | ||
| /// 4. Extracts unique sites via [ShearwaterDiveMapper.mapSites]. | ||
| /// 5. Returns a unified [ImportPayload]. | ||
| class ShearwaterCloudParser implements ImportParser { | ||
| @override | ||
| List<ImportFormat> get supportedFormats => [ImportFormat.shearwaterDb]; | ||
|
|
||
| @override | ||
| Future<ImportPayload> parse( | ||
| Uint8List fileBytes, { | ||
| ImportOptions? options, | ||
| }) async { | ||
| // 1. Validate database. | ||
| final isValid = await ShearwaterDbReader.isShearwaterCloudDb(fileBytes); | ||
| if (!isValid) { | ||
| return const ImportPayload( | ||
| entities: {}, | ||
| warnings: [ | ||
| ImportWarning( | ||
| severity: ImportWarningSeverity.error, | ||
| message: | ||
| 'File is not a valid Shearwater Cloud database. ' | ||
| 'Expected dive_details and log_data tables.', | ||
| ), | ||
| ], | ||
| ); | ||
| } | ||
|
|
||
| // 2. Read raw dives. | ||
| final List<ShearwaterRawDive> rawDives; | ||
| try { | ||
| rawDives = await ShearwaterDbReader.readDives(fileBytes); | ||
| } catch (e) { | ||
| return ImportPayload( | ||
| entities: const {}, | ||
| warnings: [ | ||
| ImportWarning( | ||
| severity: ImportWarningSeverity.error, | ||
| message: 'Failed to read dives from database: $e', | ||
| ), | ||
| ], | ||
| ); | ||
| } | ||
| if (rawDives.isEmpty) { | ||
| return const ImportPayload( | ||
| entities: {}, | ||
| warnings: [ | ||
| ImportWarning( | ||
| severity: ImportWarningSeverity.info, | ||
| message: 'Shearwater Cloud database contains no dives.', | ||
| ), | ||
| ], | ||
| ); | ||
| } | ||
|
|
||
| // 3. Map dives to ImportPayload entities. | ||
| // After the first platform-level FFI failure, fall back to | ||
| // metadata-only for remaining dives. | ||
| final warnings = <ImportWarning>[]; | ||
| final diveEntities = <Map<String, dynamic>>[]; | ||
| var ffiAvailable = true; | ||
|
|
||
| for (final rawDive in rawDives) { | ||
| if (ffiAvailable) { | ||
| try { | ||
| final diveMap = await ShearwaterDiveMapper.mapDive( | ||
| rawDive, | ||
| warnings: warnings, | ||
| ); | ||
| diveEntities.add(diveMap); | ||
| } on MissingPluginException { | ||
| ffiAvailable = false; | ||
| diveEntities.add(ShearwaterDiveMapper.mapDiveMetadata(rawDive)); | ||
| } on PlatformException { | ||
| ffiAvailable = false; | ||
| warnings.add( | ||
| const ImportWarning( | ||
| severity: ImportWarningSeverity.info, | ||
| message: | ||
| 'Profile parsing is not available on this platform. ' | ||
| 'Dives will be imported with metadata only.', | ||
| entityType: ImportEntityType.dives, | ||
| ), | ||
| ); | ||
| diveEntities.add(ShearwaterDiveMapper.mapDiveMetadata(rawDive)); | ||
| } | ||
| } else { | ||
| diveEntities.add(ShearwaterDiveMapper.mapDiveMetadata(rawDive)); | ||
| } | ||
| } | ||
|
|
||
| // 4. Extract unique sites. | ||
| final sites = ShearwaterDiveMapper.mapSites(rawDives); | ||
|
|
||
| // 5. Build payload. | ||
| final entities = <ImportEntityType, List<Map<String, dynamic>>>{}; | ||
| if (diveEntities.isNotEmpty) { | ||
| entities[ImportEntityType.dives] = diveEntities; | ||
| } | ||
| if (sites.isNotEmpty) { | ||
| entities[ImportEntityType.sites] = sites; | ||
| } | ||
|
|
||
| return ImportPayload( | ||
| entities: entities, | ||
| warnings: warnings, | ||
| metadata: {'source': 'shearwater_cloud', 'diveCount': rawDives.length}, | ||
| ); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.