/* Private functions */
-void DataManager::generateRawDataWriteList(DataFileExporter::WriteList& writeList, std::shared_ptr<const QObject> data)
+void DataManager::generateIntegDataWriteList(DataFileExporter::WriteList& writeList, const std::shared_ptr<SingleRunData> sr, const std::vector<std::string> &keys)
{
- QVariantList header;
- std::vector<QVariantList> lines;
- std::pair<QVariantList, std::vector<QVariantList>> p;
- std::string dname;
- std::shared_ptr<const Signal> sig;
-
- try {
- sig = std::dynamic_pointer_cast<const Signal>(data);
- } catch (std::bad_cast&) {
- return;
+ for (const std::string& key : keys) {
+ QVariantList header;
+ std::vector<QVariantList> lines;
+ std::pair<QVariantList, std::vector<QVariantList>> p;
+ const std::shared_ptr<SignalController> ctrl = sr->controllerAt(key);
+ std::shared_ptr<const Integrator> integrator;
+ if (ctrl == nullptr)
+ continue;
+
+ header << "time [" + QString::fromStdString(ctrl->signal()->xunitToString()) + "]" << "area [" + QString::fromStdString(ctrl->signal()->xunitToString()) + " "
+ + QString::fromStdString(ctrl->signal()->yunitToString()) + "]" << "width [" + QString::fromStdString(ctrl->signal()->xunitToString()) + "]"
+ << "height [" + QString::fromStdString(ctrl->signal()->yunitToString()) + "]";
+ integrator = ctrl->cIntegrator();
+ for (std::multimap<size_t, std::shared_ptr<IntegratedPeak>>::const_iterator cit = integrator->peaksCBegin();
+ cit != integrator->peaksCEnd(); cit++) {
+ QVariantList line;
+ line << cit->second->peakTime() << cit->second->auc() << cit->second->width() << cit->second->height();
+ lines.push_back(line);
+ }
+ p = std::pair<QVariantList, std::vector<QVariantList>>(header, lines);
+ writeList[key] = p;
}
+}
- dname = sig->descriptiveName();
-
- /* Create header */
- header << QString("time [" + QString::fromStdString(sig->xunitToString()) + "]") << QString("value [" + QString::fromStdString(sig->yunitToString()) + "]");
- for (const Signal::TimeValuePair& tvp : sig->values()) {
- QVariantList line;
- line << tvp.first << tvp.second;
- lines.push_back(line);
- }
- p = std::pair<QVariantList, std::vector<QVariantList>>(header, lines);
- writeList[dname] = p;
+void DataManager::generateRawDataWriteList(DataFileExporter::WriteList& writeList, const std::shared_ptr<SingleRunData> sr, const std::vector<std::string>& keys)
+{
+ for (const std::string& key : keys) {
+ QVariantList header;
+ std::vector<QVariantList> lines;
+ std::pair<QVariantList, std::vector<QVariantList>> p;
+ const std::shared_ptr<Signal> sig = sr->signalAt(key);
+ if (sig == nullptr)
+ continue;
+
+ /* Create header */
+ header << QString("time [" + QString::fromStdString(sig->xunitToString()) + "]") << QString("value [" + QString::fromStdString(sig->yunitToString()) + "]");
+ for (const Signal::TimeValuePair& tvp : sig->values()) {
+ QVariantList line;
+ line << tvp.first << tvp.second;
+ lines.push_back(line);
+ }
+
+ p = std::pair<QVariantList, std::vector<QVariantList>>(header, lines);
+ writeList[key] = p;
+ }
}
std::shared_ptr<Sequence> DataManager::sequenceByKey(const QString& key)
}
}
-void DataManager::processDataExport(std::function<void (DataFileExporter::WriteList&, std::shared_ptr<const QObject>)> genfunc)
+void DataManager::processDataExport(GeneratorFunc genfunc)
{
DataFileExporter exporter(this);
ExportRawDataDialog dlg(DataFileExporter::SUPPORTED_FORMATS);
DataFileExporter::WriteList writeList;
DataFileExporter::ReturnCode ret;
- std::shared_ptr<SingleRunData> srd = m_activeSequence->selectedRun();
+ std::shared_ptr<SingleRunData> sr = m_activeSequence->selectedRun();
- //for (uint idx = 0; idx < m_activeSequence->selectedRun()->signalCount(); idx++)
- //dlg.addAvailableSignal(m_activeSequence->selectedRun()->signalAt(idx)->descriptiveName());
- for (const std::string& s : srd->allKeys())
+ for (const std::string& s : sr->allKeys())
dlg.addAvailableSignal(QString::fromStdString(s));
do {
int dret = dlg.exec();
if (dret == QDialog::Rejected)
return;
- else if (dret == QDialog::Accepted && dlg.selectedSignalsCount() < 1) {
+ else if (dret == QDialog::Accepted && !dlg.isSignalSelected()) {
QMessageBox::information(nullptr, "Data export error", "No signals selected");
ret = DataFileExporter::ReturnCode::E_TRYAGAIN;
- } else if (dret == QDialog::Accepted && dlg.selectedSignalsCount() >= 1) {
+ } else if (dret == QDialog::Accepted && dlg.isSignalSelected()) {
+ std::vector<std::string> selKeys = dlg.selectedSignalKeys();
/* Generate data to export */
- for (int idx = 0; idx < dlg.signalsCount(); idx++) {
- if (dlg.isSignalSelected(idx));
- //genfunc(writeList, m_activeSequence->selectedRun()->signalAt(idx));
- }
+ genfunc(writeList, sr, selKeys);
ret = exporter.exportData(writeList, dlg.destination(), dlg.format());
}
} while (ret == DataFileExporter::ReturnCode::E_TRYAGAIN);
void DataManager::onExportPeaks()
{
- std::vector<std::shared_ptr<const SignalController>> ctrls;
-
if (m_activeSequence == nullptr)
return;
- if (m_activeSequence->selectedRun() == nullptr)
- return;
-
-
- //std::function<void (DataFileExporter::WriteList&, std::shared_ptr<const QObject>)> f = std::bind(&DataManager::generateIntegDataWriteList, this, std::placeholders::_1, std::placeholders::_2);
- //processDataExport(f);
+ GeneratorFunc f = std::bind(&DataManager::generateIntegDataWriteList, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
+ processDataExport(f);
}
void DataManager::onExportRawData()
{
if (m_activeSequence == nullptr)
return;
- if (m_activeSequence->selectedRun() == nullptr)
- return;
- std::function<void (DataFileExporter::WriteList&, std::shared_ptr<const QObject>)> f = std::bind(&DataManager::generateRawDataWriteList, this, std::placeholders::_1, std::placeholders::_2);
+ GeneratorFunc f = std::bind(&DataManager::generateRawDataWriteList, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
processDataExport(f);
}
#include <QtCore/QTime>
#include "metatypes.h"
+typedef std::function<void (DataFileExporter::WriteList&, const std::shared_ptr<SingleRunData>, std::vector<std::string>&)> GeneratorFunc;
class DataManager : public QObject
{
private:
Signal::Equipment equipmentFromFiletype(AGRE_Filetype filetype);
- void generateIntegDataWriteList(DataFileExporter::WriteList& writeList, std::shared_ptr<const QObject> data);
- void generateRawDataWriteList(DataFileExporter::WriteList& writeList, std::shared_ptr<const QObject> data);
+ void generateIntegDataWriteList(DataFileExporter::WriteList& writeList, const std::shared_ptr<SingleRunData> sr, const std::vector<std::string>& keys);
+ void generateRawDataWriteList(DataFileExporter::WriteList& writeList, const std::shared_ptr<SingleRunData> sr, const std::vector<std::string>& keys);
std::shared_ptr<Sequence> sequenceByKey(const QString& key);
int sequenceIdxByKey(const QString& key);
std::shared_ptr<SingleRunData> loadSingleRun(QDir& dir);
- void processDataExport(std::function<void (DataFileExporter::WriteList&, std::shared_ptr<const QObject>)> genfunc);
+ void processDataExport(GeneratorFunc genfunc);
Signal::Resource resourceFromFiletype(AGRE_Filetype filetype);
std::string signalControllerKey(const QString& main, const QString& resource) ;
void showOneSignal(std::shared_ptr<SignalController> ctrl);
std::unordered_map<std::string, std::shared_ptr<Signal>>& sigs, std::unordered_map<std::string, std::shared_ptr<SignalController>>& ctrls,
const QString& dirname, QObject* parent = nullptr);
std::vector<std::string> allKeys() const;
- std::shared_ptr<SignalController> controllerAt(const std::string& key) { return m_ctrls.at(key); }
+ std::shared_ptr<SignalController> controllerAt(const std::string& key);
QDate date() const { return m_date; }
QString dirName() const { return m_dirName; }
QString methodName() const { return m_methodName; }
QString operatorName() const { return m_operatorName; }
QString sampleInfo() const { return m_sampleInfo; }
- std::shared_ptr<Signal> signalAt(const std::string& key) { return m_signals.at(key); }
+ std::shared_ptr<Signal> signalAt(const std::string& key);
const std::unordered_map<std::string, std::shared_ptr<Signal>>& allSignals() const { return m_signals; }
size_t signalCount() const { return m_signals.size(); }
QTime time() const { return m_time; }