Skip to content

Commit

Permalink
chore: fix managing collector list logic
Browse files Browse the repository at this point in the history
Signed-off-by: vividf <[email protected]>
  • Loading branch information
vividf committed Feb 7, 2025
1 parent 81ec941 commit 3375c43
Showing 1 changed file with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -364,40 +364,49 @@ void PointCloudConcatenateDataSynchronizerComponent::manage_collector_list()
{
std::lock_guard<std::mutex> cloud_collectors_lock(cloud_collectors_mutex_);

int num_processing_collectors = 0;

for (auto & collector : cloud_collectors_) {
if (collector->get_status() == CollectorStatus::Finished) {
collector->reset();
}

if (collector->get_status() == CollectorStatus::Processing) {
num_processing_collectors++;
}
}

if (cloud_collectors_.size() >= collectors_threshold) {
if (num_processing_collectors >= collectors_threshold) {
auto min_it = cloud_collectors_.end();
double min_timestamp = std::numeric_limits<double>::max();
constexpr double k_max_timestamp = std::numeric_limits<double>::max();
double min_timestamp = k_max_timestamp;

for (auto it = cloud_collectors_.begin(); it != cloud_collectors_.end(); ++it) {
auto info = (*it)->get_info();
double timestamp = std::numeric_limits<double>::max();
if (auto naive_info = std::dynamic_pointer_cast<NaiveCollectorInfo>(info)) {
timestamp = naive_info->timestamp;
} else if (auto advanced_info = std::dynamic_pointer_cast<AdvancedCollectorInfo>(info)) {
timestamp = advanced_info->timestamp;
} else {
continue;
}
if ((*it)->get_status() == CollectorStatus::Processing) {
auto info = (*it)->get_info();
double timestamp = k_max_timestamp;

if (auto naive_info = std::dynamic_pointer_cast<NaiveCollectorInfo>(info)) {
timestamp = naive_info->timestamp;
} else if (auto advanced_info = std::dynamic_pointer_cast<AdvancedCollectorInfo>(info)) {
timestamp = advanced_info->timestamp;
} else {
continue;
}

// Update the iterator pointing to the collector with the smallest timestamp
if (timestamp < min_timestamp) {
min_timestamp = timestamp;
min_it = it;
if (timestamp < min_timestamp) {
min_timestamp = timestamp;
min_it = it;
}
}
}

// Reset the collector with the oldest timestamp if found
if (min_it != cloud_collectors_.end()) {
RCLCPP_WARN_STREAM(
get_logger(),
"Reset the oldest collector because the number of collectors is larger than the limit: %d"
<< collectors_threshold);
get_logger(), "Reset the oldest collector because the number of collectors ("
<< num_processing_collectors << ") exceeds the limit ("
<< collectors_threshold << "). Oldest timestamp: ");
(*min_it)->reset();

Check warning on line 410 in sensing/autoware_pointcloud_preprocessor/src/concatenate_data/concatenate_and_time_sync_node.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Complex Method

PointCloudConcatenateDataSynchronizerComponent::manage_collector_list has a cyclomatic complexity of 12, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.

Check warning on line 410 in sensing/autoware_pointcloud_preprocessor/src/concatenate_data/concatenate_and_time_sync_node.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Bumpy Road Ahead

PointCloudConcatenateDataSynchronizerComponent::manage_collector_list has 2 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is one single, nested block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.

Check notice on line 410 in sensing/autoware_pointcloud_preprocessor/src/concatenate_data/concatenate_and_time_sync_node.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ New issue: Deep, Nested Complexity

PointCloudConcatenateDataSynchronizerComponent::manage_collector_list has a nested complexity depth of 4, threshold = 4. This function contains deeply nested logic such as if statements and/or loops. The deeper the nesting, the lower the code health.
}
}
Expand Down

0 comments on commit 3375c43

Please sign in to comment.