Showing the changes to Source/Libraries/TimeSeriesPlatformLibrary/Samples/AverageFrequencyCalculator.cpp (1 of 5 files). Show all
Unified · Split
| @@ -21,13 +21,9 @@ · 20 unmodified lines | ||
| 21 | 21 | // |
| 22 | 22 | //****************************************************************************************************** |
| 23 | 23 | |
| 24 | −#include <iostream> | |
| 25 | −#include <string> | |
| 26 | −#include <vector> | |
| 27 | −#include <map> | |
| 28 | − | |
| 29 | −#include "../Common/Convert.h" | |
| 30 | 24 | #include "../Transport/DataSubscriber.h" |
| 25 | +#include "../Common/Convert.h" | |
| 26 | +#include <iostream> | |
| 31 | 27 | |
| 32 | 28 | using namespace std; |
| 33 | 29 | using namespace GSF; |
| @@ -165,12 +161,7 @@ void ProcessMeasurements(DataSubscriber* source, const vector<MeasurementPtr>& m · 131 unmodified lines | ||
| 165 | 161 | const float64_t HiFrequency = 62.0F; |
| 166 | 162 | const float64_t HzResolution = 1000.0; // three decimal places |
| 167 | 163 | |
| 168 | − const string TimestampFormat = "%Y-%m-%d %H:%M:%S.%f"; | |
| 169 | − const uint32_t MaxTimestampSize = 80; | |
| 170 | − | |
| 171 | − static map<Guid, int> m_lastValues; | |
| 172 | − | |
| 173 | − map<Guid, int>::iterator lastValueIter; | |
| 164 | + static unordered_map<Guid, int> m_lastValues; | |
| 174 | 165 | MeasurementPtr currentMeasurement; |
| 175 | 166 | Guid signalID; |
| 176 | 167 | |
| @@ -182,8 +173,6 @@ void ProcessMeasurements(DataSubscriber* source, const vector<MeasurementPtr>& m · 5 unmodified lines | ||
| 182 | 173 | int32_t lastValue; |
| 183 | 174 | int32_t total; |
| 184 | 175 | |
| 185 | − char timestamp[MaxTimestampSize]; | |
| 186 | − | |
| 187 | 176 | frequencyTotal = 0.0; |
| 188 | 177 | total = 0; |
| 189 | 178 | |
| @@ -191,13 +180,11 @@ void ProcessMeasurements(DataSubscriber* source, const vector<MeasurementPtr>& m · 1 unmodified line | ||
| 191 | 180 | |
| 192 | 181 | if (!measurements.empty()) |
| 193 | 182 | { |
| 194 | − if (TicksToString(timestamp, MaxTimestampSize, TimestampFormat, measurements[0]->Timestamp)) | |
| 195 | − cout << "Timestamp: " << string(timestamp) << endl; | |
| 196 | − | |
| 197 | − cout << "Point\tValue" << endl; | |
| 183 | + cout << "Timestamp: " << ToString(measurements[0]->GetDateTime()) << endl; | |
| 184 | + cout << "\tPoint\tValue" << endl; | |
| 198 | 185 | |
| 199 | 186 | for (uint32_t i = 0; i < measurements.size(); ++i) |
| 200 | − cout << measurements[i]->ID << '\t' << measurements[i]->Value << endl; | |
| 187 | + cout << '\t' << measurements[i]->ID << '\t' << measurements[i]->Value << endl; | |
| 201 | 188 | |
| 202 | 189 | cout << endl; |
| 203 | 190 | |
| @@ -209,14 +196,10 @@ void ProcessMeasurements(DataSubscriber* source, const vector<MeasurementPtr>& m · 5 unmodified lines | ||
| 209 | 196 | adjustedFrequency = static_cast<int32_t>(frequency * HzResolution); |
| 210 | 197 | |
| 211 | 198 | // Do some simple flat line avoidance... |
| 212 | − lastValueIter = m_lastValues.find(signalID); | |
| 213 | − | |
| 214 | − if (lastValueIter != m_lastValues.end()) | |
| 199 | + if (TryGetValue(m_lastValues, signalID, lastValue, 0)) | |
| 215 | 200 | { |
| 216 | − lastValue = lastValueIter->second; | |
| 217 | − | |
| 218 | 201 | if (lastValue == adjustedFrequency) |
| 219 | − frequency = 0.0; | |
| 202 | + frequency = 0.0; // Don't contribute duplicates to the average | |
| 220 | 203 | else |
| 221 | 204 | m_lastValues[signalID] = adjustedFrequency; |
| 222 | 205 | } |