-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
Publish bird images in mqtt events #219
Conversation
WalkthroughThis update integrates a bird image caching mechanism into various components of the system. The core additions involve modifying the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Actionable comments posted: 1
Outside diff range and nitpick comments (2)
internal/analysis/processor/processor.go (2)
16-16
: Consider grouping imports logically for better readability.
28-28
: Consider adding more detailed comments in complex sections of the code, such as dynamic threshold management and detection processing, to enhance maintainability.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (6)
- internal/analysis/processor/actions.go (3 hunks)
- internal/analysis/processor/processor.go (3 hunks)
- internal/analysis/processor/workers.go (1 hunks)
- internal/analysis/realtime.go (3 hunks)
- internal/httpcontroller/init.go (4 hunks)
- views/fragments/birdsTableHTML.html (1 hunks)
Files skipped from review due to trivial changes (1)
- views/fragments/birdsTableHTML.html
Additional comments not posted (9)
internal/analysis/processor/workers.go (1)
114-114
: Integration ofBirdImageCache
intoMqttAction
looks correct.#!/bin/bash # Description: Verify that `BirdImageCache` is properly initialized and passed to `MqttAction`. # Test: Search for initialization and usage of `BirdImageCache`. rg --type go $'BirdImageCache'internal/httpcontroller/init.go (2)
47-47
: Correct injection ofBirdImageCache
into theServer
struct.
39-39
: Proper modification to acceptbirdImageCache
as a parameter in theNew
function, ensuring it's available throughout the HTTP controller.#!/bin/bash # Description: Verify the complete initialization flow of `birdImageCache` in the HTTP controller. # Test: Search for usages of `birdImageCache` in the initialization sequence. rg --type go $'birdImageCache'internal/analysis/processor/actions.go (2)
61-61
: Integration ofBirdImageCache
inMqttAction
is implemented correctly.#!/bin/bash # Description: Ensure that `BirdImageCache` is properly integrated with the MQTT client configuration. # Test: Search for configuration and usage of `BirdImageCache` with MQTT. rg --type go $'BirdImageCache'
156-176
: Creation ofNoteWithBirdImage
struct and its usage inMqttAction.Execute
are well-implemented for the new MQTT message format.#!/bin/bash # Description: Test the new MQTT message format with `NoteWithBirdImage`. # Test: Simulate MQTT publish and verify the message format. echo 'Simulating MQTT publish...' # Example simulation command (pseudo-code) # simulate_mqtt_publish --data "$(json_note_with_bird_image)"internal/analysis/processor/processor.go (4)
28-28
: Addition ofBirdImageCache
toProcessor
struct supports the new feature of caching bird images. Ensure this field is properly initialized and used across methods.
81-81
: Proper initialization ofBirdImageCache
within theNew
function ensures it's available for use in theProcessor
.
28-28
: The structProcessor
is well-organized and modular, effectively handling various aspects of bird detection processing.
76-76
: Update toNew
function signature to includebirdImageCache
is appropriate. Ensure that all callers of this function are updated to pass the correctbirdImageCache
instance.#!/bin/bash # Description: Verify all function calls to `New` match the new signature. # Test: Search for the function usage. Expect: Only occurances of the new signature. rg --type go $'New'Also applies to: 81-81
internal/analysis/realtime.go
Outdated
func initBirdImageCache(ds datastore.Interface) *imageprovider.BirdImageCache { | ||
|
||
birdImageCache, err := imageprovider.CreateDefaultCache() | ||
if err != nil { | ||
log.Fatalf("Failed to create image cache: %v", err) | ||
} | ||
|
||
// Initialize the image cache by fetching all detectes species in database | ||
go func() error { | ||
speciesList, err := ds.GetAllDetectedSpecies() | ||
if err != nil { | ||
return fmt.Errorf("failed to get detected species: %v", err) | ||
} | ||
|
||
var wg sync.WaitGroup | ||
|
||
for _, species := range speciesList { | ||
wg.Add(1) | ||
|
||
go func(speciesName string) { | ||
defer wg.Done() | ||
_, err := birdImageCache.Get(speciesName) | ||
if err != nil { | ||
fmt.Printf("Failed to get image for species %s: %v\n", speciesName, err) | ||
} | ||
}(species.ScientificName) | ||
} | ||
|
||
wg.Wait() | ||
return nil | ||
}() | ||
|
||
return birdImageCache | ||
} |
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.
Initialization and pre-loading of BirdImageCache
are correctly implemented. Consider enhancing error handling within the goroutine to prevent silent failures.
// Improved error handling in goroutine
go func() error {
speciesList, err := ds.GetAllDetectedSpecies()
if err != nil {
log.Printf("Failed to get detected species: %v", err)
return err
}
var wg sync.WaitGroup
for _, species := range speciesList {
wg.Add(1)
go func(speciesName string) {
defer wg.Done()
_, err := birdImageCache.Get(speciesName)
if err != nil {
log.Printf("Failed to get image for species %s: %v\n", speciesName, err)
}
}(species.ScientificName)
}
wg.Wait()
return nil
}()
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- internal/analysis/realtime.go (3 hunks)
Files skipped from review as they are similar to previous changes (1)
- internal/analysis/realtime.go
Based on request #218
The new mqtt message which contains the bird image information should be backwards compatible with the old one. Since the old message is simply extended to also contain the filed BirdImage. See example below: