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

Districts : simplifying the code #2279

Merged
merged 42 commits into from
Aug 23, 2024
Merged

Districts : simplifying the code #2279

merged 42 commits into from
Aug 23, 2024

Conversation

guilpier-code
Copy link
Contributor

@guilpier-code guilpier-code commented Jul 22, 2024

Type SetsOfAreas (see study.h) is used to print aggregated results for a group of areas.
Its friend SetsOfLinks is defined but never used.
We remove it and make subsequent simplifications :

  • class Sets no longer needs to be a template class, or have template methods (So sets.hxx is removed, and sets.cpp is created)
  • class SetHandlerAreas (specific operations very much related to sets of areas) needs to be moved from Study code area into sets.h/.cpp

What should be done in the future :

  • class SetHandlerAreas should be questioned as a class : does it constitute a cohesive code entity ? Should it not be integrated to class Sets ? What should we do with its code so that Sets are clearer and simpler (next point may give a solution for this point) ?
  • class Sets should be refactored : indeed, it contains many private std::vectors / std::maps (pMap, pOptions, pByIndex, ...), associating a property to a set of area. We make many loops over these containers. This is chaotic design.
    Instead, we should define a class Set (for a single set), and make existing class Sets a collection of Set.
    Properties of a set should be contained in class Set. Besides the fact it would be more natural and clear, I suspect it would cause many simplifications and code reductions.

@guilpier-code guilpier-code requested a review from flomnes July 22, 2024 15:18
@guilpier-code guilpier-code changed the base branch from develop to feature/remove-new July 22, 2024 15:19
@flomnes flomnes linked an issue Jul 22, 2024 that may be closed by this pull request
@guilpier-code guilpier-code marked this pull request as ready for review July 25, 2024 11:10
Copy link
Member

@flomnes flomnes left a comment

Choose a reason for hiding this comment

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

Minor remarks.

  • typename makes no sense if there is no template, use auto instead
  • Use modern style for loops

src/libs/antares/study/area/sets.cpp Outdated Show resolved Hide resolved
src/libs/antares/study/area/sets.cpp Outdated Show resolved Hide resolved
src/libs/antares/study/area/sets.cpp Outdated Show resolved Hide resolved
Comment on lines 388 to 389
const typename MapType::const_iterator end = pMap.end();
for (typename MapType::const_iterator i = pMap.begin(); i != end; ++i)
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
const typename MapType::const_iterator end = pMap.end();
for (typename MapType::const_iterator i = pMap.begin(); i != end; ++i)
for (const auto& [name, content] : pMap)

Copy link
Contributor Author

@guilpier-code guilpier-code Jul 30, 2024

Choose a reason for hiding this comment

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

I'll do that, no problem, but we should keep in mind that any std::map / std::vector used as a data members of class Sets (for instance pMap) should not exist : please see PR presentation comment.
std::map and std::vector are used because of a chaotic architecture of class Sets.
Making changes on these std::map and std::vector manipulations is making changes on things that should disappear.

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

src/libs/antares/study/area/sets.cpp Outdated Show resolved Hide resolved
@guilpier-code
Copy link
Contributor Author

  • typename makes no sense if there is no template, use auto instead

Done : all typenames were removed from sets.h/.cpp

src/libs/antares/study/area/sets.cpp Outdated Show resolved Hide resolved
src/libs/antares/study/area/sets.cpp Outdated Show resolved Hide resolved
src/libs/antares/study/area/sets.cpp Outdated Show resolved Hide resolved
flomnes
flomnes previously approved these changes Jul 31, 2024
@flomnes
Copy link
Member

flomnes commented Jul 31, 2024

Add unit / study tests

@flomnes flomnes dismissed their stale review July 31, 2024 09:32

discussion

Copy link

Please retry analysis of this Pull-Request directly on SonarCloud

@guilpier-code
Copy link
Contributor Author

guilpier-code commented Aug 22, 2024

Add unit / study tests

I added many tests to be run on CI (see this commit), knowing that district results are taken into account when running CI tests.

@guilpier-code guilpier-code requested a review from flomnes August 22, 2024 14:15
Copy link
Member

@flomnes flomnes left a comment

Choose a reason for hiding this comment

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

Minor remarks

  • Revert workflow files
  • Use emplace_back(args...) instead of push_back(T(args...))

opts.rules.push_back(Rule(ruleFilter, new String("add-all")));
auto item = std::make_shared<T>();
add("all areas", item, opts);
opts.rules.push_back(Rule(ruleFilter, "add-all"));
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
opts.rules.push_back(Rule(ruleFilter, "add-all"));
opts.rules.emplace_back(ruleFilter, "add-all");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Construction in place. I get it.

@@ -239,17 +209,17 @@ bool Sets<T>::loadFromFile(const std::filesystem::path& filename)

if (p->key == "+")
{
opts.rules.push_back(Rule(ruleAdd, new String(value)));
opts.rules.push_back(Rule(ruleAdd, value.to<std::string>()));
Copy link
Member

Choose a reason for hiding this comment

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

This is so much better, the previous code was very confusing regarding memory ownership

Copy link
Member

Choose a reason for hiding this comment

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

Revert this

Copy link
Member

Choose a reason for hiding this comment

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

Revert

@guilpier-code
Copy link
Contributor Author

Add unit / study tests

Unit tests could be added easier by doing recommended refactoring (see PR presentation)

@flomnes flomnes merged commit 6e26d9c into develop Aug 23, 2024
6 of 7 checks passed
@flomnes flomnes deleted the fix/simplify-districts branch August 23, 2024 16:33
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Many .hxx files
4 participants