mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#2003 Observed Data : Merge tables if DATE is present and size is equal
This commit is contained in:
@@ -72,6 +72,8 @@ void RifColumnBasedUserDataParser::parseTableData(const QString& data)
|
|||||||
std::stringstream streamData;
|
std::stringstream streamData;
|
||||||
streamData.str(stdData);
|
streamData.str(stdData);
|
||||||
|
|
||||||
|
std::vector<TableData> rawTables;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
std::vector<std::string> errorStrings;
|
std::vector<std::string> errorStrings;
|
||||||
@@ -125,7 +127,9 @@ void RifColumnBasedUserDataParser::parseTableData(const QString& data)
|
|||||||
}
|
}
|
||||||
} while (std::getline(streamData, line));
|
} while (std::getline(streamData, line));
|
||||||
|
|
||||||
m_tableDatas.push_back(table);
|
rawTables.push_back(table);
|
||||||
|
|
||||||
} while (streamData.good());
|
} while (streamData.good());
|
||||||
|
|
||||||
|
m_tableDatas = RifEclipseUserDataParserTools::mergeEqualTimeSteps(rawTables);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -754,60 +754,54 @@ std::vector<size_t> RifEclipseUserDataParserTools::columnIndexForWords(const std
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
std::vector<std::vector<ColumnInfo>> RifEclipseUserDataParserTools::mergeEqualTimeSteps(const std::vector<std::vector<ColumnInfo>>& tables)
|
std::vector<TableData> RifEclipseUserDataParserTools::mergeEqualTimeSteps(const std::vector<TableData>& tables)
|
||||||
{
|
{
|
||||||
return tables;
|
|
||||||
|
|
||||||
/*
|
|
||||||
if (tables.size() < 2)
|
if (tables.size() < 2)
|
||||||
{
|
{
|
||||||
return tables;
|
return tables;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ColumnInfo* timeCi = nullptr;
|
if (tables[0].columnInfos().size() == 0) return tables;
|
||||||
for (const ColumnInfo& ci : tables[0])
|
|
||||||
|
ColumnInfo* dateColumn = nullptr;
|
||||||
|
for (auto c : tables[0].columnInfos())
|
||||||
{
|
{
|
||||||
if (!ci.isAVector)
|
if (c.summaryAddress.quantityName() == "DATE")
|
||||||
{
|
{
|
||||||
timeCi = &ci;
|
dateColumn = &c;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!timeCi)
|
// Support only merge of tables with the DATE column present
|
||||||
{
|
if (!dateColumn) return tables;
|
||||||
return tables;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::vector<ColumnInfo>> largeTables;
|
std::vector<TableData> largeTables;
|
||||||
{
|
|
||||||
std::vector<ColumnInfo> largeTable;
|
|
||||||
|
|
||||||
largeTable.push_back(*timeCi);
|
largeTables.push_back(tables[0]);
|
||||||
|
|
||||||
for (const auto& t : tables)
|
TableData& firstTable = largeTables[0];
|
||||||
{
|
size_t itemsInFirstTable = tables[0].columnInfos()[0].itemCount();
|
||||||
if (t.size() > 0 && t[0].itemCount() != timeCi->itemCount())
|
|
||||||
{
|
|
||||||
largeTables.push_back(t);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto& c : t)
|
for (size_t i = 1; i < tables.size(); i++)
|
||||||
{
|
{
|
||||||
if (c.isAVector &&
|
if (tables[i].columnInfos().size() > 0 &&
|
||||||
c.values.size() == timeCi->observationDateTimes.size())
|
tables[i].columnInfos()[0].itemCount() == itemsInFirstTable)
|
||||||
{
|
{
|
||||||
largeTable.push_back(c);
|
for (auto& c : tables[i].columnInfos())
|
||||||
|
{
|
||||||
|
if (c.summaryAddress.quantityName() != "DATE")
|
||||||
|
{
|
||||||
|
firstTable.columnInfos().push_back(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
largeTables.push_back(largeTable);
|
{
|
||||||
|
largeTables.push_back(tables[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return largeTables;
|
return largeTables;
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@@ -838,6 +832,19 @@ bool RifEclipseUserDataParserTools::isUnitText(const std::string& word)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
size_t ColumnInfo::itemCount() const
|
||||||
|
{
|
||||||
|
if (isStringData)
|
||||||
|
{
|
||||||
|
return stringValues.size();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return values.size();
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t itemCount() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static ColumnInfo createColumnInfo(const std::string& quantity, const std::string& unit, const RifEclipseSummaryAddress& adr);
|
static ColumnInfo createColumnInfo(const std::string& quantity, const std::string& unit, const RifEclipseSummaryAddress& adr);
|
||||||
|
|
||||||
@@ -146,7 +148,7 @@ public:
|
|||||||
static std::vector<ColumnInfo> columnInfoFromColumnHeaders(const std::vector<std::vector<std::string>>& columnData);
|
static std::vector<ColumnInfo> columnInfoFromColumnHeaders(const std::vector<std::vector<std::string>>& columnData);
|
||||||
static std::vector<size_t> columnIndexForWords(const std::string& line);
|
static std::vector<size_t> columnIndexForWords(const std::string& line);
|
||||||
|
|
||||||
static std::vector<std::vector<ColumnInfo>> mergeEqualTimeSteps(const std::vector<std::vector<ColumnInfo>>& columns);
|
static std::vector<TableData> mergeEqualTimeSteps(const std::vector<TableData>& tables);
|
||||||
|
|
||||||
static bool isUnitText(const std::string& word);
|
static bool isUnitText(const std::string& word);
|
||||||
|
|
||||||
|
|||||||
@@ -151,9 +151,9 @@ TEST(FixedWidthDataParser, DetectFixedWidth)
|
|||||||
|
|
||||||
RifColumnBasedUserDataParser parser(data);
|
RifColumnBasedUserDataParser parser(data);
|
||||||
auto tables = parser.tableData();
|
auto tables = parser.tableData();
|
||||||
EXPECT_EQ(size_t(3), tables.size());
|
EXPECT_EQ(size_t(1), tables.size());
|
||||||
|
|
||||||
EXPECT_EQ(size_t(10), tables[0].columnInfos().size());
|
EXPECT_EQ(size_t(28), tables[0].columnInfos().size());
|
||||||
EXPECT_EQ(size_t(13), tables[0].columnInfos()[0].stringValues.size());
|
EXPECT_EQ(size_t(13), tables[0].columnInfos()[0].stringValues.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,6 +209,6 @@ TEST(FixedWidthDataParser, VaryingTimeStepCount)
|
|||||||
|
|
||||||
RifColumnBasedUserDataParser parser(data);
|
RifColumnBasedUserDataParser parser(data);
|
||||||
auto tables = parser.tableData();
|
auto tables = parser.tableData();
|
||||||
EXPECT_EQ(2, tables.size());
|
EXPECT_EQ(size_t(2), tables.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user