Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Mitri <[email protected]>
  • Loading branch information
pet-mit committed Feb 6, 2025
1 parent 0af47ce commit ed197a3
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/io/inputs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ OMESSAGE("Antares IO-Inputs")
add_subdirectory(model-converter)
add_subdirectory(yml-model)
add_subdirectory(yml-system)
add_subdirectory(data-series-csv-importer)
26 changes: 26 additions & 0 deletions src/io/inputs/data-series-csv-importer/CMakeLists.txt
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 src/io/inputs/data-series-csv-importer/DataSeriesRepoImporter.cpp
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
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
3 changes: 2 additions & 1 deletion src/tests/io/CMakeLists.txt
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)
7 changes: 7 additions & 0 deletions src/tests/io/data-series-csv-importer/CMakeLists.txt
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)
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>

0 comments on commit ed197a3

Please sign in to comment.