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