Skip to content
Snippets Groups Projects
Commit 93265e73 authored by Florian Fischer's avatar Florian Fischer
Browse files

add more type hints and fail with python exceptions

parent a8fd0deb
Branches
Tags
No related merge requests found
...@@ -2,11 +2,14 @@ ...@@ -2,11 +2,14 @@
"""generate boxplots from descriptive stats in yaml""" """generate boxplots from descriptive stats in yaml"""
import sys import sys
import typing as T
import yaml import yaml
Data = dict[str, T.Any]
def parse_data(stream):
def parse_data(stream) -> T.Optional[Data]:
"""Convert yamls string to dict""" """Convert yamls string to dict"""
return yaml.safe_load(stream) return yaml.safe_load(stream)
...@@ -49,7 +52,7 @@ PLOT_TEMPLATE = \ ...@@ -49,7 +52,7 @@ PLOT_TEMPLATE = \
""" """
def generate_boxplot(data) -> str: def generate_boxplot(data: Data) -> str:
"""generate a tikzboxplot""" """generate a tikzboxplot"""
plots = '' plots = ''
for variant, stats in data.items(): for variant, stats in data.items():
...@@ -71,6 +74,10 @@ def main(): ...@@ -71,6 +74,10 @@ def main():
with open(sys.argv[1], 'r', encoding='utf-8') as yaml_file: with open(sys.argv[1], 'r', encoding='utf-8') as yaml_file:
data = parse_data(yaml_file) data = parse_data(yaml_file)
if data is None:
print('No data to plot', file=sys.stderr)
sys.exit(1)
tikz = generate_boxplot(data) tikz = generate_boxplot(data)
if len(sys.argv) > 2: if len(sys.argv) > 2:
......
#!/bin/bash #!/bin/bash
set -o pipefail set -eo pipefail
SUM=./summarize.py SUM=./summarize.py
PLOT=./gen_boxplots.py PLOT=./gen_boxplots.py
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
"""Collect and summarize evaluation results""" """Collect and summarize evaluation results"""
import argparse import argparse
import os
import sys import sys
import typing as T import typing as T
from pathlib import Path from pathlib import Path
...@@ -15,13 +14,8 @@ Measurements = list[int] ...@@ -15,13 +14,8 @@ Measurements = list[int]
Data = dict[Variant, Measurements] Data = dict[Variant, Measurements]
def collect(result_dir) -> T.Optional[Data]: def collect(result_dir) -> Data:
"""Collect the data in result_dir and return calculated averages""" """Collect the data in result_dir and return calculated averages"""
if not result_dir or not os.path.exists(result_dir) or not os.path.isdir(
result_dir):
print(f'{result_dir} is not a directory')
return None
result_dir = Path(result_dir) result_dir = Path(result_dir)
data = {} data = {}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment