-
Notifications
You must be signed in to change notification settings - Fork 24
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
Small refactoring CR23 - File deletion #1732
Small refactoring CR23 - File deletion #1732
Conversation
@@ -393,7 +393,14 @@ class JobSaveStudy final : public Toolbox::Jobs::Job | |||
} // save as | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guilpier-code This is obviously code duplication. Do you have proposal where potential function should be defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guilpier-code This is obviously code duplication. Do you have proposal where potential function should be defined?
As you know, we don't want to enhance the UI code, we think it's not worth it.
Besides, it's not exactly code we touched for this CR 23.
But you're right, there is a code duplication.
src/libs/antares/study/study.h
Outdated
@@ -449,6 +449,12 @@ class Study: public Yuni::NonCopyable<Study>, public IObject, public LayerData | |||
void removeTimeseriesIfTSGeneratorEnabled(); | |||
//@} | |||
|
|||
/*! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class Study is large enough, we plan to split it in many pieces, and we don't want it to grow.
- For now, we should make this function a free function. We could add it as a couple of source files file-removal.h/.cpp
- What it actually does is removing deprecated hydro max power input files, right ? Don't hesitate renaming it removeDeprecatedHydroMaxPowerTSfiles.
- this function should take 3 arguments :
- a list of areas (AreaList&),
- a input folder path (as an std::string or in a standard format, we don't want dependencies on Yuni strings, we want to get rid of it)
- a current study version (as a unsigned int)
It could be something like :
void removeDeprecatedHydroMaxPowerTSfiles(AreaList& areas,
std::string inputFolder,
unsigned int currentStudyVersion)
{
if (currentStudyVersion >= 870)
return;
vector<std::string> areasNames;
areas.each( [](const Area& area) { areasNames.push_back(area.id.to<std::string>(); });
for (const name : areasNames)
{
std::string filePath = folderInput + "/hydro/common/capacity/" + name + ".txt"
removeFile(filePath); // To be coded in the same source file, in the .cpp file.
}
}
On the client side, it would be :
removeDeprecatedHydroMaxPowerTSfiles(study.areas, study.folderInput.to<std::string>, study.header.version),
Note : about removeFile(filePath)
, it probably already exists in the unit tests code area
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is to first read currentStudyVerstion and save it value to temporary variable, after that we are calling study->saveToFolder
. Why we need temporary variable? We need it because, if we are upgrading a study, variable study->.header.version
will be changed (after study->saveToFolder
function call) to a current version of our software, and if we are passing value of the study->.header.version
variable to the deleteDeprecatedHydroMaxPowerTSFiles
function we will be passing already updated value of our study version (currently 870). If we are upgrading for example from 8.2 version than we need to pass 820 value to the deleteDeprecatedHydroMaxPowerTSFiles
function, and we are doing that via temporary variable.
Condition if (currentStudyVersion >= 870)
must be changed to if(previousVersion < 870)
. Why? Because currentStudyVersion after saving a study will have 870 value, and deletion won't be performed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we need to delete files just if study->saveToFolder()
function call return true, than we are sure that our new files are saved and all data from deprecated files are stored in our new files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. Your last comments regard more the updater/main.cpp than the src/libs/antares/study/study.h.
So I answer you in updater/main.cpp (below)
src/tools/updater/main.cpp
Outdated
@@ -93,7 +93,12 @@ class MyStudyFinder final : public Data::StudyFinder | |||
study->parameters.readonly = true; | |||
|
|||
logs.info() << "Saving..."; | |||
study->saveToFolder(folder); | |||
|
|||
uint tempVersionVar = (uint)study->header.version; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tempVersionVar : we should be more clear. This variable is the current study version, isn't it ?
So let's call it currentStudyVersion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An answer to the previous comment from @nikolaredstork was given here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is what think, eventually about tempVersionVar and this added piece of code.
I think we should have :
...
bool isSaved = study->saveToFolder(folder);
if (isSaved)
deleteDeprecatedHydroMaxPowerTSFiles(study->areas,
study->folderInput.to<std::string>,
study->header.version);
Note we don't need the source (what you called tmp) study version here.
Why ?
When get here, a study was loaded, and it may have input deprecated files.
Then we upgrade it, meaning that we erase input data with fresh updated one.
Deprecated files (hydro max power TS in this case) can still remain.
Calling deleteDeprecatedHydroMaxPowerTSFiles will delete them if they exists and if the new study version requires it.
Note that the small removeFile function suggested in this comment removes a file only if it exists of course.
It's more simple like this, don't you think ?
src/tools/updater/main.cpp
Outdated
@@ -93,7 +93,12 @@ class MyStudyFinder final : public Data::StudyFinder | |||
study->parameters.readonly = true; | |||
|
|||
logs.info() << "Saving..."; | |||
study->saveToFolder(folder); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally, we should add this to the src/libs/antares/study/cleaner/cleaner.cpp, which is supposed to clean any study from unsuitable files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. I've looked up cleaner.cpp file in details, and apparently after upgrading and saving our new files, we will delete deprecated files with clean command, so I don't think that we need automatic deletion after upgrade. With that been said, this PR shouldn't be merged and code for deletion of files should be excluded.
@@ -393,7 +393,14 @@ class JobSaveStudy final : public Toolbox::Jobs::Job | |||
} // save as | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guilpier-code This is obviously code duplication. Do you have proposal where potential function should be defined?
As you know, we don't want to enhance the UI code, we think it's not worth it.
Besides, it's not exactly code we touched for this CR 23.
But you're right, there is a code duplication.
src/libs/antares/study/study.h
Outdated
@@ -449,6 +449,12 @@ class Study: public Yuni::NonCopyable<Study>, public IObject, public LayerData | |||
void removeTimeseriesIfTSGeneratorEnabled(); | |||
//@} | |||
|
|||
/*! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. Your last comments regard more the updater/main.cpp than the src/libs/antares/study/study.h.
So I answer you in updater/main.cpp (below)
src/tools/updater/main.cpp
Outdated
@@ -93,7 +93,12 @@ class MyStudyFinder final : public Data::StudyFinder | |||
study->parameters.readonly = true; | |||
|
|||
logs.info() << "Saving..."; | |||
study->saveToFolder(folder); | |||
|
|||
uint tempVersionVar = (uint)study->header.version; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An answer to the previous comment from @nikolaredstork was given here.
src/tools/updater/main.cpp
Outdated
@@ -93,7 +93,12 @@ class MyStudyFinder final : public Data::StudyFinder | |||
study->parameters.readonly = true; | |||
|
|||
logs.info() << "Saving..."; | |||
study->saveToFolder(folder); | |||
|
|||
uint tempVersionVar = (uint)study->header.version; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is what think, eventually about tempVersionVar and this added piece of code.
I think we should have :
...
bool isSaved = study->saveToFolder(folder);
if (isSaved)
deleteDeprecatedHydroMaxPowerTSFiles(study->areas,
study->folderInput.to<std::string>,
study->header.version);
Note we don't need the source (what you called tmp) study version here.
Why ?
When get here, a study was loaded, and it may have input deprecated files.
Then we upgrade it, meaning that we erase input data with fresh updated one.
Deprecated files (hydro max power TS in this case) can still remain.
Calling deleteDeprecatedHydroMaxPowerTSFiles will delete them if they exists and if the new study version requires it.
Note that the small removeFile function suggested in this comment removes a file only if it exists of course.
It's more simple like this, don't you think ?
Kudos, SonarCloud Quality Gate passed! |
3da3b13
into
feature/max-gen-pump-cr23-develop-merge
Excluding deletion of deprecated files from load functions.
Comment from the main PR #1470 (comment)