예제 #1
0
    def test_sort_by_key_cast_int_desc(self):
        data = {'1': '1.4', '2': 5.2, '3': '3.3'}
        expected = OrderedDict([('3', '3.3'), ('2', 5.2), ('1', '1.4')])

        actual = helpers.sort(data, by='key', cast=int, desc=True)

        self.assertDictEqual(expected, actual)
예제 #2
0
    def test_sort_by_value_cast_float(self):
        data = {'1': '1.4', '2': 5.2, '3': '3.3'}
        expected = OrderedDict([('1', '1.4'), ('3', '3.3'), ('2', 5.2)])

        actual = helpers.sort(data, by='value', cast=float, desc=False)

        self.assertDictEqual(expected, actual)
예제 #3
0
    def test_sort_by_key_desc(self):
        data = {'one': 1, 'two': 2, 'three': 3}
        expected = OrderedDict([('two', 2), ('three', 3), ('one', 1)])

        actual = helpers.sort(data, by='key', cast=None, desc=True)

        self.assertDictEqual(expected, actual)
예제 #4
0
    def test_sort_defaults(self):
        data = {'one': 1, 'two': 2, 'three': 3}
        expected = OrderedDict([('one', 1), ('two', 2), ('three', 3)])

        actual = helpers.sort(data, by='value', cast=None, desc=False)

        self.assertDictEqual(expected, actual)
예제 #5
0
    def transform_review(self, review):
        """

        """
        patchsets = review['patchsets']

        reviewed_files, reviewed_modules = set(), set()
        for (_, patchset) in patchsets.items():
            for file in patchset['files']:
                reviewed_files.add(file)
                reviewed_modules.add(helpers.get_module_path(file))

        patchsets = helpers.sort(patchsets, by='key', cast=int, desc=True)
        committed_files, committed_modules = None, None
        for (_, patchset) in patchsets.items():
            committed_files = set(list(patchset['files'].keys()))
            committed_modules = set([
                    helpers.get_module_path(file) for file in committed_files
                ])
            break

        review['reviewed_files'] = list(reviewed_files)
        review['reviewed_modules'] = list(reviewed_modules)
        review['committed_files'] = list(committed_files)
        review['committed_modules'] = list(committed_modules)

        return review
예제 #6
0
def aggregate(oqueue, cqueue, num_doers):
    done = 0
    tfidfs = dict()
    while True:
        item = cqueue.get()
        if item == parallel.DD:
            done += 1
            if done == num_doers:
                break
            continue
        (review_id, tfidf) = item
        tfidfs[review_id] = helpers.sort(tfidf, by='value', desc=True)
    oqueue.put(tfidfs)
예제 #7
0
 def stat_reviews(self, year):
     """
     Return a dictionary of fields for all of the reviews associated with
     the specified year.
     """
     stats = dict()
     reviews = list(self.get_reviews(year))
     stats['reviews'] = len(reviews)
     stats['open'] = len(
             [review['issue'] for review in reviews if not review['closed']]
         )
     (messages, comments, patchsets) = (dict(), dict(), dict())
     for review in reviews:
         id = review['issue']
         messages[id] = len(review['messages'])
         patchsets[id] = len(review['patchsets'])
         comments[id] = 0
         for patchset in review['patchsets'].values():
             comments[id] += patchset['num_comments']
     stats['messages'] = helpers.sort(messages, desc=True)
     stats['comments'] = helpers.sort(comments, desc=True)
     stats['patchsets'] = helpers.sort(patchsets, desc=True)
     return stats