From 50304b604834b8962fc4ab7bdf4f8f28106ee3bd Mon Sep 17 00:00:00 2001 From: vrubel Date: Tue, 13 Oct 2026 09:58:42 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B2=D1=8F=D0=B7=D0=BA=D0=B8=20=D0=BA?= =?UTF-8?q?=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=20=E2=86=92=20=D1=81=D0=B5=D1=80?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D1=8B=20=D0=B2=20=D0=BA=D0=BE=D0=BD=D1=84?= =?UTF-8?q?=D0=B8=D0=B3=D0=B5,=20=D0=B8=D1=82=D0=BE=D0=B3=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D1=8F=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8=D1=86=D0=B0=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - у клиента можно указать servers = [...] — с какими серверами его проверять - итоговая таблица сгруппирована по клиентам: сервер, отдача, приём - iperf3 на клиенте запускается через timeout и с --connect-timeout Co-Authored-By: Claude Opus 5.5 --- vipref.py | 50 +++++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/vipref.py b/vipref.py index f921392..3490ff3 100755 --- a/vipref.py +++ b/vipref.py @@ -231,27 +231,40 @@ def schedule(clients: list[Host], servers: list[Host], concurrent: bool) -> list return rounds -def fmt_table(results: list[Result], clients: list[Host], servers: list[Host], direction: str) -> str: - by_pair = {(r.client, r.server): r for r in results if r.direction == direction} - header = ["клиент \\ сервер", *[s.name for s in servers]] - rows = [] +def fmt_table(results: list[Result], clients: list[Host], servers: list[Host], directions: list[str]) -> str: + """Таблица, сгруппированная по клиентам: для каждого — его серверы с отдачей и приёмом.""" + by_key = {(r.client, r.server, r.direction): r for r in results} + + def cell(r: Result | None) -> str: + if r is None: + return "—" + return "ОШИБКА" if r.mbps is None else f"{r.mbps:,.1f}".replace(",", " ") + + titles = {"upload": "отдача ↑", "download": "приём ↓"} + header = ["клиент", "сервер", *[titles[d] for d in directions]] + groups = [] for c in clients: - row = [c.name] - for srv in servers: - r = by_pair.get((c.name, srv.name)) - row.append("—" if r is None else ("ОШИБКА" if r.mbps is None else f"{r.mbps:,.1f}".replace(",", " "))) - rows.append(row) - widths = [max(len(x[i]) for x in [header, *rows]) for i in range(len(header))] + tested = [srv for srv in servers if any((c.name, srv.name, d) in by_key for d in directions)] + if tested: + groups.append([[c.name if i == 0 else "", srv.name, *[cell(by_key.get((c.name, srv.name, d))) for d in directions]] + for i, srv in enumerate(tested)]) + if not groups: + return "Нет результатов." + widths = [max(len(x[i]) for x in [header, *[row for g in groups for row in g]]) for i in range(len(header))] def line(cells): return "│ " + " │ ".join( - cell.ljust(w) if i == 0 else cell.rjust(w) for i, (cell, w) in enumerate(zip(cells, widths)) + cell.ljust(w) if i < 2 else cell.rjust(w) for i, (cell, w) in enumerate(zip(cells, widths)) ) + " │" sep = lambda l, m, r: l + m.join("─" * (w + 2) for w in widths) + r - title = ("Отдача: клиент → сервер" if direction == "upload" else "Загрузка: сервер → клиент") + ", Мбит/с" - return "\n".join([title, sep("┌", "┬", "┐"), line(header), sep("├", "┼", "┤"), - *[line(r) for r in rows], sep("└", "┴", "┘")]) + out = ["Скорость, Мбит/с (отдача — клиент → сервер, приём — сервер → клиент)", + sep("┌", "┬", "┐"), line(header)] + for g in groups: + out.append(sep("├", "┼", "┤")) + out.extend(line(row) for row in g) + out.append(sep("└", "┴", "┘")) + return "\n".join(out) def save(results: list[Result], path: Path) -> None: @@ -320,8 +333,8 @@ def main() -> None: done = 0 log(f"Тестов: {total}, по {s.duration}с (+{s.omit}с прогрев) каждый") try: - for direction in directions: - for rnd in rounds: + for rnd in rounds: + for direction in directions: with ThreadPoolExecutor(max_workers=len(rnd)) as pool: futures = [pool.submit(run_test, c, srv, direction, s) for c, srv in rnd] for fut in futures: @@ -340,9 +353,8 @@ def main() -> None: stop_server(h, s) print() - for direction in directions: - print(fmt_table(results, clients, servers, direction)) - print() + print(fmt_table(results, clients, servers, directions)) + print() if failed := [r for r in results if r.error]: print("Ошибки:") for r in failed: