mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#2003 Observed Data : Refactor creation of time steps
This commit is contained in:
@@ -66,7 +66,7 @@ bool RifColumnBasedUserData::parse(const QString& data, QString* errorText)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTimeStepsFromTables();
|
buildTimeStepsAndMappings();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@@ -133,123 +133,137 @@ std::string RifColumnBasedUserData::unitName(const RifEclipseSummaryAddress& res
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RifColumnBasedUserData::buildTimeStepsFromTables()
|
void RifColumnBasedUserData::buildTimeStepsAndMappings()
|
||||||
{
|
{
|
||||||
for (size_t tableIndex = 0; tableIndex < m_parser->tableData().size(); tableIndex++)
|
for (size_t tableIndex = 0; tableIndex < m_parser->tableData().size(); tableIndex++)
|
||||||
{
|
{
|
||||||
auto tableData = m_parser->tableData()[tableIndex];
|
auto tableData = m_parser->tableData()[tableIndex];
|
||||||
|
|
||||||
// Find time index
|
std::vector<time_t> timeStepsForTable = createTimeSteps(tableData);
|
||||||
size_t dateColumnIndex = tableData.columnInfos().size();
|
|
||||||
size_t dayOrYearColumnIndex = tableData.columnInfos().size();
|
if (timeStepsForTable.empty())
|
||||||
size_t yearXColumnIndex = tableData.columnInfos().size();
|
{
|
||||||
|
RiaLogging::warning(QString("Failed to find time data for table %1 in file %2").arg(tableIndex));
|
||||||
|
RiaLogging::warning(QString("No data for this table is imported"));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_timeSteps.push_back(timeStepsForTable);
|
||||||
|
|
||||||
for (size_t columIndex = 0; columIndex < tableData.columnInfos().size(); columIndex++)
|
for (size_t columIndex = 0; columIndex < tableData.columnInfos().size(); columIndex++)
|
||||||
{
|
{
|
||||||
const ColumnInfo& ci = tableData.columnInfos()[columIndex];
|
const ColumnInfo& ci = tableData.columnInfos()[columIndex];
|
||||||
if (dateColumnIndex == tableData.columnInfos().size() &&
|
if (!ci.isStringData)
|
||||||
RifEclipseUserDataKeywordTools::isDate(ci.summaryAddress.quantityName()))
|
|
||||||
{
|
{
|
||||||
dateColumnIndex = columIndex;
|
RifEclipseSummaryAddress sumAddress = ci.summaryAddress;
|
||||||
}
|
|
||||||
|
|
||||||
if (dayOrYearColumnIndex == tableData.columnInfos().size() &&
|
|
||||||
RifEclipseUserDataParserTools::hasTimeUnit(ci.unitName))
|
|
||||||
{
|
|
||||||
dayOrYearColumnIndex = columIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (yearXColumnIndex == tableData.columnInfos().size() &&
|
m_allResultAddresses.push_back(sumAddress);
|
||||||
ci.summaryAddress.quantityName() == "YEARX")
|
|
||||||
{
|
|
||||||
yearXColumnIndex = columIndex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dateColumnIndex == tableData.columnInfos().size() &&
|
m_mapFromAddressToTimeStepIndex[sumAddress] = m_timeSteps.size() - 1;
|
||||||
dayOrYearColumnIndex == tableData.columnInfos().size())
|
m_mapFromAddressToResultIndex[sumAddress] = std::make_pair(tableIndex, columIndex);
|
||||||
{
|
|
||||||
RiaLogging::warning(QString("Failed to find time data for table %1 in file %2").arg(tableIndex));
|
|
||||||
RiaLogging::warning(QString("No data for this table is imported"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_timeSteps.resize(m_timeSteps.size() + 1);
|
|
||||||
std::vector<time_t>& timeSteps = m_timeSteps.back();
|
|
||||||
|
|
||||||
if (dateColumnIndex != tableData.columnInfos().size())
|
|
||||||
{
|
|
||||||
const ColumnInfo& ci = tableData.columnInfos()[dateColumnIndex];
|
|
||||||
|
|
||||||
QString dateFormat;
|
|
||||||
for (auto s : ci.stringValues)
|
|
||||||
{
|
|
||||||
QDateTime dt = RiaDateStringParser::parseDateString(s);
|
|
||||||
|
|
||||||
timeSteps.push_back(dt.toTime_t());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (yearXColumnIndex != tableData.columnInfos().size())
|
|
||||||
{
|
|
||||||
const ColumnInfo& ci = tableData.columnInfos()[yearXColumnIndex];
|
|
||||||
|
|
||||||
for (const auto& timeStepValue : ci.values)
|
|
||||||
{
|
|
||||||
QDateTime dateTime = RiaQDateTimeTools::fromYears(timeStepValue);
|
|
||||||
timeSteps.push_back(dateTime.toTime_t());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QDateTime startDate = RiaQDateTimeTools::epoch();
|
|
||||||
|
|
||||||
if (!tableData.startDate().empty())
|
|
||||||
{
|
|
||||||
QDateTime candidate = RiaDateStringParser::parseDateString(tableData.startDate());
|
|
||||||
if (candidate.isValid())
|
|
||||||
{
|
|
||||||
startDate = candidate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dayOrYearColumnIndex != tableData.columnInfos().size())
|
|
||||||
{
|
|
||||||
const ColumnInfo& ci = tableData.columnInfos()[dayOrYearColumnIndex];
|
|
||||||
|
|
||||||
QString unit = QString::fromStdString(ci.unitName).trimmed().toUpper();
|
|
||||||
|
|
||||||
if (unit == "DAY" || unit == "DAYS")
|
|
||||||
{
|
|
||||||
for (const auto& timeStepValue : ci.values)
|
|
||||||
{
|
|
||||||
QDateTime dateTime = RiaQDateTimeTools::addDays(startDate, timeStepValue);
|
|
||||||
timeSteps.push_back(dateTime.toTime_t());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (unit == "YEAR" || unit == "YEARS")
|
|
||||||
{
|
|
||||||
for (const auto& timeStepValue : ci.values)
|
|
||||||
{
|
|
||||||
QDateTime dateTime = RiaQDateTimeTools::addYears(startDate, timeStepValue);
|
|
||||||
timeSteps.push_back(dateTime.toTime_t());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t columIndex = 0; columIndex < tableData.columnInfos().size(); columIndex++)
|
|
||||||
{
|
|
||||||
const ColumnInfo& ci = tableData.columnInfos()[columIndex];
|
|
||||||
if (!ci.isStringData)
|
|
||||||
{
|
|
||||||
RifEclipseSummaryAddress sumAddress = ci.summaryAddress;
|
|
||||||
|
|
||||||
m_allResultAddresses.push_back(sumAddress);
|
|
||||||
|
|
||||||
m_mapFromAddressToTimeStepIndex[sumAddress] = m_timeSteps.size() - 1;
|
|
||||||
m_mapFromAddressToResultIndex[sumAddress] = std::make_pair(tableIndex, columIndex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
std::vector<time_t> RifColumnBasedUserData::createTimeSteps(const TableData& tableData)
|
||||||
|
{
|
||||||
|
std::vector<time_t> tsVector;
|
||||||
|
|
||||||
|
// Find time index
|
||||||
|
size_t dateColumnIndex = tableData.columnInfos().size();
|
||||||
|
size_t dayOrYearColumnIndex = tableData.columnInfos().size();
|
||||||
|
size_t yearXColumnIndex = tableData.columnInfos().size();
|
||||||
|
|
||||||
|
for (size_t columIndex = 0; columIndex < tableData.columnInfos().size(); columIndex++)
|
||||||
|
{
|
||||||
|
const ColumnInfo& ci = tableData.columnInfos()[columIndex];
|
||||||
|
if (dateColumnIndex == tableData.columnInfos().size() &&
|
||||||
|
RifEclipseUserDataKeywordTools::isDate(ci.summaryAddress.quantityName()))
|
||||||
|
{
|
||||||
|
dateColumnIndex = columIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dayOrYearColumnIndex == tableData.columnInfos().size() &&
|
||||||
|
RifEclipseUserDataParserTools::hasTimeUnit(ci.unitName))
|
||||||
|
{
|
||||||
|
dayOrYearColumnIndex = columIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (yearXColumnIndex == tableData.columnInfos().size() &&
|
||||||
|
ci.summaryAddress.quantityName() == "YEARX")
|
||||||
|
{
|
||||||
|
yearXColumnIndex = columIndex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dateColumnIndex < tableData.columnInfos().size() ||
|
||||||
|
dayOrYearColumnIndex < tableData.columnInfos().size())
|
||||||
|
{
|
||||||
|
if (dateColumnIndex != tableData.columnInfos().size())
|
||||||
|
{
|
||||||
|
const ColumnInfo& ci = tableData.columnInfos()[dateColumnIndex];
|
||||||
|
|
||||||
|
QString dateFormat;
|
||||||
|
for (auto s : ci.stringValues)
|
||||||
|
{
|
||||||
|
QDateTime dt = RiaDateStringParser::parseDateString(s);
|
||||||
|
|
||||||
|
tsVector.push_back(dt.toTime_t());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (yearXColumnIndex != tableData.columnInfos().size())
|
||||||
|
{
|
||||||
|
const ColumnInfo& ci = tableData.columnInfos()[yearXColumnIndex];
|
||||||
|
|
||||||
|
for (const auto& timeStepValue : ci.values)
|
||||||
|
{
|
||||||
|
QDateTime dateTime = RiaQDateTimeTools::fromYears(timeStepValue);
|
||||||
|
tsVector.push_back(dateTime.toTime_t());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QDateTime startDate = RiaQDateTimeTools::epoch();
|
||||||
|
|
||||||
|
if (!tableData.startDate().empty())
|
||||||
|
{
|
||||||
|
QDateTime candidate = RiaDateStringParser::parseDateString(tableData.startDate());
|
||||||
|
if (candidate.isValid())
|
||||||
|
{
|
||||||
|
startDate = candidate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dayOrYearColumnIndex != tableData.columnInfos().size())
|
||||||
|
{
|
||||||
|
const ColumnInfo& ci = tableData.columnInfos()[dayOrYearColumnIndex];
|
||||||
|
|
||||||
|
QString unit = QString::fromStdString(ci.unitName).trimmed().toUpper();
|
||||||
|
|
||||||
|
if (unit == "DAY" || unit == "DAYS")
|
||||||
|
{
|
||||||
|
for (const auto& timeStepValue : ci.values)
|
||||||
|
{
|
||||||
|
QDateTime dateTime = RiaQDateTimeTools::addDays(startDate, timeStepValue);
|
||||||
|
tsVector.push_back(dateTime.toTime_t());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (unit == "YEAR" || unit == "YEARS")
|
||||||
|
{
|
||||||
|
for (const auto& timeStepValue : ci.values)
|
||||||
|
{
|
||||||
|
QDateTime dateTime = RiaQDateTimeTools::addYears(startDate, timeStepValue);
|
||||||
|
tsVector.push_back(dateTime.toTime_t());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tsVector;
|
||||||
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ class QString;
|
|||||||
|
|
||||||
class RifColumnBasedUserDataParser;
|
class RifColumnBasedUserDataParser;
|
||||||
class RifEclipseSummaryAddress;
|
class RifEclipseSummaryAddress;
|
||||||
|
class TableData;
|
||||||
|
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
//
|
//
|
||||||
@@ -50,7 +51,8 @@ public:
|
|||||||
std::string unitName(const RifEclipseSummaryAddress& resultAddress) const override;
|
std::string unitName(const RifEclipseSummaryAddress& resultAddress) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void buildTimeStepsFromTables();
|
void buildTimeStepsAndMappings();
|
||||||
|
static std::vector<time_t> createTimeSteps(const TableData& table);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<RifColumnBasedUserDataParser> m_parser;
|
std::unique_ptr<RifColumnBasedUserDataParser> m_parser;
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ public:
|
|||||||
static std::vector<TableData> mergeEqualTimeSteps(const std::vector<TableData>& tables);
|
static std::vector<TableData> mergeEqualTimeSteps(const std::vector<TableData>& tables);
|
||||||
|
|
||||||
static bool isUnitText(const std::string& word);
|
static bool isUnitText(const std::string& word);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::string trimString(const std::string& s);
|
static std::string trimString(const std::string& s);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user