Conditions | 2 |
Total Lines | 70 |
Code Lines | 48 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 | #!/usr/bin/env python3 |
||
44 | def render_items(): |
||
45 | _items = '' |
||
46 | results = database.sort_by_average( |
||
47 | database.get_last_results() |
||
48 | ) |
||
49 | |||
50 | for result in results: |
||
51 | _target = database.get_target_by_attribute(result['title'], 'title') |
||
52 | _item = render_template('partials/item.html.j2', |
||
53 | title=result['title'], |
||
54 | url=result['url'], |
||
55 | last_report=result['report'], |
||
56 | identifier=_target['identifier'], |
||
57 | graph_values_y=','.join(map(str, database.get_history_by_attribute( |
||
58 | _target, 'performance'))), |
||
59 | graph_values_x=','.join(map(str, database.get_history_by_attribute( |
||
60 | _target, 'date'))), |
||
61 | graph_values_text=','.join(map(str, database.get_history_by_attribute( |
||
62 | _target, 'report'))), |
||
63 | circle_average=render_percentage_circle( |
||
64 | description=f'<strong>Average</strong><br/>' |
||
65 | f'Calculates all available performance values to an average value.<br/><br/>' |
||
66 | f'Maximum value: {int(result["average"]["max"])}<br/>' |
||
67 | f'Minimum value: {int(result["average"]["min"])}<br/>', |
||
68 | value=result['average']['value'] |
||
69 | ), |
||
70 | circle_performance=render_percentage_circle( |
||
71 | trend=render_trend(result), |
||
72 | description=f'<strong>Performance</strong><br/>' |
||
73 | f'The performance score is calculated directly from various metrics.<br/><br/>' |
||
74 | f'Click here to get more information from the last report.', |
||
75 | url=f'{result["report"]}#performance', |
||
76 | value=result['performance'] |
||
77 | ), |
||
78 | circle_accessibility=render_percentage_circle( |
||
79 | description=f'<strong>Accessibility</strong><br/>' |
||
80 | f'These checks highlight opportunities to improve the accessibility of ' |
||
81 | f'your web app.<br/><br/>' |
||
82 | f'Click here to get more information from the last report.', |
||
83 | value=result['accessibility'], |
||
84 | url=f'{result["report"]}#accessibility', |
||
85 | additional_class='small' |
||
86 | ), |
||
87 | circle_best_practices=render_percentage_circle( |
||
88 | description=f'<strong>Best practices</strong><br/>' |
||
89 | f'Further information about best practices.' |
||
90 | f'See the lighthouse report for further information.<br/><br/>' |
||
91 | f'Click here to get more information from the last report.', |
||
92 | value=result['best-practices'], |
||
93 | url=f'{result["report"]}#best-practices', |
||
94 | additional_class='small' |
||
95 | ), |
||
96 | circle_seo=render_percentage_circle( |
||
97 | description=f'<strong>SEO</strong><br/>' |
||
98 | f'These checks ensure that your page is optimized for search engine ' |
||
99 | f'results ranking.<br/><br/>' |
||
100 | f'Click here to get more information from the last report.', |
||
101 | value=result['seo'], |
||
102 | url=f'{result["report"]}#seo', |
||
103 | additional_class='small' |
||
104 | ), |
||
105 | api_json=f'{utility.get_data_dir(absolute_path=False)}_{_target["identifier"]}.json', |
||
106 | badge_average=f'{utility.get_data_dir(absolute_path=False)}_{_target["identifier"]}.average.svg', |
||
107 | badge_performance=f'{utility.get_data_dir(absolute_path=False)}_{_target["identifier"]}.performance.svg', |
||
108 | badge_accessibility=f'{utility.get_data_dir(absolute_path=False)}_{_target["identifier"]}.accessibility.svg', |
||
109 | badge_best_practices=f'{utility.get_data_dir(absolute_path=False)}_{_target["identifier"]}.best-practices.svg', |
||
110 | badge_seo=f'{utility.get_data_dir(absolute_path=False)}_{_target["identifier"]}.seo.svg', |
||
111 | ) |
||
112 | _items += _item |
||
113 | return _items |
||
114 | |||
196 |