| Conditions | 6 |
| Total Lines | 79 |
| Lines | 0 |
| Ratio | 0 % |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import functools |
||
| 84 | def run(self, |
||
| 85 | counting_conditions: counting_condition_dict=default_cc_dict, |
||
| 86 | average_calculation: bool=False, |
||
| 87 | poly_postprocessing: bool=True, |
||
| 88 | exp_postprocessing: bool=False, |
||
| 89 | extra_include_paths: path_list=()): |
||
| 90 | ''' |
||
| 91 | Retrieves similarities for code clone detection. Those can be reused in |
||
| 92 | another bear to produce results. |
||
| 93 | |||
| 94 | Postprocessing may be done because small functions are less likely to |
||
| 95 | be clones at the same difference value than big functions which may |
||
| 96 | provide a better refactoring opportunity for the user. |
||
| 97 | |||
| 98 | :param counting_conditions: A comma seperated list of counting |
||
| 99 | conditions. Possible values are: used, |
||
| 100 | returned, is_condition, in_condition, |
||
| 101 | in_second_level_condition, |
||
| 102 | in_third_level_condition, is_assignee, |
||
| 103 | is_assigner, loop_content, |
||
| 104 | second_level_loop_content, |
||
| 105 | third_level_loop_content, is_param, |
||
| 106 | in_sum, in_product, in_binary_operation, |
||
| 107 | member_accessed. |
||
| 108 | Weightings can be assigned to each |
||
| 109 | condition due to providing a dict |
||
| 110 | value, i.e. having used weighted in |
||
| 111 | half as much as other conditions would |
||
| 112 | simply be: "used: 0.5, is_assignee". |
||
| 113 | Weightings default to 1 if unset. |
||
| 114 | :param average_calculation: If set to true the difference calculation |
||
| 115 | function will take the average of all |
||
| 116 | variable differences as the difference, |
||
| 117 | else it will normalize the function as a |
||
| 118 | whole and thus weighting in variables |
||
| 119 | dependent on their size. |
||
| 120 | :param poly_postprocessing: If set to true, the difference value of big |
||
| 121 | function pairs will be reduced using a |
||
| 122 | polynomial approach. |
||
| 123 | :param extra_include_paths: A list containing additional include paths. |
||
| 124 | :param exp_postprocessing: If set to true, the difference value of big |
||
| 125 | function pairs will be reduced using an |
||
| 126 | exponential approach. |
||
| 127 | ''' |
||
| 128 | self.debug("Using the following counting conditions:") |
||
| 129 | for key, val in counting_conditions.items(): |
||
| 130 | self.debug(" *", key.__name__, "(weighting: {})".format(val)) |
||
| 131 | |||
| 132 | self.debug("Creating count matrices...") |
||
| 133 | count_matrices = get_count_matrices( |
||
| 134 | ClangCountVectorCreator(list(counting_conditions.keys()), |
||
| 135 | list(counting_conditions.values())), |
||
| 136 | list(self.file_dict.keys()), |
||
| 137 | lambda prog: self.debug("{:2.4f}%...".format(prog)), |
||
| 138 | self.section["files"].origin, |
||
| 139 | collect_dirs(extra_include_paths)) |
||
| 140 | |||
| 141 | self.debug("Calculating differences...") |
||
| 142 | |||
| 143 | differences = [] |
||
| 144 | function_count = len(count_matrices) |
||
| 145 | # Thats n over 2, hardcoded to simplify calculation |
||
| 146 | combination_length = function_count * (function_count-1) / 2 |
||
| 147 | partial_get_difference = functools.partial( |
||
| 148 | get_difference, |
||
| 149 | count_matrices=count_matrices, |
||
| 150 | average_calculation=average_calculation, |
||
| 151 | poly_postprocessing=poly_postprocessing, |
||
| 152 | exp_postprocessing=exp_postprocessing) |
||
| 153 | |||
| 154 | for i, elem in enumerate( |
||
| 155 | map(partial_get_difference, |
||
| 156 | [(f1, f2) for f1, f2 in combinations(count_matrices, 2)])): |
||
| 157 | if i % 50 == 0: |
||
| 158 | self.debug("{:2.4f}%...".format(100*i/combination_length)) |
||
| 159 | differences.append(elem) |
||
| 160 | |||
| 161 | yield HiddenResult(self, differences) |
||
| 162 | yield HiddenResult(self, count_matrices) |
||
| 163 |