UniSet 2.32.1
ClickHouseTagsConfig.h
1// --------------------------------------------------------------------------
2#ifndef ClickHouseTagsConfig_H_
3#define ClickHouseTagsConfig_H_
4// --------------------------------------------------------------------------
5#include <memory>
6#include <unordered_map>
7#include <string>
8#include "Configuration.h"
9//------------------------------------------------------------------------------------------
10namespace uniset
11{
12 //------------------------------------------------------------------------------------------
87 {
88
89 public:
92
93 // init all tags from configure
94 void load( const std::shared_ptr<uniset::Configuration> conf
95 , const std::string& filter_field = ""
96 , const std::string& filter_value = "" );
97
98
99 // init tags map from section <cnodename>
100 void loadTagsMap( uniset::UniXML::iterator it );
101
102 // init tags for sensor
103 void initFromItem( const std::shared_ptr<uniset::Configuration> conf
104 , const uniset::UniXML::iterator& it );
105
106 struct Tag
107 {
108 std::string key;
109 std::string value;
110 const std::string orig_key;
111 const std::string orig_value;
112
113 Tag( const std::string& _key
114 , const std::string& _val
115 , const std::string& _orig_key
116 , const std::string& _orig_val):
117 key(_key),
118 value(_val),
119 orig_key(_orig_key),
120 orig_value(_orig_val)
121 {}
122 };
123
124 // parse string "key1=val1 key2=val2 key3=val3"
125 static std::vector<Tag> parseTags( const std::string& s_tags, const char sep = ' ');
126
127 std::vector<Tag> getTags( uniset::ObjectId id );
128
129 bool updateTags( uniset::ObjectId id, long value );
130
131 size_t getTagsCount() const;
132 size_t getSensorsCount() const;
133
134 using StateMap = std::unordered_map<uniset::ObjectId, long>;
135
136 std::vector<uniset::ObjectId> getAskedSensors() const;
137
138 protected:
139
140 // текущее значение датчиков по которым формируются теги (map<id,value>)
141 StateMap::iterator addState( uniset::ObjectId sid, long defval );
142
143 StateMap smap;
144
145 struct Range
146 {
147 long vmin;
148 long vmax;
149 bool checkInRange( long value ) const;
150 void updateText( long value );
151 std::vector<Tag> tags;
152
153 bool needReplaceKey = {true};
154 bool needReplaceVal = {true};
155 };
156
157 // value --> tags
158 using RangeList = std::list<Range>;
159
160 RangeList initRangeList( uniset::UniXML::iterator it );
161
162 // name --> range list
163 using TagsMap = std::unordered_map<std::string, RangeList>;
164 TagsMap tagsmap; // список тегов
165 TagsMap initTagsMap( uniset::UniXML::iterator it );
166
167 struct TagsInfo
168 {
169 std::vector<Tag> any_tags; // if not empty, work for any value
170 TagsMap::iterator vit;
171 StateMap::iterator it;
172 long prev_value = { 0 };
173 bool initOk = { false };
175 };
176
177 using TagList = std::list<TagsInfo>;
178 TagList::iterator addTagsInfo( TagList& lst, uniset::ObjectId sid );
179 std::vector<Tag> makeTags( TagList& lst );
180
181 // map<sensorID,TagList>
182 std::unordered_map<uniset::ObjectId, TagList> tags;
183
184 void initDynamicTags();
185 void initFromTags( const std::shared_ptr<uniset::Configuration>& conf, uniset::UniXML::iterator it, const std::string& s_tags );
186 void initFromValues( const std::shared_ptr<uniset::Configuration>& conf, uniset::UniXML::iterator it, const std::string& s_values );
187 void initFromTagsList( const std::shared_ptr<uniset::Configuration>& conf, uniset::UniXML::iterator it, uniset::UniXML::iterator itList );
188 };
189 //------------------------------------------------------------------------------------------
190} // end of namespace Theatre
191//------------------------------------------------------------------------------------------
192#endif
Definition ClickHouseTagsConfig.h:87
Definition UniXML.h:44
Definition Calibration.h:27
KeyType key(const uniset::ObjectId id, const uniset::ObjectId node)
Definition UniSetTypes.cc:980
const ObjectId DefaultObjectId
Definition UniSetTypes.h:71
long ObjectId
Definition UniSetTypes_i.idl:30
Definition ClickHouseTagsConfig.h:146
Definition ClickHouseTagsConfig.h:107
Definition ClickHouseTagsConfig.h:168