| Conditions | 13 |
| Total Lines | 57 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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:
Complex classes like Runner.__exportToLatex() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | from __future__ import print_function # for backward compatibility purpose |
||
| 122 | def __exportToLatex(self): |
||
| 123 | metrics = ['Best', 'Median', 'Worst', 'Mean', 'Std.'] |
||
| 124 | |||
| 125 | with open(self.__generateExportName('tex'), 'a') as outFile: |
||
| 126 | outFile.write('\\begin{table}[h]\n') |
||
| 127 | outFile.write('\\centering\n') |
||
| 128 | |||
| 129 | begin_tabular = '\\begin{tabular}{c|c' |
||
| 130 | |||
| 131 | for alg in self.results: |
||
| 132 | for _i in range(len(self.results[alg])): |
||
| 133 | begin_tabular += '|c' |
||
| 134 | |||
| 135 | firstLine = ' &' |
||
| 136 | |||
| 137 | for benchmark in self.results[alg].keys(): |
||
| 138 | firstLine += ' & ' + benchmark |
||
| 139 | |||
| 140 | firstLine += ' \\\\' |
||
| 141 | |||
| 142 | break |
||
| 143 | |||
| 144 | begin_tabular += '}\n' |
||
| 145 | outFile.write(begin_tabular) |
||
| 146 | outFile.write('\\hline\n') |
||
| 147 | outFile.write(firstLine + '\n') |
||
| 148 | outFile.write('\\hline\n') |
||
| 149 | |||
| 150 | for alg in self.results: |
||
| 151 | for metric in metrics: |
||
| 152 | line = '' |
||
| 153 | |||
| 154 | if metric != 'Worst': |
||
| 155 | line += ' & ' + metric |
||
| 156 | else: |
||
| 157 | line += alg + ' & ' + metric |
||
| 158 | |||
| 159 | for benchmark in self.results[alg]: |
||
| 160 | if metric == 'Best': |
||
| 161 | line += ' & ' + str(np.amin(self.results[alg][benchmark])) |
||
| 162 | elif metric == 'Median': |
||
| 163 | line += ' & ' + str(np.median(self.results[alg][benchmark])) |
||
| 164 | elif metric == 'Worst': |
||
| 165 | line += ' & ' + str(np.amax(self.results[alg][benchmark])) |
||
| 166 | elif metric == 'Mean': |
||
| 167 | line += ' & ' + str(np.mean(self.results[alg][benchmark])) |
||
| 168 | else: |
||
| 169 | line += ' & ' + str(np.std(self.results[alg][benchmark])) |
||
| 170 | |||
| 171 | line += ' \\\\' |
||
| 172 | outFile.write(line + '\n') |
||
| 173 | |||
| 174 | outFile.write('\\hline\n') |
||
| 175 | outFile.write('\\end{tabular}\n') |
||
| 176 | outFile.write('\\end{table}\n') |
||
| 177 | |||
| 178 | logger.info('Export to Latex completed!') |
||
| 179 | |||
| 218 |