-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_report.py
executable file
·64 lines (55 loc) · 3.15 KB
/
create_report.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# this command-line tool can take two arguments which must be preceded by their respective flags
# 1) -f : (REQUIRED) The CSV file that has four columns:
# original_path, normalized_path, predicted_class, predicted_conf
# 2) -s : (OPTIONAL) The path to the saved html path. If this argument is not specified,
# a 'reports' directory will be created where 'reports.html' will be saved.
# 3) -x : (OPTIONAL) Substring that indicates the start of the normalized image path that will follow the normalized-url.
# 4) -n : (OPTIONAL) HTTP url which the normalized image paths will be made relative to.
# 5) -O : (OPTIONAL) Indicates whether the HTML report should be opened in default browser
# 6) -A : (OPTIONAL) Indicates whether aggregate data table will be created
from src.utils.classifier_report import DataParser, ReportGenerator
from pathlib import Path
import argparse
import os
parser = argparse.ArgumentParser()
parser.add_argument('-f', '--file-path', type=Path, required=True,
help="Path to csv file that will be used to generate html page.")
parser.add_argument('-s', '--output-path', type=Path, default=False, required=False,
help="Path to output HTML report. Defaults to src/report/report.html")
parser.add_argument('-x', '--substring', default="/shared/", required=False,
help="Substring that indicates the start of the normalized image path that will follow the normalized-url.")
parser.add_argument('-n', '--normalized-url', default=False, required=False,
help="URL which normalized image paths will be made relative to.")
parser.add_argument('-O', '--open', action='store_true', required=False,
help="Flag indicates to open the html report in system's default browser.")
parser.add_argument('-A', '--agg-data', action='store_true', required=False,
help="Parser will provide additional table with aggregate data.")
# command line arguments
args = parser.parse_args()
print(f'CSV path: {args.file_path}')
print(f'Outpath path: {args.output_path}')
print(f'Normalized HTTP URL: {args.normalized_url}')
# check that input path is a csv file
assert os.path.splitext(args.file_path)[-1].lower() == '.csv'
# if provided, checks the output path is a html file
if args.output_path:
assert os.path.splitext(args.output_path)[-1].lower() == '.html'
# initializes data parser and report generator objects
parser = DataParser(args.file_path, args.normalized_url, args.substring)
generator = ReportGenerator()
# parser creates item-level data and aggregate data if indicated
data = parser.get_data()
stats = False
if args.agg_data:
stats = parser.get_stats()
# create url for csv download
if args.normalized_url:
csv_url = parser.normalize_to_url(str(args.file_path), args.normalized_url, '/reports/')
else:
csv_url = os.path.abspath(args.file_path)
# generate html page and saves it
generator.create_html_page(data, csv_url, stats)
generator.save_file(args.output_path)
# if indicated, opens html report in browser
if args.open:
generator.launch_page()