4#include <ArmarXCore/interface/core/UserException.h>
16 std::vector<std::unique_ptr<processor::SnapshotFilter>>
17 Processors::buildSnapshotFilters(
const nlohmann::json& config)
19 std::vector<std::unique_ptr<processor::SnapshotFilter>> filters;
23 auto f = std::make_unique<processor::filter::SnapshotFrequencyFilter>();
25 filters.push_back(std::move(f));
30 auto f = std::make_unique<processor::filter::SnapshotSimilarityFilter>();
32 filters.push_back(std::move(f));
37 auto f = std::make_unique<processor::filter::SnapshotImportanceFilter>();
39 filters.push_back(std::move(f));
52 if (config.contains(
"storeSegments"))
54 std::set<std::string> whitelist;
55 for (
const auto& entry : config[
"storeSegments"])
57 whitelist.insert(entry.get<std::string>());
59 ARMARX_IMPORTANT <<
"LTM storeSegments whitelist active with " << whitelist.size()
66 if (config.contains(
"segments"))
68 for (
const auto& [segmentPath, segmentConfig] : config[
"segments"].items())
79 auto f = std::make_unique<processor::converter::data::image::PngConverter>();
86 auto f = std::make_unique<processor::converter::data::image::ExrConverter>();
99 Processors::isSegmentWhitelisted(
const std::string& coreSegmentName,
100 const std::string& providerSegmentName)
const
110 if (whitelist.count(coreSegmentName) > 0)
114 if (!providerSegmentName.empty() &&
115 whitelist.count(coreSegmentName +
"/" + providerSegmentName) > 0)
124 const std::string& providerSegmentName,
126 bool simulatedVersion)
129 if (!isSegmentWhitelisted(coreSegmentName, providerSegmentName))
136 const std::string providerPath = coreSegmentName +
"/" + providerSegmentName;
150 if (!filter->accept(snapshot, simulatedVersion))
158 std::map<std::string, processor::SnapshotFilter::FilterStatistics>
161 std::map<std::string, processor::SnapshotFilter::FilterStatistics> stats;
162 bool recordedOverall =
false;
165 auto collect = [&](
const std::string& keyPrefix,
166 const std::vector<std::unique_ptr<processor::SnapshotFilter>>&
filters)
168 for (
const auto& filter_ptr :
filters)
170 auto statistics = filter_ptr->getFilterStatistics();
171 auto recorded = statistics.accepted + statistics.rejected;
172 stats[keyPrefix + filter_ptr->getName()] = statistics;
175 recordedOverall =
true;
184 collect(segmentPath +
":",
filters);
187 ARMARX_INFO <<
"Number of active filters: " << numFilters;
191 if (numFilters > 0 && !recordedOverall)
193 throw InvalidArgumentException(
194 "NoFilters recorded any data being accepted or rejected, "
195 "cant store empty statistics");
206 filter_ptr->resetStatisticsForNewEpisode();
210 for (
const auto& filter_ptr :
filters)
212 filter_ptr->resetStatisticsForNewEpisode();
std::vector< std::unique_ptr< processor::SnapshotFilter > > snapFilters
std::optional< std::set< std::string > > storeSegments
Optional whitelist of segments to store.
void configure(const nlohmann::json &config)
std::vector< std::unique_ptr< processor::DataConverter > > converters
bool acceptSnapshotForSegment(const std::string &coreSegmentName, const std::string &providerSegmentName, const armem::wm::EntitySnapshot &snapshot, bool simulatedVersion=false)
Decide whether a snapshot of the given segment should be stored to LTM.
std::map< std::string, std::vector< std::unique_ptr< processor::SnapshotFilter > > > segmentSnapFilters
Per-segment snapshot filter overrides, keyed by "CoreSegment" or "CoreSegment/ProviderSegment".
std::map< std::string, processor::SnapshotFilter::FilterStatistics > getSnapshotFilterStatistics()
bool hasSegmentSelection() const
Whether any segment-based selection or per-segment filtering is configured.
void resetFilterStatisticsForNewEpisode()
resetFilterStatisticsForNewEpisode runs resetFilterStatisticsForNewEpisode on all snapshot filters
static const constexpr char * NAME
static const constexpr char * NAME
static const constexpr char * NAME
static const constexpr char * NAME
static const constexpr char * NAME
Client-side working memory entity snapshot.
#define ARMARX_INFO
The normal logging level.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.