* @brief Reads a query result set into parallel DSP ring buffers. */
| 291 | * @brief Reads a query result set into parallel DSP ring buffers. |
| 292 | */ |
| 293 | static std::size_t readAxisData(QSqlQuery& rows, |
| 294 | qint64 originNs, |
| 295 | qint64 reservation, |
| 296 | DSP::AxisData& x, |
| 297 | DSP::AxisData& y, |
| 298 | double& globalMin, |
| 299 | double& globalMax) |
| 300 | { |
| 301 | const std::size_t capacity = static_cast<std::size_t>(std::max<qint64>(reservation, 1)); |
| 302 | x.resize(capacity); |
| 303 | y.resize(capacity); |
| 304 | x.clear(); |
| 305 | y.clear(); |
| 306 | |
| 307 | globalMin = std::numeric_limits<double>::infinity(); |
| 308 | globalMax = -std::numeric_limits<double>::infinity(); |
| 309 | std::size_t count = 0; |
| 310 | |
| 311 | constexpr double kInvNs = 1.0 / 1.0e9; |
| 312 | while (rows.next()) { |
| 313 | const double val = SerialStudio::toDouble(rows.value(1)); |
| 314 | if (!std::isfinite(val)) |
| 315 | continue; |
| 316 | |
| 317 | const qint64 ts = rows.value(0).toLongLong(); |
| 318 | const double tSec = static_cast<double>(ts - originNs) * kInvNs; |
| 319 | x.push(tSec); |
| 320 | y.push(val); |
| 321 | |
| 322 | globalMin = std::min(globalMin, val); |
| 323 | globalMax = std::max(globalMax, val); |
| 324 | ++count; |
| 325 | } |
| 326 | |
| 327 | return count; |
| 328 | } |
| 329 | |
| 330 | /** |
| 331 | * @brief Appends @p index to @p indices when it is not already present. |