Skip to content

Commit

Permalink
chore: remove oldest timestamp
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 cbb94ec commit 81ec941
Showing 1 changed file with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <pcl_conversions/pcl_conversions.h>

#include <iomanip>
#include <limits>
#include <list>
#include <memory>
#include <optional>
Expand Down Expand Up @@ -369,12 +370,36 @@ void PointCloudConcatenateDataSynchronizerComponent::manage_collector_list()
}
}

if (cloud_collectors_.size() > collectors_threshold) {
RCLCPP_WARN_STREAM_THROTTLE(
get_logger(), *get_clock(), 1000,
"The number of cloud collectors (" << cloud_collectors_.size() << ") exceeds the threshold ("
<< collectors_threshold
<< "), be careful if it keeps increasing.");
if (cloud_collectors_.size() >= collectors_threshold) {
auto min_it = cloud_collectors_.end();
double min_timestamp = std::numeric_limits<double>::max();

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;
}

// Update the iterator pointing to the collector with the smallest timestamp
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);
(*min_it)->reset();

Check warning on line 401 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 10, 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 401 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.
}
}
}

Expand Down

0 comments on commit 81ec941

Please sign in to comment.