SkillEventSegment.cpp
Go to the documentation of this file.
1 #include "SkillEventSegment.h"
2 
3 #include <SimoxUtility/algorithm/string.h>
4 
6 #include <RobotAPI/libraries/armem_skills/aron/Skill.aron.generated.h>
9 
11 {
12 
14  Base(iceMemory,
15  CoreSegmentName,
16  armarx::skills::arondto::SkillExecutionRequest::ToAronType())
17  {
18  }
19 
20  void
22  {
23  // No properties! (meaning no name and no max size)
24  }
25 
26  void
28  {
29  Base::init();
30  }
31 
32  void
34  {
35  // create commit about new update
36  armarx::skills::arondto::SkillStatusUpdate event;
37  armem::toAron(event, update);
38 
39  armem::MemoryID commitId = id();
40  commitId.providerSegmentName = event.skillId.providerId.providerName;
41  commitId.entityName = event.skillId.skillName;
42 
43  auto aron = event.toAron();
44 
45  armem::Commit comm;
46  auto& entityUpdate = comm.add();
47  entityUpdate.confidence = 1.0;
48  entityUpdate.referencedTime = armem::Time::Now();
49  entityUpdate.instancesData = {aron};
50  entityUpdate.entityID = commitId;
51 
53  }
54 
55  std::map<skills::SkillExecutionID, skills::SkillStatusUpdate>
57  {
58  std::map<skills::SkillExecutionID, skills::SkillStatusUpdate> ret;
59  auto coreSegment = this->segmentPtr;
60  ARMARX_CHECK(coreSegment);
61 
62  coreSegment->forEachInstance(
63  [&](const armem::wm::EntityInstance& i)
64  {
65  auto event = i.dataAs<armarx::skills::arondto::SkillStatusUpdate>();
67  armem::fromAron(event, up);
68 
69  if (auto it = ret.find(up.executionId); it != ret.end() && up < it->second)
70  {
71  return;
72  }
73 
74  // set or replace
75  ret[up.executionId] = up;
76  });
77 
78  // for (const auto& [k, v] : ret)
79  // {
80  // ARMARX_IMPORTANT << "Skill " << k.skillId << " has stati: " << int(v.status);
81  // }
82 
83  return ret;
84  }
85 
86  std::optional<skills::SkillStatusUpdate>
88  {
89  std::optional<skills::SkillStatusUpdate> ret = std::nullopt;
90  auto coreSegment = this->segmentPtr;
91  ARMARX_CHECK(coreSegment);
92 
93  coreSegment->forEachInstance(
94  [&](const armem::wm::EntityInstance& i)
95  {
96  auto event = i.dataAs<armarx::skills::arondto::SkillStatusUpdate>();
98  armem::fromAron(event, up);
99 
100  if (up.executionId == id)
101  {
102  if (!ret || (ret.has_value() && *ret < up))
103  {
104  ret = up;
105  }
106  }
107  });
108  return ret;
109  }
110 } // namespace armarx::skills::segment
armarx::skills::SkillExecutionID
Definition: SkillExecutionID.h:19
armarx::aron::ret
ReaderT::InputType T & ret
Definition: rw.h:21
skills
This file is part of ArmarX.
armarx::armem::MemoryID::providerSegmentName
std::string providerSegmentName
Definition: MemoryID.h:52
armarx::armem::Commit
A bundle of updates to be sent to the memory.
Definition: Commit.h:89
armarx::armem::wm::EntityInstance
Client-side working entity instance.
Definition: memory_definitions.h:32
armarx::armem::server::MemoryToIceAdapter
Helps connecting a Memory server to the Ice interface.
Definition: MemoryToIceAdapter.h:19
armarx::core::time::DateTime::Now
static DateTime Now()
Definition: DateTime.cpp:55
armarx::armem::EntityUpdate::confidence
float confidence
An optional confidence, may be used for things like decay.
Definition: Commit.h:45
armarx::armem::toAron
void toAron(arondto::MemoryID &dto, const MemoryID &bo)
Definition: aron_conversions.cpp:19
armarx::skills::segment::SkillEventCoreSegment::init
void init()
Definition: SkillEventSegment.cpp:27
ARMARX_CHECK
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
Definition: ExpressionException.h:82
armarx::skills::segment::SkillEventCoreSegment::SkillEventCoreSegment
SkillEventCoreSegment(armem::server::MemoryToIceAdapter &iceMemory)
Definition: SkillEventSegment.cpp:13
NLohmannJSONConverter.h
armarx::skills::SkillExecutionRequest
Definition: SkillExecutionRequest.h:21
armarx::armem::server::segment::detail::SegmentBase< server::wm::CoreSegment >::segmentPtr
server::wm::CoreSegment * segmentPtr
Definition: SpecializedSegment.h:54
armarx::armem::base::EntityInstanceBase::dataAs
AronDtoT dataAs() const
Get the data converted to a generated Aron DTO class.
Definition: EntityInstanceBase.h:157
armarx::skills::SkillStatusUpdate
Definition: SkillStatusUpdate.h:139
armarx::armem::MemoryID
A memory ID.
Definition: MemoryID.h:47
aron_conversions.h
armarx::skills::segment
Definition: ExecutableSkillLibrarySegment.cpp:13
armarx::armem::server::segment::detail::SegmentBase< server::wm::CoreSegment >
armarx::armem::server::segment::SpecializedCoreSegment::init
virtual void init() override
Definition: SpecializedCoreSegment.cpp:49
armarx::armem::MemoryID::entityName
std::string entityName
Definition: MemoryID.h:53
armarx::armem::server::ltm::util::mongodb::detail::update
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition: mongodb.cpp:67
MemoryToIceAdapter.h
armarx::armem::fromAron
void fromAron(const arondto::MemoryID &dto, MemoryID &bo)
Definition: aron_conversions.cpp:8
armarx::armem::Commit::add
EntityUpdate & add()
Definition: Commit.cpp:81
armarx::armem::server::segment::detail::SegmentBase< server::wm::CoreSegment >::iceMemory
MemoryToIceAdapter & iceMemory
Definition: SpecializedSegment.h:60
armarx::skills::segment::SkillEventCoreSegment::getSkillStatusUpdates
std::map< skills::SkillExecutionID, skills::SkillStatusUpdate > getSkillStatusUpdates()
Definition: SkillEventSegment.cpp:56
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::skills::segment::SkillEventCoreSegment::addSkillUpdateEvent
void addSkillUpdateEvent(const skills::SkillStatusUpdate &update)
Definition: SkillEventSegment.cpp:33
armarx::armem::server::segment::detail::SegmentBase< server::wm::CoreSegment >::id
MemoryID & id()
Definition: SpecializedSegment.h:35
SkillEventSegment.h
armarx::skills::segment::SkillEventCoreSegment::defineProperties
void defineProperties(PropertyDefinitionsPtr defs, const std::string &prefix)
Definition: SkillEventSegment.cpp:21
armarx::skills::segment::SkillEventCoreSegment::getSkillStatusUpdate
std::optional< skills::SkillStatusUpdate > getSkillStatusUpdate(const skills::SkillExecutionID &id)
Definition: SkillEventSegment.cpp:87
armarx::armem::server::MemoryToIceAdapter::commitLocking
data::CommitResult commitLocking(const data::Commit &commitIce, Time timeArrived)
Definition: MemoryToIceAdapter.cpp:163
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28