def get_average_cc(self): ''' Calculate the CC of every file in the tmp directory of Blobs CCHarvester returns a block of metrics for each function, class and method in a given file in dict format. CC is contained in this dict and is totalled for the file. Tmp directory is cleaned up afterwards ''' results = CCHarvester(self.cc_path, self.cc_config)._to_dicts() if results == {}: rmtree('tmp') return 0 total_cc = 0 for filename in results.values(): file_cc = 0 for block in filename: try: file_cc += block['complexity'] except TypeError: print( "CC failed, file in script format with no classes/functions" ) total_cc += file_cc rmtree('tmp') return total_cc / len(results)
def doWork(self): print 3 config = Config(exclude='', ignore='venv', order=SCORE, no_assert=True, show_closures=False, min='A', max='F') complexity = CCHarvester('./worker1tempfolder', config)._to_dicts() print 4 print complexity print 5 print complexity.values() totalComplexity = 0 for doc in complexity.values(): docComplexity = 0 for codeBlock in doc: docComplexity = docComplexity + codeBlock['complexity'] totalComplexity = totalComplexity + docComplexity self.deletefiles() return total_cc / len(complexity)