Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trial for improve issue 2033 #2629

Merged
merged 6 commits into from
Feb 10, 2025
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions src/io/inputs/data-series-csv-importer/DataSeriesRepoImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
*/
#include <fstream>
#include <ranges>

#include <boost/regex.hpp>

Expand All @@ -28,26 +29,30 @@ namespace Antares::IO::Inputs::DataSeriesCsvImporter
{
using namespace Optimisation::LinearProblemDataImpl;

bool hasRightExtension(const std::filesystem::directory_entry& e)
{
auto ext = e.path().extension();
return ext == ".csv" | ext == ".tsv";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return ext == ".csv" | ext == ".tsv";
return (ext == ".csv") || (ext == ".tsv");

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(gcc warning)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

DataSeriesRepository DataSeriesRepoImporter::importFromDirectory(const std::filesystem::path& path,
char csvSeparator)
{
if (!is_directory(path))
{
throw std::invalid_argument("Not a directory: " + path.string());
}

auto paths = std::filesystem::directory_iterator{path};
auto pathFilter = std::views::filter([](const auto& e) { return is_regular_file(e); })
| std::views::filter(&hasRightExtension);

DataSeriesRepository repo{};
for (const auto& entry: std::filesystem::directory_iterator(path))
for (const auto& entry: paths | pathFilter)
{
if (!is_regular_file(entry))
{
continue;
}
if (entry.path().extension() == ".csv" || entry.path().extension() == ".tsv")
{
std::unique_ptr<IDataSeries> timeSeriesSet = std::make_unique<TimeSeriesSet>(
TimeSeriesSetImporter::importFromFile(entry, csvSeparator));
repo.addDataSeries(std::move(timeSeriesSet));
}
std::unique_ptr<IDataSeries> timeSeriesSet = std::make_unique<TimeSeriesSet>(
TimeSeriesSetImporter::importFromFile(entry, csvSeparator));
repo.addDataSeries(std::move(timeSeriesSet));
}
return repo;
}
Expand Down
Loading