Skip to content

Commit

Permalink
Split TS generation into files : correction after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
guilpier-code committed Jun 28, 2024
1 parent 76a83f9 commit 2abab72
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 177 deletions.
15 changes: 0 additions & 15 deletions src/solver/ts-generator/availability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ class AvailabilityTSgenerator final
public:
explicit AvailabilityTSgenerator(Data::Study&, unsigned, MersenneTwister&);
explicit AvailabilityTSgenerator(bool, unsigned, MersenneTwister&);
explicit GeneratorTempData(bool, unsigned, MersenneTwister&);

void run(AvailabilityTSGeneratorData&) const;

Expand Down Expand Up @@ -628,20 +627,6 @@ void writeTStoDisk(const Matrix<>& series,
Antares::IO::fileSetContent(savePath.string(), buffer);
}

void writeResultsToDisk(const Matrix<>& series,
const std::filesystem::path savePath)
{
std::string buffer;
series.saveToBuffer(buffer, 0);

std::filesystem::path parentDir = savePath.parent_path();
if (! std::filesystem::exists(parentDir))
{
std::filesystem::create_directories(parentDir);
}
Antares::IO::fileSetContent(savePath.string(), buffer);
}

bool generateThermalTimeSeries(Data::Study& study,
const std::vector<Data::ThermalCluster*>& clusters,
const std::string& savePath)
Expand Down
162 changes: 0 additions & 162 deletions src/tools/ts-generator/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,168 +70,6 @@ std::vector<Data::ThermalCluster*> getClustersToGen(Data::AreaList& areas,
return clusters;
}

bool readLinkIniProperty(LinkTSgenerationParams* link,
const Yuni::String& key,
const Yuni::String& value)
{
if (key == "unitcount")
{
return value.to<uint>(link->unitCount);
}

if (key == "nominalcapacity")
{
return value.to<double>(link->nominalCapacity);
}

if (key == "law.planned")
{
return value.to(link->plannedLaw);
}

if (key == "law.forced")
{
return value.to(link->forcedLaw);
}

if (key == "volatility.planned")
{
return value.to(link->plannedVolatility);
}

if (key == "volatility.forced")
{
return value.to(link->forcedVolatility);
}

if (key == "force-no-generation")
{
return value.to<bool>(link->forceNoGeneration);
}
return true;
}

void readLinkIniProperties(LinkTSgenerationParams* link,
IniFile::Section* section)
{
for (const IniFile::Property* p = section->firstProperty; p; p = p->next)
{
if (! readLinkIniProperty(link, p->key, p->value))
{
std::string linkName = link->namesPair.first + "." + link->namesPair.second;
logs.warning() << "Link '" << linkName << "' : reading value of '"
<< p->key << "' went wrong";
link->hasValidData = false;
}
}
}

void readSourceAreaIniFile(fs::path pathToIni,
std::string sourceAreaName,
std::vector<LinkTSgenerationParams>& linkList)
{
IniFile ini;
ini.open(pathToIni); // gp : we should handle reading issues
for (auto* section = ini.firstSection; section; section = section->next)
{
std::string targetAreaName = transformNameIntoID(section->name);
const LinkPair processedLink = std::make_pair(sourceAreaName, targetAreaName);
if (auto* foundLink = findLinkInList(processedLink, linkList); foundLink)
{
readLinkIniProperties(foundLink, section);
}
}
}

void readIniProperties(std::vector<LinkTSgenerationParams>& linkList, fs::path toLinksDir)
{
for(auto& link : linkList)
{
std::string sourceAreaName = link.namesPair.first;
fs::path pathToIni = toLinksDir / sourceAreaName / "properties.ini";
readSourceAreaIniFile(pathToIni, sourceAreaName, linkList);
}
}

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;

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

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

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

void readPreproTimeSeries(std::vector<LinkTSgenerationParams>& linkList,
fs::path toLinksDir)
{
for(auto& link : linkList)
{
std::string sourceAreaName = link.namesPair.first;
fs::path sourceAreaDir = toLinksDir / sourceAreaName;
if (! readLinkPreproTimeSeries(link, sourceAreaDir))
{
logs.warning() << "Could not load all prepro data for link '"
<< link.namesPair.first << "." << link.namesPair.second << "'";
}
}
}

void readLinksSpecificTSparameters(std::vector<LinkTSgenerationParams>& linkList,
fs::path studyFolder)
{
fs::path toLinksDir = studyFolder / "input" / "links";
readIniProperties(linkList, toLinksDir);
readPreproTimeSeries(linkList, toLinksDir);
}

std::string DateAndTime()
{
YString to_return;
unsigned int now = Yuni::DateTime::Now();
Yuni::DateTime::TimestampToString(to_return, "%Y%m%d-%H%M", now);
return to_return.to<std::string>();
}
// ============================================================================

int main(int argc, char* argv[])
{
logs.applicationName("ts-generator");
Expand Down

0 comments on commit 2abab72

Please sign in to comment.