31#include <VisionX/libraries/armem_human/aron/HumanRobotInteraction.aron.generated.h>
38 armarx::armem::client::query::Builder
49 if (not
query.providerName.empty())
72 if (not
query.providerName.empty())
84 std::vector<HumanRobotInteraction>
90 std::vector<HumanRobotInteraction> interactions;
99 entitySnapshot.forEachInstance(
100 [&interactions, &
timestamp, &maxAge](
const auto& entityInstance)
105 timestamp - entityInstance.metadata().referencedTime;
107 if (dtToNow < maxAge and dtToNow.
isPositive())
112 ARMARX_CHECK(aronDto) <<
"Failed casting to HumanRobotInteraction";
117 interactions.push_back(interaction);
128 return "mem.human.interaction.";
134 return {.memoryName =
"Human", .coreSegmentName =
"HumanRobotInteraction"};
152 ARMARX_INFO <<
"[InteractionReader] Querying memory...";
168 return {.interactions = {},
179 <<
"' does not exist in memory!";
180 ARMARX_INFO <<
"[InteractionReader] Available core segments:";
183 return {.interactions = {},
185 .errorMessage =
"Core segment not found"};
190 if (
query.providerName.empty())
194 std::vector<HumanRobotInteraction> allInteractions;
196 coreSegment.forEachProviderSegment(
197 [
this, &allInteractions, &
query](
const auto& providerSegment)
199 const std::vector<HumanRobotInteraction> interactions =
201 std::copy(interactions.begin(),
203 std::back_inserter(allInteractions));
206 if (allInteractions.empty())
208 return {.interactions = {},
210 .errorMessage =
"No entities"};
219 if (not coreSegment.hasProviderSegment(
query.providerName))
222 <<
"` does not exist (yet).";
229 coreSegment.getProviderSegment(
query.providerName);
231 if (providerSegment.
empty())
234 return {.interactions = {},
236 .errorMessage =
"No entities"};
243 const auto interactions =
254 std::vector<HumanRobotInteraction>
256 const std::string& lastName,
258 const std::string& providerName)
260 Query queryDefinition =
Query{.providerName = providerName,
264 auto queryResult =
query(queryDefinition,
true);
266 std::vector<HumanRobotInteraction> matchingInteractions;
270 for (
const auto& interaction : queryResult.interactions)
272 if (interaction.personID.has_value() &&
273 interaction.personID.value().firstName == firstName &&
274 interaction.personID.value().lastName == lastName)
276 matchingInteractions.push_back(interaction);
280 if (matchingInteractions.empty())
282 ARMARX_INFO <<
"No interactions found for person " << firstName <<
" "
291 return matchingInteractions;
294 std::optional<HumanRobotInteraction>
296 const std::string& lastName,
297 const std::string& providerName)
299 Query queryDefinition =
Query{.providerName = providerName,
303 auto queryResult =
query(queryDefinition,
true);
308 std::optional<HumanRobotInteraction> latestInteraction;
311 for (
const auto& interaction : queryResult.interactions)
313 if (interaction.personID.has_value() &&
314 interaction.personID.value().firstName == firstName &&
315 interaction.personID.value().lastName == lastName)
317 if (!latestInteraction.has_value() || interaction.startTime > latestTime)
319 latestInteraction = interaction;
320 latestTime = interaction.startTime;
325 if (latestInteraction.has_value())
327 return latestInteraction;
331 ARMARX_INFO <<
"No interactions found for person " << firstName <<
" "
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
static Duration Minutes(std::int64_t minutes)
Constructs a duration in minutes.
bool forEachCoreSegment(CoreSegmentFunctionT &&func)
bool hasCoreSegment(const std::string &name) const
CoreSegmentT & getCoreSegment(const std::string &name)
bool forEachEntity(EntityFunctionT &&func)
QueryResult query(const QueryInput &input) const
Perform a query on the WM.
The query::Builder class provides a fluent-style specification of hierarchical queries.
QueryInput buildQueryInput() const
CoreSegmentSelector & coreSegments()
Start specifying core segments.
CoreSegmentSelector & withName(const std::string &name) override
ProviderSegmentSelector & providerSegments()
Start specifying provider segments.
EntitySelector & all() override
SnapshotSelector & snapshots()
Start specifying entity snapshots.
ProviderSegmentSelector & withName(const std::string &name) override
EntitySelector & entities()
Start specifying entities.
ProviderSegmentSelector & all() override
SnapshotSelector & beforeOrAtTime(Time timestamp)
SnapshotSelector & latest()
const armem::client::Reader & memoryReader() const
const Properties & properties() const
Properties defaultProperties() const override
~InteractionReader() override
std::string propertyPrefix() const override
std::vector< HumanRobotInteraction > queryInteractionsForPerson(const std::string &firstName, const std::string &lastName, const Duration &maxAge, const std::string &providerName="")
::armarx::armem::client::query::Builder buildQuery(const Query &query) const
::armarx::armem::client::query::Builder buildLatestQuery(const Query &query) const
Result query(const Query &query, bool latest) const
std::optional< HumanRobotInteraction > queryLatestInteractionForPerson(const std::string &firstName, const std::string &lastName, const std::string &providerName="")
std::vector< HumanRobotInteraction > asHumanRobotInteractions(const wm::ProviderSegment &providerSegment, const DateTime ×tamp, const Duration &maxAge) const
Represents a point in time.
bool isPositive() const
Tests whether the duration is positive (value in µs > 0).
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#define ARMARX_INFO
The normal logging level.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
void fromAron(const armarx::human::arondto::HumanPose &dto, HumanPose &bo)
armarx::core::time::Duration Duration
std::optional< AronClass > tryCast(const wm::EntityInstance &item)
Tries to cast a armem::EntityInstance to AronClass.
std::string GetHandledExceptionString()
auto & getLatestSnapshot(int snapshotIndex=0)
Retrieve the latest entity snapshot.
wm::Memory memory
The slice of the memory that matched the query.
std::string coreSegmentName