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