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  this->setDefaultMaxHistorySize(300);
24  Base::defineProperties(defs, prefix);
25  }
26 
27  void
29  {
30  Base::init();
31  }
32 
33  void
35  {
36  // create commit about new update
37  armarx::skills::arondto::SkillStatusUpdate event;
38  armem::toAron(event, update);
39 
40  armem::MemoryID commitId = id();
41  commitId.providerSegmentName = event.skillId.providerId.providerName;
42  commitId.entityName = event.skillId.skillName;
43 
44  auto aron = event.toAron();
45 
46  armem::Commit comm;
47  auto& entityUpdate = comm.add();
48  entityUpdate.confidence = 1.0;
49  entityUpdate.referencedTime = armem::Time::Now();
50  entityUpdate.instancesData = {aron};
51  entityUpdate.entityID = commitId;
52 
54  }
55 
56  std::map<skills::SkillExecutionID, skills::SkillStatusUpdate>
58  {
59  std::map<skills::SkillExecutionID, skills::SkillStatusUpdate> ret;
60  auto coreSegment = this->segmentPtr;
61  ARMARX_CHECK(coreSegment);
62 
63  coreSegment->doLocked([&](){
64  coreSegment->forEachInstance(
65  [&](const armem::wm::EntityInstance& i)
66  {
67  auto event = i.dataAs<armarx::skills::arondto::SkillStatusUpdate>();
69  armem::fromAron(event, up);
70 
71  if (auto it = ret.find(up.executionId); it != ret.end() && up < it->second)
72  {
73  return;
74  }
75 
76  // set or replace
77  ret[up.executionId] = up;
78  });
79  });
80 
81  // for (const auto& [k, v] : ret)
82  // {
83  // ARMARX_IMPORTANT << "Skill " << k.skillId << " has stati: " << int(v.status);
84  // }
85 
86  return ret;
87  }
88 
89  std::optional<skills::SkillStatusUpdate>
91  {
92  std::optional<skills::SkillStatusUpdate> ret = std::nullopt;
93  auto coreSegment = this->segmentPtr;
94  ARMARX_CHECK(coreSegment);
95 
96  coreSegment->doLocked([&](){
97  coreSegment->forEachInstance(
98  [&](const armem::wm::EntityInstance& i)
99  {
100  auto event = i.dataAs<armarx::skills::arondto::SkillStatusUpdate>();
102  armem::fromAron(event, up);
103 
104  if (up.executionId == id)
105  {
106  if (!ret || (ret.has_value() && *ret < up))
107  {
108  ret = up;
109  }
110  }
111  });
112  });
113  return ret;
114  }
115 } // 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:28
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::armem::server::segment::SpecializedCoreSegment::setDefaultMaxHistorySize
void setDefaultMaxHistorySize(int64_t maxHistorySize)
Definition: SpecializedCoreSegment.cpp:75
armarx::skills::segment::SkillEventCoreSegment::getSkillStatusUpdates
std::map< skills::SkillExecutionID, skills::SkillStatusUpdate > getSkillStatusUpdates()
Definition: SkillEventSegment.cpp:57
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::skills::segment::SkillEventCoreSegment::addSkillUpdateEvent
void addSkillUpdateEvent(const skills::SkillStatusUpdate &update)
Definition: SkillEventSegment.cpp:34
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:90
armarx::armem::server::segment::SpecializedCoreSegment::defineProperties
virtual void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix="") override
Definition: SpecializedCoreSegment.cpp:33
armarx::armem::server::MemoryToIceAdapter::commitLocking
data::CommitResult commitLocking(const data::Commit &commitIce, Time timeArrived)
Definition: MemoryToIceAdapter.cpp:166
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28