GithubHelp home page GithubHelp logo

Comments (10)

johnmhoran avatar johnmhoran commented on June 7, 2024 1

Thanks @MaJuRG . Coincidentally, I've already rewritten get_stats:

    def get_stats(self):
        """
        Given a list of Delta objects, return a 'counts' dictionary keyed by
        category -- i.e., the keys of the determine_delta() OrderedDict of
        Delta objects -- that contains the count as a value for each category.
        """
        added, modified, moved, removed, unmodified = 0, 0, 0, 0, 0

        # added = len(self.deltas['added'])
        # modified = len(self.deltas['modified'])
        # moved = len(self.deltas['moved'])
        # removed = len(self.deltas['removed'])
        # unmodified = len(self.deltas['unmodified'])

        added = len([i for i in self.deltas if i.category == 'added'])
        modified = len([i for i in self.deltas if i.category == 'modified'])
        moved = len([i for i in self.deltas if i.category == 'moved'])
        removed = len([i for i in self.deltas if i.category == 'removed'])
        unmodified = len([i for i in self.deltas if i.category == 'unmodified'])

from deltacode.

johnmhoran avatar johnmhoran commented on June 7, 2024

@MaJuRG Making my way through the flattening process. Re DeltaCode.to_dict(), is it accurate to say that we . . .

  • . . . want to convert DeltaCode.to_dict() so that it returns a single list of Delta objects instead of an OrderedDict of Delta objects keyed by added, removed etc.?
  • . . . need to change the method name to, e.g., DeltaCode.to_list()?
  • . . . could sort by Delta.score inside this method before returning the list?

from deltacode.

steven-esser avatar steven-esser commented on June 7, 2024

@johnmhoran We do not care about to_dict or to_list.

We want to change the Deltacode.deltas field to a list of Delta objects instead of a dictionary as it currently is

from deltacode.

johnmhoran avatar johnmhoran commented on June 7, 2024

@MaJuRG I've already done that. My question is, what do we want to do with the current method, DeltaCode.to_dict()?

from deltacode.

steven-esser avatar steven-esser commented on June 7, 2024

It is not needed anymore in that case. We will need to replace code paths that use the old dict structure (few, mostly output related) and all code that calls Deltacode.to_dict() (many,mostly in tests).

from deltacode.

johnmhoran avatar johnmhoran commented on June 7, 2024

Thanks.

from deltacode.

johnmhoran avatar johnmhoran commented on June 7, 2024

@MaJuRG FYI I'm replacing tests that use DeltaCode.to_dict() with equivalent tests where possible. For example, I've replaced test_DeltaCode_to_dict_simple_file_added() with this:

    def test_DeltaCode_counts_simple_file_added(self):
        new_scan = self.get_test_loc('deltacode/new_added1.json')
        old_scan = self.get_test_loc('deltacode/old_added1.json')

        options = OrderedDict([
            ('--all-delta-types', False)
        ])

        deltacode = DeltaCode(new_scan, old_scan, options)

        assert (len([d.to_dict() for d in deltacode.deltas if d.category == 'added']) +
                len([d.to_dict() for d in deltacode.deltas if d.category == 'removed']) +
                len([d.to_dict() for d in deltacode.deltas if d.category == 'moved']) +
                len([d.to_dict() for d in deltacode.deltas if d.category == 'modified']) +
                len([d.to_dict() for d in deltacode.deltas if d.category == 'unmodified'])) == 9

        assert len([d.to_dict() for d in deltacode.deltas if d.category == 'added']) == 1
        assert len([d.to_dict() for d in deltacode.deltas if d.category == 'removed']) == 0
        assert len([d.to_dict() for d in deltacode.deltas if d.category == 'moved']) == 0
        assert len([d.to_dict() for d in deltacode.deltas if d.category == 'modified']) == 0
        assert len([d.to_dict() for d in deltacode.deltas if d.category == 'unmodified']) == 8

from deltacode.

steven-esser avatar steven-esser commented on June 7, 2024

@johnmhoran A better option may be to simply re-write get_stats() and use that for for the tests.

from deltacode.

steven-esser avatar steven-esser commented on June 7, 2024

to avoid massive duplications. Code of similar logic could be used in an updated get_stats()

from deltacode.

steven-esser avatar steven-esser commented on June 7, 2024

#66 Handles this. Closing.

from deltacode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.