Verified Commit 63c17f65 authored by Sebastian Endres's avatar Sebastian Endres
Browse files

Use left AND right pcap for plotting, plot right trace

parent 1da94eeb
......@@ -9,10 +9,11 @@ from typing import Literal, Optional, Union
from termcolor import colored, cprint
from plot_diagram import DEFAULT_TITLES, PlotCli, PlotMode
from enums import CacheMode, PlotMode
from plot_diagram import DEFAULT_TITLES, PlotCli
from result_parser import ExtendedMeasurementResult, Result
from tracer import ParsingError
from utils import create_relpath, existing_file_path
from utils import TraceTriple, create_relpath, existing_file_path
DEFAULT_TITLE = "{mode_default_title} ({test_abbr}, server: {server}, client: {client})"
......@@ -106,7 +107,7 @@ class PlotAllCli:
force=False,
only_sat=False,
include_failed=False,
modes: list[PlotMode] = [mode for mode in PlotMode],
modes: list[PlotMode] = list(PlotMode),
debug=False,
):
# self.log_dirs = log_dirs
......@@ -144,23 +145,38 @@ class PlotAllCli:
return ["testcase failed"]
pcaps: list[Path] = []
trace_triples = list[TraceTriple]()
for repetition_dir in measurement_result.repetition_log_dirs:
pcapng = (
repetition_dir
/ "sim"
/ f"trace_node_{self.side.value}_with_secrets.pcapng"
base_sim_path = repetition_dir / "sim"
trace_triple = TraceTriple(
left_pcap_path=base_sim_path
/ f"trace_node_{Side.LEFT.value}_with_secrets.pcapng",
right_pcap_path=base_sim_path
/ f"trace_node_{Side.LEFT.value}_with_secrets.pcapng",
)
if not pcapng.is_file():
print(f"⨯ {pcapng} does not exist", file=sys.stderr)
if not trace_triple.left_pcap_path.is_file():
cprint(
f"⨯ {trace_triple.left_pcap_path} does not exist",
color="red",
file=sys.stderr,
)
continue
if not trace_triple.right_pcap_path.is_file():
cprint(
f"⨯ {trace_triple.right_pcap_path} does not exist",
color="red",
file=sys.stderr,
)
continue
pcaps.append(pcapng)
trace_triples.append(trace_triple)
if not pcaps:
if not trace_triples:
cprint(
f"⨯ no pcapng files found for {test_case_dir}. Skipping...",
file=sys.stderr,
......@@ -170,9 +186,9 @@ class PlotAllCli:
return ["no traces files found"]
cli = PlotCli(
pcap_files=pcaps,
trace_triples=trace_triples,
annotate=self.annotate,
cache=True,
cache=CacheMode.LOAD,
debug=self.debug,
)
......@@ -198,7 +214,7 @@ class PlotAllCli:
cprint(
(
f"⚒ Plotting in {create_relpath(test_case_dir)} "
f"({len(pcaps)} traces) → {create_relpath(output_file)}"
f"({len(trace_triples)} trace pairs) → {create_relpath(output_file)}"
),
attrs=["bold"],
)
......
This diff is collapsed.
......@@ -6,6 +6,14 @@ category = "dev"
optional = false
python-versions = "*"
[[package]]
name = "appnope"
version = "0.1.2"
description = "Disable App Nap on macOS >= 10.9"
category = "dev"
optional = false
python-versions = "*"
[[package]]
name = "astroid"
version = "2.7.3"
......@@ -18,6 +26,14 @@ python-versions = "~=3.6"
lazy-object-proxy = ">=1.4.0"
wrapt = ">=1.11,<1.13"
[[package]]
name = "backcall"
version = "0.2.0"
description = "Specifications for callback functions passed in to an API"
category = "dev"
optional = false
python-versions = "*"
[[package]]
name = "backports.entry-points-selectable"
version = "1.1.0"
......@@ -101,6 +117,14 @@ python-versions = ">=3.6"
[package.extras]
dev = ["black", "flake8", "flake8-pyi", "matplotlib", "mypy (==0.770)", "numpy", "pandas", "pytest"]
[[package]]
name = "decorator"
version = "5.1.0"
description = "Decorators for Humans"
category = "dev"
optional = false
python-versions = ">=3.5"
[[package]]
name = "distlib"
version = "0.3.2"
......@@ -139,6 +163,51 @@ python-versions = ">=3.6.1"
[package.extras]
license = ["editdistance-s"]
[[package]]
name = "ipdb"
version = "0.13.9"
description = "IPython-enabled pdb"
category = "dev"
optional = false
python-versions = ">=2.7"
[package.dependencies]
decorator = {version = "*", markers = "python_version > \"3.6\""}
ipython = {version = ">=7.17.0", markers = "python_version > \"3.6\""}
toml = {version = ">=0.10.2", markers = "python_version > \"3.6\""}
[[package]]
name = "ipython"
version = "7.27.0"
description = "IPython: Productive Interactive Computing"
category = "dev"
optional = false
python-versions = ">=3.7"
[package.dependencies]
appnope = {version = "*", markers = "sys_platform == \"darwin\""}
backcall = "*"
colorama = {version = "*", markers = "sys_platform == \"win32\""}
decorator = "*"
jedi = ">=0.16"
matplotlib-inline = "*"
pexpect = {version = ">4.3", markers = "sys_platform != \"win32\""}
pickleshare = "*"
prompt-toolkit = ">=2.0.0,<3.0.0 || >3.0.0,<3.0.1 || >3.0.1,<3.1.0"
pygments = "*"
traitlets = ">=4.2"
[package.extras]
all = ["Sphinx (>=1.3)", "ipykernel", "ipyparallel", "ipywidgets", "nbconvert", "nbformat", "nose (>=0.10.1)", "notebook", "numpy (>=1.17)", "pygments", "qtconsole", "requests", "testpath"]
doc = ["Sphinx (>=1.3)"]
kernel = ["ipykernel"]
nbconvert = ["nbconvert"]
nbformat = ["nbformat"]
notebook = ["notebook", "ipywidgets"]
parallel = ["ipyparallel"]
qtconsole = ["qtconsole"]
test = ["nose (>=0.10.1)", "requests", "testpath", "pygments", "nbformat", "ipykernel", "numpy (>=1.17)"]
[[package]]
name = "isort"
version = "5.9.3"
......@@ -153,6 +222,21 @@ requirements_deprecated_finder = ["pipreqs", "pip-api"]
colors = ["colorama (>=0.4.3,<0.5.0)"]
plugins = ["setuptools"]
[[package]]
name = "jedi"
version = "0.18.0"
description = "An autocompletion tool for Python that can be used for text editors."
category = "dev"
optional = false
python-versions = ">=3.6"
[package.dependencies]
parso = ">=0.8.0,<0.9.0"
[package.extras]
qa = ["flake8 (==3.8.3)", "mypy (==0.782)"]
testing = ["Django (<3.1)", "colorama", "docopt", "pytest (<6.0.0)"]
[[package]]
name = "jinja2"
version = "3.0.1"
......@@ -221,6 +305,17 @@ pillow = ">=6.2.0"
pyparsing = ">=2.2.1"
python-dateutil = ">=2.7"
[[package]]
name = "matplotlib-inline"
version = "0.1.3"
description = "Inline Matplotlib backend for Jupyter"
category = "dev"
optional = false
python-versions = ">=3.5"
[package.dependencies]
traitlets = "*"
[[package]]
name = "mccabe"
version = "0.6.1"
......@@ -270,6 +365,18 @@ category = "main"
optional = false
python-versions = ">=3.7,<3.11"
[[package]]
name = "parso"
version = "0.8.2"
description = "A Python Parser"
category = "dev"
optional = false
python-versions = ">=3.6"
[package.extras]
qa = ["flake8 (==3.8.3)", "mypy (==0.782)"]
testing = ["docopt", "pytest (<6.0.0)"]
[[package]]
name = "pathspec"
version = "0.9.0"
......@@ -278,6 +385,25 @@ category = "dev"
optional = false
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7"
[[package]]
name = "pexpect"
version = "4.8.0"
description = "Pexpect allows easy control of interactive console applications."
category = "dev"
optional = false
python-versions = "*"
[package.dependencies]
ptyprocess = ">=0.5"
[[package]]
name = "pickleshare"
version = "0.7.5"
description = "Tiny 'shelve'-like database with concurrency support"
category = "dev"
optional = false
python-versions = "*"
[[package]]
name = "pillow"
version = "8.3.2"
......@@ -314,6 +440,20 @@ pyyaml = ">=5.1"
toml = "*"
virtualenv = ">=20.0.8"
[[package]]
name = "prettytable"
version = "2.2.0"
description = "A simple Python library for easily displaying tabular data in a visually appealing ASCII table format"
category = "main"
optional = false
python-versions = ">=3.6"
[package.dependencies]
wcwidth = "*"
[package.extras]
tests = ["pytest", "pytest-cov"]
[[package]]
name = "prompt-toolkit"
version = "3.0.20"
......@@ -325,6 +465,14 @@ python-versions = ">=3.6.2"
[package.dependencies]
wcwidth = "*"
[[package]]
name = "ptyprocess"
version = "0.7.0"
description = "Run a subprocess in a pseudo terminal"
category = "dev"
optional = false
python-versions = "*"
[[package]]
name = "py"
version = "1.10.0"
......@@ -333,6 +481,14 @@ category = "main"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
[[package]]
name = "pygments"
version = "2.10.0"
description = "Pygments is a syntax highlighting package written in Python."
category = "dev"
optional = false
python-versions = ">=3.5"
[[package]]
name = "pylint"
version = "2.10.2"
......@@ -420,6 +576,17 @@ category = "dev"
optional = false
python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*"
[[package]]
name = "traitlets"
version = "5.1.0"
description = "Traitlets Python configuration system"
category = "dev"
optional = false
python-versions = ">=3.7"
[package.extras]
test = ["pytest"]
[[package]]
name = "typed-ast"
version = "1.4.3"
......@@ -485,17 +652,25 @@ termcolor = ">=1.1.0,<2.0.0"
[metadata]
lock-version = "1.1"
python-versions = ">=3.9,<3.11"
content-hash = "2ded71ac90683d8f0dfc0800a2b74a4f8d9732b33cf51b1208fabd7bbdf379f1"
content-hash = "842665f1d2e794d0551896c8ab3c016e4d9686d9d0056a5e0264427effe25eda"
[metadata.files]
appdirs = [
{file = "appdirs-1.4.4-py2.py3-none-any.whl", hash = "sha256:a841dacd6b99318a741b166adb07e19ee71a274450e68237b4650ca1055ab128"},
{file = "appdirs-1.4.4.tar.gz", hash = "sha256:7d5d0167b2b1ba821647616af46a749d1c653740dd0d2415100fe26e27afdf41"},
]
appnope = [
{file = "appnope-0.1.2-py2.py3-none-any.whl", hash = "sha256:93aa393e9d6c54c5cd570ccadd8edad61ea0c4b9ea7a01409020c9aa019eb442"},
{file = "appnope-0.1.2.tar.gz", hash = "sha256:dd83cd4b5b460958838f6eb3000c660b1f9caf2a5b1de4264e941512f603258a"},
]
astroid = [
{file = "astroid-2.7.3-py3-none-any.whl", hash = "sha256:dc1e8b28427d6bbef6b8842b18765ab58f558c42bb80540bd7648c98412af25e"},
{file = "astroid-2.7.3.tar.gz", hash = "sha256:3b680ce0419b8a771aba6190139a3998d14b413852506d99aff8dc2bf65ee67c"},
]
backcall = [
{file = "backcall-0.2.0-py2.py3-none-any.whl", hash = "sha256:fbbce6a29f263178a1f7915c1940bde0ec2b2a967566fe1c65c1dfb7422bd255"},
{file = "backcall-0.2.0.tar.gz", hash = "sha256:5cbdbf27be5e7cfadb448baf0aa95508f91f2bbc6c6437cd9cd06e2a4c215e1e"},
]
"backports.entry-points-selectable" = [
{file = "backports.entry_points_selectable-1.1.0-py2.py3-none-any.whl", hash = "sha256:a6d9a871cde5e15b4c4a53e3d43ba890cc6861ec1332c9c2428c92f977192acc"},
{file = "backports.entry_points_selectable-1.1.0.tar.gz", hash = "sha256:988468260ec1c196dab6ae1149260e2f5472c9110334e5d51adcb77867361f6a"},
......@@ -523,6 +698,10 @@ data-science-types = [
{file = "data-science-types-0.2.23.tar.gz", hash = "sha256:8096b9a35a8a187bf9a122b4707c97de841d810744690ee2a4ac30c6462e0d16"},
{file = "data_science_types-0.2.23-py3-none-any.whl", hash = "sha256:bca319abc0e53a0316f9fcb887937e942477cb9e5fc63c8581e0b0438903b977"},
]
decorator = [
{file = "decorator-5.1.0-py3-none-any.whl", hash = "sha256:7b12e7c3c6ab203a29e157335e9122cb03de9ab7264b137594103fd4a683b374"},
{file = "decorator-5.1.0.tar.gz", hash = "sha256:e59913af105b9860aa2c8d3272d9de5a56a4e608db9a2f167a8480b323d529a7"},
]
distlib = [
{file = "distlib-0.3.2-py2.py3-none-any.whl", hash = "sha256:23e223426b28491b1ced97dc3bbe183027419dfc7982b4fa2f05d5f3ff10711c"},
{file = "distlib-0.3.2.zip", hash = "sha256:106fef6dc37dd8c0e2c0a60d3fca3e77460a48907f335fa28420463a6f799736"},
......@@ -539,10 +718,21 @@ identify = [
{file = "identify-2.2.14-py2.py3-none-any.whl", hash = "sha256:113a76a6ba614d2a3dd408b3504446bcfac0370da5995aa6a17fd7c6dffde02d"},
{file = "identify-2.2.14.tar.gz", hash = "sha256:32f465f3c48083f345ad29a9df8419a4ce0674bf4a8c3245191d65c83634bdbf"},
]
ipdb = [
{file = "ipdb-0.13.9.tar.gz", hash = "sha256:951bd9a64731c444fd907a5ce268543020086a697f6be08f7cc2c9a752a278c5"},
]
ipython = [
{file = "ipython-7.27.0-py3-none-any.whl", hash = "sha256:75b5e060a3417cf64f138e0bb78e58512742c57dc29db5a5058a2b1f0c10df02"},
{file = "ipython-7.27.0.tar.gz", hash = "sha256:58b55ebfdfa260dad10d509702dc2857cb25ad82609506b070cf2d7b7df5af13"},
]
isort = [
{file = "isort-5.9.3-py3-none-any.whl", hash = "sha256:e17d6e2b81095c9db0a03a8025a957f334d6ea30b26f9ec70805411e5c7c81f2"},
{file = "isort-5.9.3.tar.gz", hash = "sha256:9c2ea1e62d871267b78307fe511c0838ba0da28698c5732d54e2790bf3ba9899"},
]
jedi = [
{file = "jedi-0.18.0-py2.py3-none-any.whl", hash = "sha256:18456d83f65f400ab0c2d3319e48520420ef43b23a086fdc05dff34132f0fb93"},
{file = "jedi-0.18.0.tar.gz", hash = "sha256:92550a404bad8afed881a137ec9a461fed49eca661414be45059329614ed0707"},
]
jinja2 = [
{file = "Jinja2-3.0.1-py3-none-any.whl", hash = "sha256:1f06f2da51e7b56b8f238affdd6b4e2c61e39598a378cc49345bc1bd42a978a4"},
{file = "Jinja2-3.0.1.tar.gz", hash = "sha256:703f484b47a6af502e743c9122595cc812b0271f661722403114f71a79d0f5a4"},
......@@ -714,6 +904,10 @@ matplotlib = [
{file = "matplotlib-3.4.3-pp37-pypy37_pp73-manylinux2010_x86_64.whl", hash = "sha256:54a026055d5f8614f184e588f6e29064019a0aa8448450214c0b60926d62d919"},
{file = "matplotlib-3.4.3.tar.gz", hash = "sha256:fc4f526dfdb31c9bd6b8ca06bf9fab663ca12f3ec9cdf4496fb44bc680140318"},
]
matplotlib-inline = [
{file = "matplotlib-inline-0.1.3.tar.gz", hash = "sha256:a04bfba22e0d1395479f866853ec1ee28eea1485c1d69a6faf00dc3e24ff34ee"},
{file = "matplotlib_inline-0.1.3-py3-none-any.whl", hash = "sha256:aed605ba3b72462d64d475a21a9296f400a19c4f74a31b59103d2a99ffd5aa5c"},
]
mccabe = [
{file = "mccabe-0.6.1-py2.py3-none-any.whl", hash = "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42"},
{file = "mccabe-0.6.1.tar.gz", hash = "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"},
......@@ -783,10 +977,22 @@ numpy = [
{file = "numpy-1.21.2-pp37-pypy37_pp73-manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:d96a6a7d74af56feb11e9a443150216578ea07b7450f7c05df40eec90af7f4a7"},
{file = "numpy-1.21.2.zip", hash = "sha256:423216d8afc5923b15df86037c6053bf030d15cc9e3224206ef868c2d63dd6dc"},
]
parso = [
{file = "parso-0.8.2-py2.py3-none-any.whl", hash = "sha256:a8c4922db71e4fdb90e0d0bc6e50f9b273d3397925e5e60a717e719201778d22"},
{file = "parso-0.8.2.tar.gz", hash = "sha256:12b83492c6239ce32ff5eed6d3639d6a536170723c6f3f1506869f1ace413398"},
]
pathspec = [
{file = "pathspec-0.9.0-py2.py3-none-any.whl", hash = "sha256:7d15c4ddb0b5c802d161efc417ec1a2558ea2653c2e8ad9c19098201dc1c993a"},
{file = "pathspec-0.9.0.tar.gz", hash = "sha256:e564499435a2673d586f6b2130bb5b95f04a3ba06f81b8f895b651a3c76aabb1"},
]
pexpect = [
{file = "pexpect-4.8.0-py2.py3-none-any.whl", hash = "sha256:0b48a55dcb3c05f3329815901ea4fc1537514d6ba867a152b581d69ae3710937"},
{file = "pexpect-4.8.0.tar.gz", hash = "sha256:fc65a43959d153d0114afe13997d439c22823a27cefceb5ff35c2178c6784c0c"},
]
pickleshare = [
{file = "pickleshare-0.7.5-py2.py3-none-any.whl", hash = "sha256:9649af414d74d4df115d5d718f82acb59c9d418196b7b4290ed47a12ce62df56"},
{file = "pickleshare-0.7.5.tar.gz", hash = "sha256:87683d47965c1da65cdacaf31c8441d12b8044cdec9aca500cd78fc2c683afca"},
]
pillow = [
{file = "Pillow-8.3.2-cp310-cp310-macosx_10_10_universal2.whl", hash = "sha256:c691b26283c3a31594683217d746f1dad59a7ae1d4cfc24626d7a064a11197d4"},
{file = "Pillow-8.3.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:f514c2717012859ccb349c97862568fdc0479aad85b0270d6b5a6509dbc142e2"},
......@@ -850,14 +1056,26 @@ pre-commit = [
{file = "pre_commit-2.15.0-py2.py3-none-any.whl", hash = "sha256:a4ed01000afcb484d9eb8d504272e642c4c4099bbad3a6b27e519bd6a3e928a6"},
{file = "pre_commit-2.15.0.tar.gz", hash = "sha256:3c25add78dbdfb6a28a651780d5c311ac40dd17f160eb3954a0c59da40a505a7"},
]
prettytable = [
{file = "prettytable-2.2.0-py3-none-any.whl", hash = "sha256:b186f1db9c9377cb552cfa95a3b7a0feab6ec55d7cad7e0763bdcbea1e8f4687"},
{file = "prettytable-2.2.0.tar.gz", hash = "sha256:bd81678c108e6c73d4f1e47cd4283de301faaa6ff6220bcd1d4022038c56b416"},
]
prompt-toolkit = [
{file = "prompt_toolkit-3.0.20-py3-none-any.whl", hash = "sha256:6076e46efae19b1e0ca1ec003ed37a933dc94b4d20f486235d436e64771dcd5c"},
{file = "prompt_toolkit-3.0.20.tar.gz", hash = "sha256:eb71d5a6b72ce6db177af4a7d4d7085b99756bf656d98ffcc4fecd36850eea6c"},
]
ptyprocess = [
{file = "ptyprocess-0.7.0-py2.py3-none-any.whl", hash = "sha256:4b41f3967fce3af57cc7e94b888626c18bf37a083e3651ca8feeb66d492fef35"},
{file = "ptyprocess-0.7.0.tar.gz", hash = "sha256:5c5d0a3b48ceee0b48485e0c26037c0acd7d29765ca3fbb5cb3831d347423220"},
]
py = [
{file = "py-1.10.0-py2.py3-none-any.whl", hash = "sha256:3b80836aa6d1feeaa108e046da6423ab8f6ceda6468545ae8d02d9d58d18818a"},
{file = "py-1.10.0.tar.gz", hash = "sha256:21b81bda15b66ef5e1a777a21c4dcd9c20ad3efd0b3f817e7a809035269e1bd3"},
]
pygments = [
{file = "Pygments-2.10.0-py3-none-any.whl", hash = "sha256:b8e67fe6af78f492b3c4b3e2970c0624cbf08beb1e493b2c99b9fa1b67a20380"},
{file = "Pygments-2.10.0.tar.gz", hash = "sha256:f398865f7eb6874156579fdf36bc840a03cab64d1cde9e93d68f46a425ec52c6"},
]
pylint = [
{file = "pylint-2.10.2-py3-none-any.whl", hash = "sha256:e178e96b6ba171f8ef51fbce9ca30931e6acbea4a155074d80cc081596c9e852"},
{file = "pylint-2.10.2.tar.gz", hash = "sha256:6758cce3ddbab60c52b57dcc07f0c5d779e5daf0cf50f6faacbef1d3ea62d2a1"},
......@@ -959,6 +1177,10 @@ toml = [
{file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"},
{file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"},
]
traitlets = [
{file = "traitlets-5.1.0-py3-none-any.whl", hash = "sha256:03f172516916220b58c9f19d7f854734136dd9528103d04e9bf139a92c9f54c4"},
{file = "traitlets-5.1.0.tar.gz", hash = "sha256:bd382d7ea181fbbcce157c133db9a829ce06edffe097bcf3ab945b435452b46d"},
]
typed-ast = [
{file = "typed_ast-1.4.3-cp35-cp35m-manylinux1_i686.whl", hash = "sha256:2068531575a125b87a41802130fa7e29f26c09a2833fea68d9a40cf33902eba6"},
{file = "typed_ast-1.4.3-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:c907f561b1e83e93fad565bac5ba9c22d96a54e7ea0267c708bffe863cbe4075"},
......
......@@ -16,6 +16,7 @@ numpy = "^1.21.2"
yaspin = "^2.1.0"
humanize = "^3.11.0"
Jinja2 = "^3.0.1"
prettytable = "^2.2.0"
[tool.poetry.dev-dependencies]
pylint = "^2.6.0"
......@@ -23,6 +24,8 @@ mypy = "^0.910"
black = "^20.8b1"
data-science-types = "^0.2.22"
pre-commit = "^2.9.3"
ipython = "^7.27.0"
ipdb = "^0.13.9"
[build-system]
requires = ["poetry-core>=1.0.0"]
......
This diff is collapsed.
......@@ -3,10 +3,12 @@
import argparse
import logging
import os
import statistics
import sys
import typing
from pathlib import Path
from typing import Callable, NamedTuple, Optional, TypeVar, Union
from dataclasses import dataclass
import termcolor
from matplotlib import pyplot as plt
......@@ -74,44 +76,16 @@ class Statistics(NamedTuple):
@classmethod
def calc(cls, data: list[Union[int, float]]) -> "Statistics":
"""Calculate statistics for data."""
num_val = len(data)
sum_val = sum(data)
def avg(data: list[Union[int, float]]) -> float:
""":Return: The average."""
return sum_val / num_val
def med(data: list[Union[int, float]]) -> float:
""":Return: The median."""
data = sorted(data)
len_half = num_val / 2
if len_half.is_integer():
return data[int(len_half)]
else:
lower = len_half - 0.5
higher = len_half + 0.5
assert lower.is_integer() and higher.is_integer()
return avg([data[int(lower)], data[int(higher)]])
avg_val = avg(data)
med_val = med(data)
var_val = avg([(x - avg_val) ** 2 for x in data])
std_val = var_val ** 0.5
max_val = max(data)
min_val = min(data)
return cls(
avg=avg_val,
med=med_val,
var=var_val,
std=std_val,
sum=sum_val,
num=num_val,
max=max_val,
min=min_val,
avg=statistics.mean(data),
med=statistics.median(data),
var=statistics.variance(data),
std=statistics.stdev(data),
sum=sum(data),
num=len(data),
max=max(data),
min=min(data),
)
......@@ -268,6 +242,37 @@ def existing_file_path(value: str, allow_none=False) -> Optional[Path]:
return path
@dataclass
class TraceTriple:
left_pcap_path: Path
right_pcap_path: Path
keylog_path: Optional[Path] = None
@classmethod
def from_str(cls, value: str) -> "TraceTriple":
parts = value.split(":")
if len(parts) not in (2, 3):
raise argparse.ArgumentTypeError(
f"{value} is not a valid triple or tuple of paths separated by :"
)
path0 = Path(parts[0])
path1 = Path(parts[1])
path2 = Path(parts[2]) if len(parts) == 3 else None
for path in (path0, path1, path2):
if path:
if path.is_dir():
raise argparse.ArgumentTypeError(
f"{path} is a directory. A file is required."
)
elif not path.is_file():
raise argparse.ArgumentTypeError(f"{path} does not exist.")
return cls(left_pcap_path=path0, right_pcap_path=path1, keylog_path=path2)
class Subplot:
fig: plt.Figure
ax: plt.Axes
......
Supports Markdown
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