HumanProfileWriter.cpp
Go to the documentation of this file.
2
4
6
8
10{
11
15
17
18 void
23
24 void
26 {
27 ARMARX_VERBOSE << "Connecting ...";
29 ARMARX_VERBOSE << "Connected.";
30
31 humanMemory =
32 armem::human::HumanMemoryServerInterfacePrx::checkedCast(this->memoryWriter().memory);
33
34 reader.connect(memoryNameSystem);
35 }
36
37 bool
39 const std::string& provider,
40 const armem::Time& referencedTime,
41 const std::string& entityName)
42 {
43 std::string entityNameAdjusted = entityName;
44 if (entityName == "")
45 {
46 entityNameAdjusted = (humanProfile.id.firstName + "-" + humanProfile.id.lastName);
47 ARMARX_INFO << "Setting entity name to " << entityNameAdjusted;
48 }
49 this->commitHumanProfiles({humanProfile}, provider, referencedTime, entityNameAdjusted);
50 return true;
51 }
52
53 bool
55 const std::string& providerName,
56 const armem::Time& referencedTime,
57 const armarx::armem::human::Preferences preferences)
58 {
60 try
61 {
62 profile = this->reader.queryLatestProfileByName(
63 personID.firstName, personID.lastName, providerName);
64 }
65 catch (...)
66 {
67 ARMARX_WARNING << "You are trying to commit preferences to a profile which cannot be "
68 "read (maybe it does not exist?)";
69 return false;
70 }
71
72 profile.preferences = preferences;
73 this->commitHumanProfile(profile, providerName, referencedTime);
74
75 ARMARX_DEBUG << "Committed adjusted profile with new preferences for " << personID.firstName
76 << " " << personID.lastName;
77
78 return true;
79 }
80
81 bool
83 const std::string& providerName,
84 const armem::Time& referencedTime,
85 const std::string key,
86 const std::string value)
87
88 {
90 try
91 {
92 profile = this->reader.queryLatestProfileByName(
93 personID.firstName, personID.lastName, providerName);
94 if (profile.id.firstName == "")
95 {
96 return false;
97 }
98 }
99 catch (...)
100 {
101 ARMARX_WARNING << "You are trying to commit preferences to a profile which cannot be "
102 "read (maybe it does not exist?)";
103 return false;
104 }
105
106 int customAttributeCountBefore = profile.customAttributes.size();
107 ARMARX_INFO << "Amount of custom attributes before: " << customAttributeCountBefore;
108 profile.customAttributes[key] = value;
109 if (profile.customAttributes.size() == (customAttributeCountBefore + 1))
110 {
111 ARMARX_INFO << "Added additional attribute for " << personID.firstName << " "
112 << personID.lastName << " successfully";
113 }
114 else
115 {
116 ARMARX_INFO << "Changed existing attribute for " << personID.firstName << " "
117 << personID.lastName << " successfully";
118 }
119 ARMARX_INFO << "Amount of custom attributes before commiting: "
120 << profile.customAttributes.size();
121 this->commitHumanProfile(profile, providerName, referencedTime);
122
123 ARMARX_DEBUG << "Committed adjusted profile with new preferences for " << personID.firstName
124 << " " << personID.lastName;
125
126 return true;
127 }
128
129 bool
130 ProfileWriter::commitHumanProfiles(const std::vector<Person>& humanProfiles,
131 const std::string& provider,
132 const armem::Time& referencedTime,
133 const std::string& entityName)
134 {
135 std::vector<armarx::aron::data::dto::DictPtr> humanProfilesDto;
136 for (const Person& humanProfile : humanProfiles)
137 {
138 armarx::human::arondto::Person humanProfileAron;
139 toAron(humanProfileAron, humanProfile);
140 humanProfilesDto.push_back(humanProfileAron.toAronDTO());
141 }
142
143 core::time::dto::DateTime referencedTimeDto;
144 toIce(referencedTimeDto, referencedTime);
145 try
146 {
147 humanMemory->commitHumanProfiles(
148 humanProfilesDto, provider, referencedTimeDto, entityName);
149 return true;
150 }
151 catch (...)
152 {
153 ARMARX_INFO << "Failed to commit human profiles: " << GetHandledExceptionString();
154 return false;
155 }
156 }
157
158 bool
160 const std::string& providerName,
161 const armem::Time& referencedTime,
162 const std::string& drink)
163 {
164 Preferences preferences;
165
166 try
167 {
168 preferences = this->reader.queryPreferences(
169 personID.firstName, personID.lastName, armarx::Duration::Hours(1000), providerName);
170 }
171 catch (...)
172 {
173 ARMARX_WARNING << "You are trying to set preferred drinks on a profile which could not "
174 "be read (maybe it does not exist?)";
175 return false;
176 }
177
178 if (!preferences.drink)
179 preferences.drink.emplace();
180
181 // Filter out duplicates
182 preferences.drink->preferred.erase(std::remove(preferences.drink->preferred.begin(),
183 preferences.drink->preferred.end(),
184 drink),
185 preferences.drink->preferred.end());
186
187 // We will insert the new preference at the beginning, implicitly conveying it is the "number one" preferred (-> favorite) drink
188 // This way, we don't loose prior information about other liked drinks
189 preferences.drink->preferred.insert(preferences.drink->preferred.begin(), drink);
190
191 return this->commitPreferencesToProfile(personID, providerName, referencedTime, preferences);
192 }
193
194
195} // namespace armarx::armem::human::client
static Duration Hours(std::int64_t hours)
Constructs a duration in hours.
Definition Duration.cpp:120
The memory name system (MNS) client.
void connect(armarx::armem::client::MemoryNameSystem &mns)
void registerPropertyDefinitions(armarx::PropertyDefinitionsPtr &def)
void connect(armem::client::MemoryNameSystem &memoryNameSystem)
bool commitHumanProfiles(const std::vector< Person > &humanProfiles, const std::string &provider, const armem::Time &referencedTime, const std::string &entityName)
bool commitPreferencesToProfile(const armarx::armem::human::PersonID &personID, const std::string &providerName, const armem::Time &referencedTime, const armarx::armem::human::Preferences preferences)
bool commitHumanProfile(const Person &humanProfile, const std::string &provider, const armem::Time &referencedTime, const std::string &entityName="")
bool setCustomAttributeInProfile(const armarx::armem::human::PersonID &personID, const std::string &providerName, const armem::Time &referencedTime, const std::string key, const std::string value)
bool setPreferredDrink(const armarx::armem::human::PersonID &personID, const std::string &providerName, const armem::Time &referencedTime, const std::string &drink)
Inserts the given drink at the first place of the given humans list of preferred drinks,...
void registerPropertyDefinitions(armarx::PropertyDefinitionsPtr &def)
Brief description of class memory.
Definition memory.h:39
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#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
void toIce(data::MemoryID &ice, const MemoryID &id)
std::string GetHandledExceptionString()
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
std::map< std::string, std::string > customAttributes
Definition types.h:218
std::optional< Preference > drink
Definition types.h:184