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)
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)
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)
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)
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
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)
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