Skip to content

Commit

Permalink
Split thermal TS generation : raised an error if a prepro file does n…
Browse files Browse the repository at this point in the history
…ot exist

Not just ignore it, as code used to do.
  • Loading branch information
guilpier-code committed Jun 28, 2024
1 parent daa483b commit 8b17810
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct LinkTSgenerationParams
{
LinkPair namesPair;

unsigned unitCount = 0;
unsigned unitCount = 1;
double nominalCapacity = 0;

double forcedVolatility = 0.;
Expand Down
74 changes: 39 additions & 35 deletions src/tools/ts-generator/linksTSgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,52 +166,56 @@ void readIniProperties(std::vector<LinkTSgenerationParams>& linkList, fs::path t
}
}

bool readLinkPreproTimeSeries(LinkTSgenerationParams& link,
fs::path sourceAreaDir)
{
bool to_return = true;
const auto preproId = link.namesPair.first + "/" + link.namesPair.second;
link.prepro = std::make_unique<Data::PreproAvailability>(preproId, link.unitCount);
fs::path makePreproFile(const fs::path& preproFilePath, const std::string& changingEnd)
{
auto to_return = preproFilePath;
to_return += changingEnd + ".txt";
return to_return;
}

auto preproFileRoot = sourceAreaDir / "prepro" / link.namesPair.second;
bool readLinkPreproTimeSeries(LinkTSgenerationParams& link,
fs::path sourceAreaDir)
{
bool to_return = true;
const auto preproId = link.namesPair.first + "/" + link.namesPair.second;
link.prepro = std::make_unique<Data::PreproAvailability>(preproId, link.unitCount);

auto preproFileRoot = sourceAreaDir / "prepro" / link.namesPair.second;

// Testing files existence
auto preproFile = makePreproFile(preproFileRoot, "");
auto modulationDirectFile = makePreproFile(preproFileRoot, "_mod_direct");
auto modulationIndirectFile = makePreproFile(preproFileRoot, "_mod_indirect");
std::vector<fs::path> paths {preproFile, modulationDirectFile, modulationIndirectFile};
if (std::any_of(paths.begin(), paths.end(), [](auto& path) {return ! fs::exists(path);}))
{
link.hasValidData = false;
return false;
}

auto preproFile = preproFileRoot;
preproFile += ".txt";
if (fs::exists(preproFile))
{
to_return = link.prepro->data.loadFromCSVFile(
// Files loading
to_return = link.prepro->data.loadFromCSVFile(
preproFile.string(),
Data::PreproAvailability::preproAvailabilityMax,
DAYS_PER_YEAR)
&& link.prepro->validate()
&& to_return;
}
&& link.prepro->validate()
&& to_return;

auto modulationFileDirect = preproFileRoot;
modulationFileDirect += "_mod_direct.txt";
if (fs::exists(modulationFileDirect))
{
to_return = link.modulationCapacityDirect.loadFromCSVFile(
modulationFileDirect.string(),
to_return = link.modulationCapacityDirect.loadFromCSVFile(
modulationDirectFile.string(),
1,
HOURS_PER_YEAR)
&& to_return;
}
&& to_return;

auto modulationFileIndirect = preproFileRoot;
modulationFileIndirect += "_mod_indirect.txt";
if (fs::exists(modulationFileIndirect))
{
to_return = link.modulationCapacityIndirect.loadFromCSVFile(
modulationFileIndirect.string(),
to_return = link.modulationCapacityIndirect.loadFromCSVFile(
modulationIndirectFile.string(),
1,
HOURS_PER_YEAR)
&& to_return;
}
// Makes it possible to skip a link's TS generation when time comes
link.hasValidData = link.hasValidData && to_return;
return to_return;
}
&& to_return;

link.hasValidData = link.hasValidData && to_return;
return to_return;
}

void readPreproTimeSeries(std::vector<LinkTSgenerationParams>& linkList,
fs::path toLinksDir)
Expand Down

0 comments on commit 8b17810

Please sign in to comment.