# Implementation Plan: Infrared Camera Data Query Enhancement ## Overview This implementation plan enhances the `FindDatas` method to query infrared camera temperature data from the `OriginalInspectionStoreResult` collection. The implementation adds camera identification logic, fuzzy equipment name matching with 85% similarity, and structured temperature data parsing. ## Tasks - [x] 1. Implement helper method for infrared camera identification - Create `IsInfraredCamera` method that checks if CamName contains "热成像" or ends with 'B' - Handle null/empty camera names safely - _Requirements: 1.1, 1.2, 1.3_ - [ ]* 1.1 Write property test for infrared camera identification - **Property 1: Infrared Camera Identification Completeness** - **Validates: Requirements 1.1, 1.2, 1.3** - Generate camera names with "热成像" or ending with 'B' - Verify IsInfraredCamera returns true for all matching patterns - [ ]* 1.2 Write unit tests for IsInfraredCamera edge cases - Test null camera name - Test empty camera name - Test camera name with neither pattern - _Requirements: 1.1, 1.2, 1.3_ - [x] 2. Enhance CalculateSimilarity method with Levenshtein distance - Replace simple character matching with Levenshtein distance algorithm - Implement formula: `similarity = 1.0 - (distance / maxLength)` - Add null/empty string handling returning 0.0 - Make comparison case-insensitive - _Requirements: 2.4_ - [ ]* 2.1 Write property test for similarity symmetry - **Property 2: Similarity Calculation Symmetry** - **Validates: Requirements 2.4** - Generate random string pairs - Verify CalculateSimilarity(A, B) == CalculateSimilarity(B, A) - [ ]* 2.2 Write property test for similarity bounds - **Property 3: Similarity Score Bounds** - **Validates: Requirements 2.4** - Generate random string pairs - Verify 0.0 <= CalculateSimilarity(A, B) <= 1.0 - [ ]* 2.3 Write unit tests for similarity calculation - Test identical strings (should return 1.0) - Test completely different strings - Test strings at 85% similarity threshold - Test null and empty string handling - _Requirements: 2.4, 5.2_ - [x] 3. Implement equipment name matching method - Create `MatchesEquipmentByName` method - Compare data.EquipmentInfoName against equipment.Name - Compare data.Name against equipment.Name - Return true if either similarity >= 0.85 - _Requirements: 2.2, 2.3, 2.5, 2.6_ - [ ]* 3.1 Write property test for equipment matching threshold - **Property 4: Equipment Matching Threshold** - **Validates: Requirements 2.5, 2.6** - Generate inspection data and equipment with varying name similarities - Verify matching returns true when similarity >= 0.85 - [ ]* 3.2 Write unit tests for equipment matching - Test exact name match - Test 85% similarity match - Test 84% similarity (should not match) - Test null equipment names - Test matching via EquipmentInfoName field - Test matching via Name field - _Requirements: 2.2, 2.3, 2.5, 2.6_ - [x] 4. Implement temperature data parsing method - Create `ParseTemperatureFromInfraredResult` method - Split Result field by delimiters: `,`, `,`, `\r\n`, `\n` - For each segment, check if contains `:` or `:` - Split valid segments into name and value parts - Extract numeric temperature using regex: `@"-?\d+(?:\.\d+)?"` - Create MeasureTemperatureResultOutput for each valid temperature - Add error logging for parsing failures - _Requirements: 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 5.1_ - [ ]* 4.1 Write property test for valid temperature parsing - **Property 5: Valid Temperature Data Parsing** - **Validates: Requirements 3.1, 3.2, 3.3, 3.5, 3.6** - Generate Result strings with valid "name:value" format - Verify at least one temperature point is extracted with non-null value - [ ]* 4.2 Write property test for invalid segment skipping - **Property 6: Invalid Segment Skipping** - **Validates: Requirements 3.4, 3.7** - Generate Result strings with mix of valid and invalid segments - Verify invalid segments are skipped without errors - [ ]* 4.3 Write unit tests for temperature parsing - Test valid format: "2BL_C相连接点:-12.5℃" - Test multiple temperature points separated by commas - Test mixed valid and invalid segments - Test empty Result string - Test Result with no colons - Test negative temperatures - Test decimal temperatures - _Requirements: 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7_ - [ ] 5. Checkpoint - Ensure all helper methods and tests pass - Ensure all tests pass, ask the user if questions arise. - [x] 6. Modify FindDatas method to add infrared camera query logic - Add MongoDB filter for infrared cameras using IsInfraredCamera logic - Query OriginalInspectionStoreResult collection with time range filters - Apply equipment matching using MatchesEquipmentByName when EquipmentInfoId is specified - Parse temperature data using ParseTemperatureFromInfraredResult - Apply name filter to parsed temperature points - Merge results with existing thermal imaging device results - _Requirements: 4.1, 4.2, 4.3, 4.4, 4.5_ - [ ]* 6.1 Write property test for filter application order - **Property 7: Filter Application Order** - **Validates: Requirements 4.1, 4.2, 4.3, 4.4, 4.5** - Generate test data with various filter combinations - Verify filters are applied in correct order - [ ]* 6.2 Write integration tests for FindDatas - Test full query flow with infrared camera data - Test equipment matching integration - Test pagination with infrared camera results - Test time range filtering - Test name filtering on parsed temperature points - _Requirements: 4.1, 4.2, 4.3, 4.4, 4.5, 4.6_ - [x] 7. Add comprehensive error handling and logging - Add try-catch for MongoDB query failures - Add try-catch for temperature parsing failures with graceful degradation - Add try-catch for similarity calculation errors - Add try-catch for equipment lookup failures - Implement logging strategy (Error, Warning, Info levels) - _Requirements: 5.1, 5.2, 5.3, 5.4, 5.5_ - [ ]* 7.1 Write property test for parsing error isolation - **Property 9: Parsing Error Isolation** - **Validates: Requirements 5.1, 5.5** - Generate dataset with some invalid Result formats - Verify parsing failures don't prevent processing of other records - [ ]* 7.2 Write unit tests for error handling - Test MongoDB query failure handling - Test temperature parsing failure handling - Test similarity calculation error handling - Test equipment lookup failure handling - Verify appropriate logging occurs - _Requirements: 5.1, 5.2, 5.3, 5.4_ - [ ] 8. Final checkpoint - Ensure all tests pass and integration works - Run all unit tests and property tests - Run integration tests with real MongoDB data - Verify backward compatibility with existing thermal imaging queries - Ensure all tests pass, ask the user if questions arise. ## Notes - Tasks marked with `*` are optional and can be skipped for faster MVP - Each task references specific requirements for traceability - Checkpoints ensure incremental validation - Property tests validate universal correctness properties - Unit tests validate specific examples and edge cases - The Levenshtein distance algorithm is critical for accurate 85% similarity matching - Error handling ensures graceful degradation when parsing fails - Logging provides visibility into query execution and failures