MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / loadNumericAggregates

Function loadNumericAggregates

app/src/Sessions/ReportData.cpp:127–155  ·  view source on GitHub ↗

* @brief Runs the single-pass numeric aggregate (count, min, max, mean, stddev) per dataset. */

Source from the content-addressed store, hash-verified

125 * @brief Runs the single-pass numeric aggregate (count, min, max, mean, stddev) per dataset.
126 */
127static bool loadNumericAggregates(QSqlDatabase& db,
128 int sessionId,
129 std::vector<Sessions::DatasetStats>& datasets)
130{
131 QSqlQuery aggQ(db);
132 aggQ.prepare("SELECT unique_id, COUNT(*), MIN(final_numeric_value), MAX(final_numeric_value), "
133 " AVG(final_numeric_value), AVG(final_numeric_value*final_numeric_value) "
134 "FROM readings WHERE session_id = ? AND is_numeric = 1 GROUP BY unique_id");
135 aggQ.bindValue(0, sessionId);
136 if (!aggQ.exec())
137 return false;
138
139 while (aggQ.next()) {
140 const int uid = aggQ.value(0).toInt();
141 auto it = findDatasetByUid(datasets, uid);
142 if (it == datasets.end())
143 continue;
144
145 it->numericSamples = aggQ.value(1).toLongLong();
146 it->minValue = SerialStudio::toDouble(aggQ.value(2));
147 it->maxValue = SerialStudio::toDouble(aggQ.value(3));
148 it->mean = SerialStudio::toDouble(aggQ.value(4));
149 const double meanSq = SerialStudio::toDouble(aggQ.value(5));
150 const double var = std::max(0.0, meanSq - it->mean * it->mean);
151 it->stddev = std::sqrt(var);
152 }
153
154 return true;
155}
156
157/**
158 * @brief Counts non-numeric samples per dataset and stores them on each DatasetStats row.

Callers 1

buildFromSessionMethod · 0.85

Calls 5

findDatasetByUidFunction · 0.85
sqrtFunction · 0.85
execMethod · 0.80
nextMethod · 0.80
valueMethod · 0.45

Tested by

no test coverage detected