CosinusProvider.cpp
50 lines
| 1.5 KiB
| text/x-c
|
CppLexer
Alexandre Leroux
|
r120 | #include "CosinusProvider.h" | ||
#include <Data/DataProviderParameters.h> | ||||
#include <Data/ScalarSeries.h> | ||||
r127 | #include <cmath> | |||
r276 | #include <QDateTime> | |||
r336 | #include <QThread> | |||
r276 | ||||
r215 | Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider") | |||
Alexandre Leroux
|
r287 | std::shared_ptr<IDataSeries> | ||
Alexandre Leroux
|
r120 | CosinusProvider::retrieveData(const DataProviderParameters ¶meters) const | ||
{ | ||||
r177 | auto dateTime = parameters.m_Time; | |||
r276 | auto dataIndex = 0; | |||
r215 | ||||
// Gets the timerange from the parameters | ||||
r276 | double freq = 100.0; | |||
double start = dateTime.m_TStart * freq; // 100 htz | ||||
double end = dateTime.m_TEnd * freq; // 100 htz | ||||
r215 | ||||
// We assure that timerange is valid | ||||
if (end < start) { | ||||
std::swap(start, end); | ||||
} | ||||
// Generates scalar series containing cosinus values (one value per second) | ||||
auto scalarSeries | ||||
= std::make_shared<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{}); | ||||
for (auto time = start; time < end; ++time, ++dataIndex) { | ||||
r276 | const auto timeOnFreq = time / freq; | |||
scalarSeries->setData(dataIndex, timeOnFreq, std::cos(timeOnFreq)); | ||||
r215 | } | |||
Alexandre Leroux
|
r120 | return scalarSeries; | ||
} | ||||
Alexandre Leroux
|
r287 | |||
void CosinusProvider::requestDataLoading(const QVector<SqpDateTime> &dateTimeList) | ||||
{ | ||||
r339 | qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataLoading" | |||
<< QThread::currentThread()->objectName(); | ||||
Alexandre Leroux
|
r287 | // NOTE: Try to use multithread if possible | ||
for (const auto &dateTime : dateTimeList) { | ||||
auto scalarSeries = this->retrieveData(DataProviderParameters{dateTime}); | ||||
emit dataProvided(scalarSeries, dateTime); | ||||
} | ||||
} | ||||