Changeset 12909 for fact/Evidence
- Timestamp:
- 02/19/12 17:19:46 (13 years ago)
- Location:
- fact/Evidence
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/Evidence/History.cc
r11088 r12909 23 23 #include <math.h> 24 24 #include <float.h> 25 #include <limits> 25 26 #include <sys/stat.h> 26 27 #include <sys/time.h> … … 44 45 double LastValue; 45 46 double MinAbsChange; 47 pair <unsigned int, unsigned int> Range; 46 48 string Format; 47 49 time_t LastSave; … … 51 53 DimInfo *ServerList; 52 54 char *Directory; 53 string Change;54 55 55 56 void infoHandler(); … … 73 74 74 75 // Get/initialize configuration 75 Change =GetConfig("minchange", " ");76 GetConfig("minchange", " "); 76 77 GetConfig("maxsize_kb", DEFAULT_MAX_SIZE_KB); 77 78 GetConfig("numentries", DEFAULT_NUM_ENTRIES); … … 161 162 } 162 163 163 // If data is number of single type, check minumum change before adding to history 164 if (strcmp(I->getFormat(), "C") != 0) { 165 // Calculate sum of all number in array 166 istringstream Text(EvidenceServer::ToString(I->getFormat(), I->getData(), I->getSize())); 167 double Num, Sum = 0; 168 while (Text.good()) { 169 Text >> Num; 170 Sum += fabs(Num); 171 } 172 173 // Minimum change? 174 if (fabs(Sum-Map[Service].LastValue) < fabs(Map[Service].MinAbsChange)) return; 164 // Check minumum change before adding to history 165 if (Map[Service].MinAbsChange != 0) { 166 double Sum = 0; 167 unsigned int Count = 0; 168 169 // Add values within given range 170 vector<string> Values = Tokenize(EvidenceServer::ToString(I->getFormat(), I->getData(), I->getSize())); 171 172 for (unsigned int i=0; i<Values.size(); i++) { 173 if ((i < Map[Service].Range.first) || (i > Map[Service].Range.second)) continue; 174 175 Sum += atof(Values[i].c_str()); 176 Count++; 177 } 178 179 // Minimum change of average value? 180 if (Count>0 && (fabs(Sum-Map[Service].LastValue)/Count < fabs(Map[Service].MinAbsChange))) return; 175 181 Map[Service].LastValue = Sum; 176 182 } … … 276 282 Map[Name].Format = Format; 277 283 Map[Name].MinAbsChange = 0.0; 284 Map[Name].Range = pair <unsigned int, unsigned int> (0, numeric_limits<unsigned int>::max()); 278 285 Map[Name].LastSave = 0.0; 279 286 280 287 // Set minimum required change if given in configuratrion 288 string Change = GetConfig("minchange"); 281 289 size_t Pos = Change.find(Name+":"); 282 if (Pos != string::npos) Map[Name].MinAbsChange = atof(Change.c_str() + Pos + Name.size() + 1); 283 290 291 if (Pos != string::npos) { 292 vector<string> Parts = Tokenize(Change.substr(Pos, Change.find(' ', Pos)-Pos), ":"); 293 294 // Check if index range is given as well 295 if (Parts.size() == 2) Map[Name].MinAbsChange = atof(Parts[1].c_str()); 296 else if (Parts.size() == 3) { 297 Map[Name].MinAbsChange = atof(Parts[2].c_str()); 298 299 vector<string> Range = Tokenize(Parts[1], "-"); 300 if (Range.size() == 1) Map[Name].Range = pair <unsigned int, unsigned int> (atoi(Range[0].c_str()), atoi(Range[0].c_str())); 301 else if (Range.size() == 2) Map[Name].Range = pair <unsigned int, unsigned int> (atoi(Range[0].c_str()), atoi(Range[1].c_str())); 302 } 303 } 304 305 SendToLog("Subscribing to service '%s': MinAbsChange %f, Index range %u-%u\n", Name.c_str(), Map[Name].MinAbsChange, Map[Name].Range.first, Map[Name].Range.second); 306 284 307 // Load history buffer from file if existing 285 308 FILE *File = OpenFile(Name, "rb"); … … 326 349 if (Map.count(Name) == 0) return; 327 350 351 SendToLog("Unsubscribing service '%s'", Name.c_str()); 352 328 353 // Delete subscription first so handler and not called anymore 329 354 delete Map[Name].DataItem; -
fact/Evidence/readme.txt
r12892 r12909 54 54 6/7/2011 Missing pthread_mutexattr_init() in Evidence constructor caused spurious errors when 55 55 locking mutex 56 2/8/2011 Used inCallback() method of DIM version v19r23 to decide between blocking or non-blocking config request. 57 Updated EvidenceServer::ToString() for B and V formats. 56 2/8/2011 Used inCallback() method of DIM version v19r23 to decide between blocking or 57 non-blocking config request. Updated EvidenceServer::ToString() for B and V formats. 58 16/2/2012 EvidenceServer::ToString() handles more complex single-type formats (e.g. "F:1;F:4;F" 59 18/2/2012 History server detection for minimum change takes an index range given in the configuration 60 into account (e.g. Service:a-b:0.4 requires an minimum absolute change of 0.4 for the average 61 value of indices a to b)
Note:
See TracChangeset
for help on using the changeset viewer.