forked from nishimotz/as_info_publish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
results_yaml_to_csv.py
52 lines (48 loc) · 1.56 KB
/
results_yaml_to_csv.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
import yaml
import pandas as pd
import click
@click.command()
@click.option(
"--src", "-s", default="../as_info/data/results.yaml",
help="name of input yaml file", show_default=True
)
@click.option(
"--dest",
"-d",
default="results_new.csv",
help="name of output csv (or xlsx) file",
show_default=True
)
@click.option(
"--excel",
"-e",
is_flag=True,
help="use to_excel rather than to_csv",
)
@click.option("--sheet", "-s", default="results", help="output sheet name of xlsx file", show_default=True)
def main(src, dest, excel, sheet):
with open(src, "r") as y:
results = yaml.safe_load(y)
for result in results:
contents = result.get("contents")
if contents:
for index, item in enumerate(contents):
for name in ("expected", "procedure", "actual", "judgment"):
result[f"{name}{index+1}"] = item.get(name)
del result["contents"]
df = pd.json_normalize(results)
columns = "id,test,date,tester,os,user_agent,assistive_tech,assistive_tech_config,expected1,procedure1,actual1,judgment1,expected2,procedure2,actual2,judgment2,expected3,procedure3,actual3,judgment3,expected4,procedure4,actual4,judgment4,comment,reviewer_comment".split(
","
)
if excel:
df.to_excel(
dest,
sheet,
index=False,
columns=columns,
engine="openpyxl",
)
else:
df.to_csv(dest, encoding="utf-8-sig", index=False, columns=columns, quoting=2)
if __name__ == "__main__":
main()