-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Peter Mitri <[email protected]>
- Loading branch information
Showing
7 changed files
with
210 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
set(SOURCES | ||
include/antares/io/inputs/data-series-csv-importer/DataSeriesRepoImporter.h | ||
DataSeriesRepoImporter.cpp | ||
) | ||
|
||
# Create the library | ||
add_library(data-series-csv-importer STATIC ${SOURCES}) | ||
add_library(Antares::data-series-csv-importer ALIAS data-series-csv-importer) | ||
|
||
# Specify include directories | ||
target_include_directories(data-series-csv-importer | ||
PUBLIC | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
) | ||
|
||
# Link dependencies | ||
target_link_libraries(data-series-csv-importer | ||
PRIVATE | ||
linear-problem-data-impl | ||
PUBLIC | ||
Boost::headers | ||
) | ||
|
||
install(DIRECTORY include/antares | ||
DESTINATION "include" | ||
) |
99 changes: 99 additions & 0 deletions
99
src/io/inputs/data-series-csv-importer/DataSeriesRepoImporter.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
** Copyright 2007-2024, RTE (https://www.rte-france.com) | ||
** See AUTHORS.txt | ||
** SPDX-License-Identifier: MPL-2.0 | ||
** This file is part of Antares-Simulator, | ||
** Adequacy and Performance assessment for interconnected energy networks. | ||
** | ||
** Antares_Simulator is free software: you can redistribute it and/or modify | ||
** it under the terms of the Mozilla Public Licence 2.0 as published by | ||
** the Mozilla Foundation, either version 2 of the License, or | ||
** (at your option) any later version. | ||
** | ||
** Antares_Simulator is distributed in the hope that it will be useful, | ||
** but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
** Mozilla Public Licence 2.0 for more details. | ||
** | ||
** You should have received a copy of the Mozilla Public Licence 2.0 | ||
** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>. | ||
*/ | ||
#include <fstream> | ||
|
||
#include <boost/regex.hpp> | ||
|
||
#include <antares/io/inputs/data-series-csv-importer/DataSeriesRepoImporter.h> | ||
#include <antares/optimisation/linear-problem-data-impl/dataSeriesRepo.h> | ||
#include <antares/optimisation/linear-problem-data-impl/timeSeriesSet.h> | ||
|
||
namespace Antares::IO::Inputs::DataSeriesCsvImporter | ||
{ | ||
using namespace std; | ||
using namespace boost; | ||
using namespace Optimisation::LinearProblemDataImpl; | ||
|
||
DataSeriesRepository DataSeriesRepoImporter::importFromDirectory(const string& path, | ||
char csvSeparator) | ||
{ | ||
return DataSeriesRepository(); | ||
} | ||
|
||
TimeSeriesSet TimeSeriesSetImporter::importFromFile(const string& path, char csvSeparator) | ||
{ | ||
// used to split the file in lines | ||
const regex linesregx("\\r\\n|\\n\\r|\\n|\\r"); | ||
// used to split each line to tokens, assuming ',' as column separator | ||
const regex fieldsregx(csvSeparator + "(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))"); | ||
vector<vector<double>> result; | ||
ifstream infile; | ||
infile.open(path); | ||
char data[1024]; | ||
infile.read(data, sizeof(data)); | ||
data[infile.tellg()] = '\0'; | ||
unsigned int length = strlen(data); | ||
|
||
// iterator splits data to lines | ||
cregex_token_iterator li(data, data + length, linesregx, -1); | ||
cregex_token_iterator end; | ||
|
||
while (li != end) | ||
{ | ||
string line = li->str(); | ||
++li; | ||
|
||
// Split line to tokens | ||
sregex_token_iterator ti(line.begin(), line.end(), fieldsregx, -1); | ||
sregex_token_iterator end2; | ||
|
||
vector<double> row; | ||
while (ti != end2) | ||
{ | ||
double token = stod(ti->str()); | ||
++ti; | ||
row.push_back(token); | ||
} | ||
result.push_back(row); | ||
} | ||
// We have to transpose the matrix | ||
string id = path; // TODO | ||
if (result.empty()) | ||
{ | ||
return TimeSeriesSet(id, 0); | ||
} | ||
int nTimestamps = result.size(); | ||
TimeSeriesSet timeSeriesSet(id, nTimestamps); | ||
int nSets = result[0].size(); | ||
for (int i = 0; i < nSets; ++i) | ||
{ | ||
vector<double> set; | ||
set.reserve(nTimestamps); | ||
for (int j = 0; j < nTimestamps; ++j) | ||
{ | ||
set.push_back(result[j][i]); | ||
} | ||
timeSeriesSet.add(set); | ||
} | ||
return timeSeriesSet; | ||
} | ||
|
||
} // namespace Antares::IO::Inputs::DataSeriesCsvImporter |
54 changes: 54 additions & 0 deletions
54
...-csv-importer/include/antares/io/inputs/data-series-csv-importer/DataSeriesRepoImporter.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
** Copyright 2007-2025, RTE (https://www.rte-france.com) | ||
** See AUTHORS.txt | ||
** SPDX-License-Identifier: MPL-2.0 | ||
** This file is part of Antares-Simulator, | ||
** Adequacy and Performance assessment for interconnected energy networks. | ||
** | ||
** Antares_Simulator is free software: you can redistribute it and/or modify | ||
** it under the terms of the Mozilla Public Licence 2.0 as published by | ||
** the Mozilla Foundation, either version 2 of the License, or | ||
** (at your option) any later version. | ||
** | ||
** Antares_Simulator is distributed in the hope that it will be useful, | ||
** but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
** Mozilla Public Licence 2.0 for more details. | ||
** | ||
** You should have received a copy of the Mozilla Public Licence 2.0 | ||
** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>. | ||
*/ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
namespace Antares::Optimisation::LinearProblemDataImpl | ||
{ | ||
class DataSeriesRepository; | ||
class TimeSeriesSet; | ||
} // namespace Antares::Optimisation::LinearProblemDataImpl | ||
|
||
/** | ||
* Reads a DataSeriesRepo from a directory | ||
* Every csv file found represents a DataSeries, its id will be the name of the file | ||
*/ | ||
namespace Antares::IO::Inputs::DataSeriesCsvImporter | ||
{ | ||
|
||
class TimeSeriesSetImporter | ||
{ | ||
public: | ||
static Optimisation::LinearProblemDataImpl::TimeSeriesSet importFromFile( | ||
const std::string& path, | ||
char csvSeparator = ';'); | ||
}; | ||
|
||
class DataSeriesRepoImporter | ||
{ | ||
public: | ||
static Optimisation::LinearProblemDataImpl::DataSeriesRepository importFromDirectory( | ||
const std::string& path, | ||
char csvSeparator = ';'); | ||
}; | ||
|
||
} // namespace Antares::IO::Inputs::DataSeriesCsvImporter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
add_subdirectory(yml-importers) | ||
add_subdirectory(yml-importers) | ||
add_subdirectory(data-series-csv-importer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
include(${CMAKE_SOURCE_DIR}/tests/macros.cmake) | ||
|
||
add_boost_test(TestDataSeriesCsvImporter | ||
SRC | ||
testDataSeriesRepoImporter.cpp | ||
LIBS | ||
Antares::data-series-csv-importer) |
21 changes: 21 additions & 0 deletions
21
src/tests/io/data-series-csv-importer/testDataSeriesRepoImporter.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
** Copyright 2007-2024, RTE (https://www.rte-france.com) | ||
** See AUTHORS.txt | ||
** SPDX-License-Identifier: MPL-2.0 | ||
** This file is part of Antares-Simulator, | ||
** Adequacy and Performance assessment for interconnected energy networks. | ||
** | ||
** Antares_Simulator is free software: you can redistribute it and/or modify | ||
** it under the terms of the Mozilla Public Licence 2.0 as published by | ||
** the Mozilla Foundation, either version 2 of the License, or | ||
** (at your option) any later version. | ||
** | ||
** Antares_Simulator is distributed in the hope that it will be useful, | ||
** but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
** Mozilla Public Licence 2.0 for more details. | ||
** | ||
** You should have received a copy of the Mozilla Public Licence 2.0 | ||
** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>. | ||
*/ | ||
#include <antares/io/inputs/data-series-csv-importer/DataSeriesRepoImporter.h> |