#2640 implement merge behavior on Reactions#2641
#2640 implement merge behavior on Reactions#2641benjaperez1983 wants to merge 7 commits intodevelopfrom
Conversation
msevestre
left a comment
There was a problem hiding this comment.
ok some feedback. This will change completely once the merge stuff that I am doing is implemented. For nwo my suggestgion would be to have one method that takes two reaction, a merge and returns the merge results.. This should be tested and this shoudl be enough.
overall the code is veyr hard to read. Did you generate this code with AI somehow?
tests/OSPSuite.Core.IntegrationTests/ModelConstructorIntegrationTests.cs
Outdated
Show resolved
Hide resolved
I have resolved the comments how, I have some remarks anyways. On the Cloning, you are right there is a whole logic for it (which I`m reusing right now) but nevertheless there are some things that are not being fully cloned (such as formula and parameters), so I added that to it. Regarding your other question, funny thing I had a very large and difficult to read nested methods which I asked the AI to simplify, turned out to be even harder to read, so I rolled that back and try refactoring in a way it is better now. Thanks! |
|
@benjaperez1983 Let's meet when you have time this week. Most of this code is obsolete I believe. I am going to comment on the PR what I believe will be kept |
msevestre
left a comment
There was a problem hiding this comment.
I suggest to close this PR and to make one towards #2603 implementing the mergeReactions method
private void mergeReactions(ReactionBuilder target, BuilderSource<ReactionBuilder> source)
{
//TODO add reaction merge behavior
}
integrations tests should be written by modifying the ModuleHelperForTests ensuring that we have the right behavior for OVERWRITE (is given normally since the code is generic) and EXTEND (is bb specific)
| private void performMerge() | ||
| { | ||
| cacheBuilders(x => x.Reactions, _reactions); | ||
| var mergedReactions = mergeReactions(ReactionAndMergeBehaviors); |
| internal IReadOnlyList<(EventGroupBuildingBlock eventGroupBuildingBlock, MergeBehavior mergeBehavior)> EventGroupAndMergeBehaviors => | ||
| _simulationConfiguration.ModuleConfigurations.Where(x => x.Module.EventGroups != null).Select(x => (x.Module.EventGroups, x.MergeBehavior)).ToList(); | ||
|
|
||
| internal IReadOnlyList<(ReactionBuildingBlock reactionBuildingBlock, MergeBehavior mergeBehavior)> ReactionAndMergeBehaviors => |
| } | ||
| else | ||
| { | ||
| extendReaction(current, incoming); |
There was a problem hiding this comment.
this is the method that we need to probably port over (the merge). The rest is done dynamically using the clone as I suggested (yes it also clones the formula)
There was a problem hiding this comment.
Well, if I dont copy the formula as Im doing now. I get this over many tests.
Message:
System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
----> System.NullReferenceException : Object reference not set to an instance of an object.
All related with the formula.
So maybe I`m not doing this as I should. Will mark it for conversation
|
|
||
| private static void extendReaction(ReactionBuilder target, ReactionBuilder incoming) | ||
| { | ||
| var byNameParam = target.Parameters.ToDictionary(x => x.Name, StringComparer.OrdinalIgnoreCase); |
There was a problem hiding this comment.
none of thos management of parmaeter stuff is required. We have the contaienr task that merge container structure already for us. It's being used in #2603
| target.Dimension = incoming.Dimension ?? target.Dimension; | ||
|
|
||
| if (incoming.ContainerCriteria != null) | ||
| target.ContainerCriteria = incoming.ContainerCriteria; |
There was a problem hiding this comment.
I am not srue about this line to be honest.
|
|
||
| private static void extendReaction(ReactionBuilder target, ReactionBuilder incoming) | ||
| { | ||
| var byNameParam = target.Parameters.ToDictionary(x => x.Name, StringComparer.OrdinalIgnoreCase); |
There was a problem hiding this comment.
this feels a bit heavy considering we have a functiont aht returns null already
the code is already implemented for this in the merge taks so we can ignroe
public void AddOrReplaceInContainer(IContainer container, IEntity entityToAddOrReplace)
{
var existingChild = container.GetSingleChildByName(entityToAddOrReplace.Name);
if (existingChild != null)
container.RemoveChild(existingChild);
container.Add(entityToAddOrReplace);
}
|
|
||
| copy.Formula = incoming.Formula; | ||
|
|
||
| copy.CreateProcessRateParameter = incoming.CreateProcessRateParameter; |
There was a problem hiding this comment.
this should alreayd be taken over from the updatePropertiesFrom
There was a problem hiding this comment.
Again, some failing tests if I exclude this in relation with the createprocessrate.
|
|
||
| copy.CreateProcessRateParameter = incoming.CreateProcessRateParameter; | ||
| copy.ProcessRateParameterPersistable = incoming.ProcessRateParameterPersistable; | ||
| copy.Id = incoming.Id; |
|
@benjaperez1983 do you need this PR or branch anymore? |
|
@benjaperez1983 close this one? |
|
@rwmcintosh closed, was waiting until the other branch (based on michael`s) was reviewed, but I believe we can close it now. |
Fixes #2640
Description
Merge behavior for reactions
Type of change
Please mark relevant options with an
xin the brackets.How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Reviewer checklist
Mark everything that needs to be checked before merging the PR.
This change requires a documentation updateabove is selectedScreenshots (if appropriate):
Questions (if appropriate):