Skip to content
Snippets Groups Projects
Commit 5b8cc2ee authored by m.puchner's avatar m.puchner
Browse files

Merge branch 'issue_67' into 'develop'

allow arbitrary ordering of Q

Closes #67

See merge request !97
parents 92aa5123 cdbc3427
No related branches found
No related tags found
1 merge request!97allow arbitrary ordering of Q
Pipeline #38239 passed
...@@ -208,6 +208,17 @@ void QREDataLoader::deserialize(const QByteArray& data) ...@@ -208,6 +208,17 @@ void QREDataLoader::deserialize(const QByteArray& data)
if (s.status() != QDataStream::Ok) if (s.status() != QDataStream::Ok)
throw DeserializationException::streamError(); throw DeserializationException::streamError();
// If calculationErrors contains the outdated "WrongQOrder": Throw "too old".
// Recalculation seems to be an option, but is difficult to realize since the item's
// data loading takes place at another spot in the loading process (to keep compatibility).
// Taking the little likelihood of such a file in an old project into account, it seems to
// be not worth the effort to implement compatibility for such a project.
// #baProjectCompatibility If it is decided to break project compatibility, these lines can be
// removed, as well as the type WrongQOrder itself.
for (const auto& error : m_importResult.calculationErrors.values())
if (error.type == ErrorDefinition::wrongQOrder)
throw DeserializationException::tooOld();
} }
AbstractDataLoader* QREDataLoader::clone() const AbstractDataLoader* QREDataLoader::clone() const
...@@ -461,7 +472,6 @@ void QREDataLoader::calculateFromParseResult() const ...@@ -461,7 +472,6 @@ void QREDataLoader::calculateFromParseResult() const
const int eCol = c[DataType::dR].column; const int eCol = c[DataType::dR].column;
QSet<double> foundQValues; QSet<double> foundQValues;
double lastFoundQ = std::numeric_limits<double>::quiet_NaN();
for (int lineNr = 0; lineNr < m_importResult.lines.size(); lineNr++) { for (int lineNr = 0; lineNr < m_importResult.lines.size(); lineNr++) {
const bool skipLine = m_importResult.lines[lineNr].first; const bool skipLine = m_importResult.lines[lineNr].first;
...@@ -504,11 +514,6 @@ void QREDataLoader::calculateFromParseResult() const ...@@ -504,11 +514,6 @@ void QREDataLoader::calculateFromParseResult() const
continue; continue;
} }
if (!std::isnan(lastFoundQ) && q <= lastFoundQ) {
m_importResult.addError(lineNr, ErrorDefinition::wrongQOrder);
continue;
}
if (r > 1.0) { if (r > 1.0) {
m_importResult.addError(lineNr, ErrorDefinition::RGreaterOne, r); m_importResult.addError(lineNr, ErrorDefinition::RGreaterOne, r);
continue; continue;
...@@ -524,22 +529,31 @@ void QREDataLoader::calculateFromParseResult() const ...@@ -524,22 +529,31 @@ void QREDataLoader::calculateFromParseResult() const
m_importResult.eValues[lineNr] = e; m_importResult.eValues[lineNr] = e;
m_importResult.validCalculatedLines++; m_importResult.validCalculatedLines++;
foundQValues << q; foundQValues << q;
lastFoundQ = q;
} }
} }
void QREDataLoader::createOutputDataFromParsingResult(RealDataItem* item) const void QREDataLoader::createOutputDataFromParsingResult(RealDataItem* item) const
{ {
// -- create OutputData // create data sorted by ascending Q values.
std::vector<double> qVec; // For this, the line numbers are sorted by Q
std::vector<double> rVec; QVector<int> lineNumbers;
for (int lineNr = 0; lineNr < m_importResult.lines.size(); lineNr++) { for (int lineNr = 0; lineNr < m_importResult.lines.size(); lineNr++) {
const bool skipLine = m_importResult.lines[lineNr].first; const bool skipLine = m_importResult.lines[lineNr].first;
const bool lineHasError = m_importResult.calculationErrors.contains(lineNr); const bool lineHasError = m_importResult.calculationErrors.contains(lineNr);
if (skipLine || lineHasError) if (skipLine || lineHasError)
continue; continue;
lineNumbers.push_back(lineNr);
}
std::sort(lineNumbers.begin(), lineNumbers.end(),
[&](int a, int b) { return m_importResult.qValues[a] < m_importResult.qValues[b]; });
// -- create OutputData
std::vector<double> qVec;
std::vector<double> rVec;
for (auto lineNr : lineNumbers) {
qVec.push_back(m_importResult.qValues[lineNr]); qVec.push_back(m_importResult.qValues[lineNr]);
rVec.push_back(m_importResult.rValues[lineNr]); rVec.push_back(m_importResult.rValues[lineNr]);
} }
......
...@@ -85,7 +85,7 @@ private: ...@@ -85,7 +85,7 @@ private:
none = 0, none = 0,
columnDoesNotContainValidNumber = 1, columnDoesNotContainValidNumber = 1,
duplicateQ = 2, duplicateQ = 2,
wrongQOrder = 3, wrongQOrder = 3, // outdated, but kept for backwards compatibility (deserialize!)
RGreaterOne = 4, RGreaterOne = 4,
RLessZero = 5 RLessZero = 5
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment