HumanActivityWriter.cpp
Go to the documentation of this file.
2
4
8
11
13{
14
18
20
21 void
26
27 void
29 {
30 ARMARX_VERBOSE << "Connecting ...";
32 ARMARX_VERBOSE << "Connected.";
33
34 reader.connect(memoryNameSystem);
35 }
36
37 bool
39 const std::string& provider,
40 const armem::Time& referencedTime)
41 {
42 return this->commitHumanActivities({activity}, provider, referencedTime);
43 }
44
45 bool
46 ActivityWriter::commitHumanActivities(const std::vector<HumanActivity>& activities,
47 const std::string& provider,
48 const armem::Time& referencedTime)
49 {
50 if (activities.empty())
51 {
52 ARMARX_WARNING << "No activities to commit";
53 return false;
54 }
55
56 try
57 {
58 // Group activities by person (entity)
59 std::map<std::string, std::vector<HumanActivity>> activitiesByPerson;
60
61 for (const HumanActivity& activity : activities)
62 {
63 std::string entityName;
64 if (activity.personID.has_value())
65 {
66 entityName = activity.personID.value().toMemoryEntityID();
67 }
68 else
69 {
70 // If no person ID, use a default entity name
71 entityName = "unknown-person";
72 }
73
74 activitiesByPerson[entityName].push_back(activity);
75 }
76
77 // Commit each entity separately
78 for (const auto& [entityName, entityActivities] : activitiesByPerson)
79 {
80 // Convert activities to DTO
81 std::vector<armarx::aron::data::DictPtr> activityDtos;
82 for (const HumanActivity& activity : entityActivities)
83 {
84 armarx::human::arondto::HumanActivity activityAron;
85 toAron(activityAron, activity);
86 activityDtos.push_back(activityAron.toAron());
87 }
88
89 // Create entity ID
91 armarx::human::HumanActivityCoreSegmentID.withProviderSegmentName(provider)
92 .withEntityName(entityName);
93
94 // Create entity update
96 .entityID = entityId,
97 .instancesData = activityDtos,
98 .referencedTime = referencedTime,
99 .confidence = 1.0F,
100 .sentTime = armarx::armem::Time::Now(),
101 .arrivedTime = armarx::armem::Time::Now(),
102 };
103
104 // Commit the update
105 armem::Commit commit;
106 commit.add(update);
107
108 ARMARX_DEBUG << "Committing " << entityActivities.size()
109 << " activities for entity " << entityName;
110
111 memoryWriter().commit(commit);
112 }
113
114 return true;
115 }
116 catch (...)
117 {
118 ARMARX_WARNING << "Failed to commit human activities: " << GetHandledExceptionString();
119 return false;
120 }
121 }
122
123
124} // namespace armarx::armem::human::client
The memory name system (MNS) client.
CommitResult commit(const Commit &commit) const
Writes a Commit to the memory.
Definition Writer.cpp:68
void connect(armarx::armem::client::MemoryNameSystem &mns)
void registerPropertyDefinitions(armarx::PropertyDefinitionsPtr &def)
void connect(armem::client::MemoryNameSystem &memoryNameSystem)
bool commitHumanActivities(const std::vector< HumanActivity > &activities, const std::string &provider, const armem::Time &referencedTime)
bool commitHumanActivity(const HumanActivity &activity, const std::string &provider, const armem::Time &referencedTime)
void registerPropertyDefinitions(armarx::PropertyDefinitionsPtr &def)
static DateTime Now()
Definition DateTime.cpp:51
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
void toAron(armarx::human::arondto::HumanPose &dto, const HumanPose &bo)
armarx::core::time::DateTime Time
const armem::MemoryID HumanActivityCoreSegmentID
std::string GetHandledExceptionString()
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
A bundle of updates to be sent to the memory.
Definition Commit.h:90
EntityUpdate & add()
Definition Commit.cpp:80
An update of an entity for a specific point in time.
Definition Commit.h:26