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

Implemented toplogical sorting for totals #65

Closed
wants to merge 1 commit into from

Conversation

amenk
Copy link
Contributor

@amenk amenk commented Aug 15, 2012

The sorting of totals is incorrect with causes lots of problem when new modules that define own totals are added.

For details see http://stackoverflow.com/a/9258826/288568

This patch implementes a toplogic sort to fix this problem.

For a unit test I suggest the following code ($result is the result of the _getSortedCollectorCodes array for any input)

        $this->assertEquals(count($configArray), count($result));

        // check if all conditions where matched
        // as we do have only a partial order, it does not make sense
        // to check the definite result
        foreach($configArray as $code=>$data) {
            $_code = $data['_code'];
            $codeIndex = array_search($_code, $result);
            if (!isset($configArray[$_code])) continue;
            foreach($data['before'] as $beforeCode) {
                if (!isset($configArray[$beforeCode])) continue;
                $bIndex = array_search($beforeCode, $result);
                $this->assertTrue($codeIndex < $bIndex, "Condition not fullfilled: $codeIndex < $bIndex");
            }
            foreach($data['after'] as $afterCode) {
                if (!isset($configArray[$afterCode])) continue;
                $aIndex = array_search($afterCode, $result);
                $this->assertTrue($codeIndex > $aIndex, "Condition not fullfilled: $codeIndex > $aIndex");
            }
        }

@IvanChepurnyi
Copy link
Contributor

Hi Amenk.
Check this pull request submitted by me: #49

It has already a fixed solution with integration test that confirmes that fix is working.

@amenk
Copy link
Contributor Author

amenk commented Aug 20, 2012

Hi Ivan,

thanks for the comment - I wish I saw that pull request earlier...

Alex

@magento-team
Copy link
Contributor

@amenk
Thank you for yet another contribution.

Recently (see pull request #49) we have implemented a library Magento_Data_Graph, which allows depth-first search (DFS). The topological search algorithm is known to be based on the DFS algorithm -- would you try redo your contribution to add the search algorithm to graph class and then utilize it for sorting sales totals?

@amenk
Copy link
Contributor Author

amenk commented Aug 31, 2012

Okay. Can you give me a ping as soon as the Magento_Data_Graph is available in the git - I did not find it.

But I think the "drawback" of using the topological sort will be that if the ordering is not possible it would fail. See the discussion in #49 - so I do not know if it will be possible to still "sell" if there are problems.

@magento-team
Copy link
Contributor

@amenk Magento_Data_Graph is available since Sep 5, 2012.

As you mentioned, there are drawbacks in a case of ambiguous input data. Feel free to close the ticket, if you think this ticket is no longer actual after the contribution #49 has been accepted.

@amenk
Copy link
Contributor Author

amenk commented Sep 25, 2012

I will try to implement a check when sorting the data as an addition to #49 and log an exception when there are contradictions.

@magento-team
Copy link
Contributor

Hello Amenk, any luck with implementing this one?

@amenk
Copy link
Contributor Author

amenk commented Oct 17, 2012

Did not have a time yet.

I thought again about your suggestion in the other ticket to implement it in a CI test. Not sure about that.

I think if I integrate it with the Magento_Data_Graph you would use my functionality only to verify and log an exception but use Ivan's patch to do the actual sorting?

Is such a double-check and double-sorting intended ?

What do you think?

@magento-team
Copy link
Contributor

In the particular case with checkout -- yes, we'd have to use this algorithm only to verify and log an exception.

But also we intend to utilize topological sorting in future for other places:

  • Across the board, where sorting elements is based on "before" and "after" attributes
  • In core layout and sales totals, admin menu, PEAR packages (Mage_Connect), module dependencies, admin system configuration (system.xml)

@magento-team
Copy link
Contributor

Is such a double-check and double-sorting intended ?
Yes, it is intended as we described in Ivan's ticket: #49 (comment)

@amenk
Copy link
Contributor Author

amenk commented Oct 17, 2012

Alright. What algorithms are used in those cases currently.

Please be aware, that the algorithm I suggest will fail if there are any contradictions. (which I do not think is a problem - but basically the discussion is the same like in #49) You mentioned also sales totals - isn't that the same use case?

@kirmorozov
Copy link
Member

Here's the code for sorting one way,
http://pubsvn.ez.no/doxygen/trunk/html/ezptopologicalsort_8php_source.html
And before is the same is opposite depends on for constructor.
Cant you just copy over GPL code?

@amenk
Copy link
Contributor Author

amenk commented Oct 18, 2012

I actually used the code from http://www.calcatraz.com/blog/php-topological-sort-function-384 which is without license, means public domain.

@magento-team
Copy link
Contributor

But also we intend to utilize topological sorting in future for other places:
... sales totals ...

You mentioned also sales totals - isn't that the same use case?

Right. It was listed there by mistake, please disregard that part.

@magento-team
Copy link
Contributor

Hi. Would you be able to contribute topological sorting in Magento_Data_Graph? (and if you can add test/cases that would be great)

@magento-team
Copy link
Contributor

Closing the thread due to no recent activity.

magento-team pushed a commit that referenced this pull request Jan 30, 2015
[Mavericks] Convert all fixtures/repositories for functional tests into *.xml files
okorshenko pushed a commit that referenced this pull request Oct 28, 2015
MAGETWO-44707: Remove @api sign from CatalogInventory module
@ghost ghost mentioned this pull request Oct 21, 2017
magento-engcom-team pushed a commit that referenced this pull request Oct 8, 2018
MQE-1068: Require Issue ID for Skipped Test
@FabXav FabXav mentioned this pull request Oct 11, 2024
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants