Commit d972bc72 authored by Florian Fischer's avatar Florian Fischer
Browse files

enable mypy and fix/ignore all complaints

parent e3b55401
Pipeline #67418 failed with stage
in 41 seconds
......@@ -10,7 +10,7 @@ servers:
clients:
$(MAKE) -C clients/
check: check-pylint check-format
check: check-pylint check-format check-mypy
format:
yapf -i $(PYTHONFILES)
......@@ -21,6 +21,9 @@ check-format:
check-pylint:
pylint --rcfile=.pylint.rc -j 0 $(PYTHONFILES) || ./tools/check-pylint $$?
check-mypy:
mypy --ignore-missing-imports $(PYTHONFILES)
clean-emper-client:
rm -rf emper-client
git -C emper/ worktree prune
......
......@@ -6,7 +6,7 @@ import csv
import fnmatch
import io
from pathlib import Path
from typing import Sequence, Union
from typing import Iterable, Mapping, Optional, Sequence, Union
import numpy as np
......@@ -20,9 +20,9 @@ def to_number(string: str) -> Number:
DataPoint = Union[list[Number], Number]
ExperimentResults = dict[str, DataPoint]
ImplResults = dict[int, ExperimentResults]
EvaluationResults = dict[str, ImplResults]
ExperimentData = dict[str, DataPoint]
ImplData = dict[int, list[ExperimentData]]
EvaluationResults = dict[str, ImplData]
def collect_results(result_dir: Union[Path, str],
......@@ -55,7 +55,7 @@ def collect_results(result_dir: Union[Path, str],
data = {}
for impl, impl_dir in impl_dirs.items():
impl_d: ImplResults = {}
impl_d: ImplData = {}
data_files = impl_dir.glob(f'*.{file_extension}')
......@@ -64,8 +64,7 @@ def collect_results(result_dir: Union[Path, str],
configparser = ConfigParser()
configparser.read(data_path)
# convert everything to numbers if possible
exp_data = {}
exp_data: ExperimentData = {}
error = False
for k in ['connect_duration', 'echo_duration', 'total_duration']:
try:
......@@ -93,7 +92,8 @@ def collect_results(result_dir: Union[Path, str],
echos = sum(client_iterations)
exp_data['total_iterations'] = echos
iops = echos / (exp_data['echo_duration'] * 10**-9)
# We know that echo_duration is a Number so ignore mypy
iops = echos / (exp_data['echo_duration'] * 10**-9) # type: ignore
exp_data['iops'] = iops
if cons in impl_d:
......@@ -114,7 +114,8 @@ def collect_results(result_dir: Union[Path, str],
return data
ConnectionStats = dict[str, Number]
Stats = dict[str, float]
ConnectionStats = dict[str, Stats]
ImplStats = dict[int, ConnectionStats]
EvaluationStats = dict[str, ImplStats]
......@@ -127,28 +128,30 @@ def calculate_stats(data: EvaluationResults, warn=False) -> EvaluationStats:
for cons in impl_d:
cons_stats = {}
for k in impl_d[cons][0]:
all_k = [x[k] for x in impl_d[cons]]
for key in impl_d[cons][0]:
_values = [x[key] for x in impl_d[cons]]
if isinstance(all_k[0], list):
all_k = [x for l in all_k for x in l]
if isinstance(_values[0], list):
values = [x for l in _values for x in l] # type: ignore
else:
values = _values
cur_stats = {}
cur_stats['mean'] = np.mean(all_k)
cur_stats['median'] = np.median(all_k)
cur_stats['min'] = min(all_k)
cur_stats['max'] = max(all_k)
cur_stats['std'] = np.std(all_k)
cur_stats['mean'] = np.mean(values)
cur_stats['median'] = np.median(values)
cur_stats['min'] = min(values)
cur_stats['max'] = max(values)
cur_stats['std'] = np.std(values)
if warn:
precision = cur_stats['std'] / cur_stats['mean']
if precision > 0.05:
print('Warning: imprecise data impl:', end='')
print(
f' {impl}, c: {cons}, k: {k} p: {precision*100:.5}%'
f' {impl}, c: {cons}, k: {key} p: {precision*100:.5}%'
)
cons_stats[k] = cur_stats
cons_stats[key] = cur_stats
impl_stats[cons] = cons_stats
......@@ -157,14 +160,14 @@ def calculate_stats(data: EvaluationResults, warn=False) -> EvaluationStats:
return stats
def print_stats_for_variable(variable: str, stats: dict):
def print_stats_for_variable(variable: str, stats: Mapping):
print(f'{variable}: ', end='')
for name, value in stats.items():
print(f'{name}: {value}, ', end='')
print(f'std[%]: {(stats["std"]/stats["mean"])*100:.2f}%')
def print_stats(stats: EvaluationStats, variables: list):
def print_stats(stats: EvaluationStats, variables: Optional[Iterable]):
for impl, impl_stats in stats.items():
print(f'{impl}:')
for cons in sorted(list(impl_stats.keys())):
......@@ -200,7 +203,8 @@ def main():
parser.add_argument(
"--print-stats",
help="variables about which the collected statistics should be print",
nargs='*')
nargs='*',
default=['iops'])
args = parser.parse_args()
......
......@@ -11,7 +11,7 @@ import plot_utils
#https://stackoverflow.com/questions/2371436/evaluating-a-mathematical-expression-in-a-string
def _eval_with_stat(evaluation: str, stats: str, stat: str):
def _eval_with_stat(evaluation: str, stats, stat: str):
"""Helper to evaluate a datapoint description string as arithmetic operation"""
def _eval(node):
"""evaluate a arithmetic ast node"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment