|
16 | 16 | import os
|
17 | 17 | import pandas as pd
|
18 | 18 | import plotly.io
|
19 |
| -from reports import Report |
| 19 | +from jinja2 import Environment, FileSystemLoader |
20 | 20 | import plotly.express as px
|
21 | 21 |
|
22 | 22 |
|
23 | 23 |
|
24 | 24 | AMOUNT_OF_TESTS_IN_TOP = 3
|
25 |
| -RESULT_PATH = "../target/coppers_results/" |
| 25 | +RESULT_PATH = "../results/" |
26 | 26 |
|
27 | 27 |
|
28 | 28 | def is_coppers_file(filename):
|
@@ -146,31 +146,46 @@ def comparison_to_last(data):
|
146 | 146 |
|
147 | 147 |
|
148 | 148 | def main():
|
149 |
| - rep = Report("template") |
| 149 | + env = Environment() |
| 150 | + env.loader = FileSystemLoader("template") |
| 151 | + template = env.get_template("index.html") |
| 152 | + jinja = {} |
| 153 | + |
150 | 154 | results = get_data()
|
151 | 155 | amount_of_results = len([filename for filename in os.listdir(RESULT_PATH) if "json" in filename])
|
152 | 156 |
|
153 | 157 | if amount_of_results > 2:
|
154 |
| - rep.jinja['over_time'] = True |
155 |
| - rep.jinja['plot_energy_over_time'] = visualize_over_time() |
| 158 | + jinja['over_time'] = True |
| 159 | + jinja['plot_energy_over_time'] = visualize_over_time() |
156 | 160 |
|
157 | 161 | sorted_tests = sorted(results["tests"], reverse=True, key=lambda item: item["uj"])
|
158 | 162 | n = float(results["number_of_repeats"])
|
159 |
| - rep.jinja['amount_top'] = AMOUNT_OF_TESTS_IN_TOP |
160 |
| - rep.jinja['most_energy_consuming_names'] = [sorted_tests[i]['name'] for i in range(AMOUNT_OF_TESTS_IN_TOP)] |
161 |
| - rep.jinja['most_energy_consuming_usages'] = [sorted_tests[i]['uj']/n for i in range(AMOUNT_OF_TESTS_IN_TOP)] |
162 |
| - rep.jinja['least_energy_consuming_names'] = [sorted_tests[-(i+1)]['name'] for i in range(AMOUNT_OF_TESTS_IN_TOP)] |
163 |
| - rep.jinja['least_energy_consuming_usages'] = [sorted_tests[-(i+1)]['uj']/n for i in range(AMOUNT_OF_TESTS_IN_TOP)] |
| 163 | + jinja['amount_top'] = AMOUNT_OF_TESTS_IN_TOP |
| 164 | + jinja['most_energy_consuming_names'] = [sorted_tests[i]['name'] for i in range(AMOUNT_OF_TESTS_IN_TOP)] |
| 165 | + jinja['most_energy_consuming_usages'] = [sorted_tests[i]['uj']/n for i in range(AMOUNT_OF_TESTS_IN_TOP)] |
| 166 | + jinja['least_energy_consuming_names'] = [sorted_tests[-(i+1)]['name'] for i in range(AMOUNT_OF_TESTS_IN_TOP)] |
| 167 | + jinja['least_energy_consuming_usages'] = [sorted_tests[-(i+1)]['uj']/n for i in range(AMOUNT_OF_TESTS_IN_TOP)] |
164 | 168 |
|
165 | 169 | if amount_of_results > 1:
|
166 |
| - rep.jinja["compare_to_last"] = True |
167 |
| - rep.jinja["overall_change"], rep.jinja["comparison_table"] = comparison_to_last(results) |
| 170 | + jinja["compare_to_last"] = True |
| 171 | + jinja["overall_change"], jinja["comparison_table"] = comparison_to_last(results) |
168 | 172 |
|
169 |
| - rep.jinja['all_tests_plot'] = visualize_all_tests(sorted_tests, n) |
| 173 | + jinja['all_tests_plot'] = visualize_all_tests(sorted_tests, n) |
170 | 174 |
|
171 |
| - rep.create_report(onweb=False) |
| 175 | + generate_report(template, jinja) |
172 | 176 | print("------- Generated report of energy consumption results -------")
|
173 | 177 |
|
174 | 178 |
|
| 179 | +def generate_report(template, jinja): |
| 180 | + if not os.path.isdir("report"): |
| 181 | + os.mkdir("report") |
| 182 | + |
| 183 | + if not os.path.isdir("report/images"): |
| 184 | + os.mkdir("report/images") |
| 185 | + |
| 186 | + with open("report/index.html", "w") as fh: |
| 187 | + data = template.render(jinja) |
| 188 | + fh.write(data) |
| 189 | + |
175 | 190 | if __name__ == "__main__":
|
176 | 191 | main()
|
0 commit comments