Skip to content

Commit

Permalink
Remove TS links from solver : extract study general parameters relate…
Browse files Browse the repository at this point in the history
…d to link TS generation
  • Loading branch information
guilpier-code committed Jun 11, 2024
1 parent daaef31 commit 44993fc
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion src/tools/ts-generator/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,14 @@ TSGenerator::listOfLinks getLinksToGen(Data::AreaList& areas, const std::string&
return links;
}

// ===== New code for TS generation links ====================================

std::vector<std::string> extractTargetAreas(fs::path sourceLinkDir)
{
std::vector<std::string> to_return;
fs::path pathToIni = sourceLinkDir / "properties.ini";
IniFile ini;
ini.open(pathToIni);
ini.open(pathToIni); // gp : we should handle reading issues
for (auto* s = ini.firstSection; s; s = s->next)
{
std::string targetAreaName = transformNameIntoID(s->name);
Expand Down Expand Up @@ -214,6 +216,58 @@ void logLinks(std::string title, LinkPairs& links)
}
}

struct StudyParamsForLinkTS
{
bool derated = false;
unsigned int nbLinkTStoGenerate = 1;
unsigned int seed = Data::antaresSeedDefaultValue;
};

bool readProperty(StudyParamsForLinkTS& params,
const Yuni::String& key,
const Yuni::String& value)
{
if (key == "derated")
{
return value.to<bool>(params.derated);
}
if (key == "nbtimeserieslinks")
{
return value.to<unsigned int>(params.nbLinkTStoGenerate);
}
if (key == "seed-tsgen-links")
{
return value.to<unsigned int>(params.seed);
}
return true; // gp : should we return true here ?
}

StudyParamsForLinkTS readParamsForLinksTS(fs::path studyDir)
{
StudyParamsForLinkTS to_return;
fs::path pathToGeneraldata = studyDir / "settings" / "generaldata.ini";
IniFile ini;
ini.open(pathToGeneraldata); // gp : we should handle reading issues
for (auto* section = ini.firstSection; section; section = section->next)
{
// Skipping sections useless in the current context
Yuni::String sectionName = section->name;
if (sectionName != "general" && sectionName != "seeds - Mersenne Twister")
continue;

for (const IniFile::Property* p = section->firstProperty; p; p = p->next)
{
if (! readProperty(to_return, p->key, p->value))
{
logs.warning() << ini.filename() << ": '" << p->key << "': Unknown property";
}
}
}
return to_return;
}

// ============================================================================

int main(int argc, char* argv[])
{
logs.applicationName("ts-generator");
Expand Down Expand Up @@ -304,6 +358,8 @@ int main(int argc, char* argv[])
auto linksFromCmdLine = extractLinksFromCmdLine(allLinksPairs, settings.linksListToGen);
logLinks("Links from cmd line", linksFromCmdLine);

StudyParamsForLinkTS params = readParamsForLinksTS(settings.studyFolder);

TSGenerator::listOfLinks links;
if (settings.allLinks)
{
Expand Down

0 comments on commit 44993fc

Please sign in to comment.