| Conditions | 9 |
| Total Lines | 57 |
| 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 py |
||
| 34 | def make_plot(benchmarks, title, adjustment): |
||
| 35 | class Style(DefaultStyle): |
||
| 36 | colors = ["#000000" if row["path"] else DefaultStyle.colors[1] |
||
| 37 | for row in benchmarks] |
||
| 38 | font_family = 'Consolas, "Deja Vu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace' |
||
| 39 | |||
| 40 | minimum = int(min(row["min"] * adjustment for row in benchmarks)) |
||
| 41 | maximum = int(max( |
||
| 42 | min(row["max"], row["hd15iqr"]) * adjustment |
||
| 43 | for row in benchmarks |
||
| 44 | ) + 1) |
||
| 45 | |||
| 46 | try: |
||
| 47 | import pygaljs |
||
| 48 | except ImportError: |
||
| 49 | opts = {} |
||
| 50 | else: |
||
| 51 | opts = { |
||
| 52 | "js": [ |
||
| 53 | pygaljs.uri("2.0.x", "pygal-tooltips.js") |
||
| 54 | ] |
||
| 55 | } |
||
| 56 | print(["{0[name]}".format(row) for row in benchmarks]) |
||
| 57 | plot = CustomBox( |
||
| 58 | box_mode='tukey', |
||
| 59 | x_label_rotation=-90, |
||
| 60 | x_labels=["{0[name]}".format(row) for row in benchmarks], |
||
| 61 | show_legend=False, |
||
| 62 | title=title, |
||
| 63 | x_title="Trial", |
||
| 64 | y_title="Duration", |
||
| 65 | style=Style, |
||
| 66 | min_scale=20, |
||
| 67 | max_scale=20, |
||
| 68 | truncate_label=50, |
||
| 69 | range=(minimum, maximum), |
||
| 70 | zero=minimum, |
||
| 71 | css=[ |
||
| 72 | "file://style.css", |
||
| 73 | "file://graph.css", |
||
| 74 | """inline: |
||
| 75 | .tooltip .value { |
||
| 76 | font-size: 1em !important; |
||
| 77 | } |
||
| 78 | .axis text { |
||
| 79 | font-size: 9px !important; |
||
| 80 | } |
||
| 81 | """ |
||
| 82 | ], |
||
| 83 | **opts |
||
| 84 | ) |
||
| 85 | |||
| 86 | for row in benchmarks: |
||
| 87 | serie = [row[field] * adjustment for field in ["min", "ld15iqr", "q1", "median", "q3", "hd15iqr", "max"]] |
||
| 88 | serie.append(row["path"]) |
||
| 89 | plot.add("{0[fullname]} - {0[rounds]} rounds".format(row), serie) |
||
| 90 | return plot |
||
| 91 | |||
| 110 |