mirror of
https://github.com/Horizontal42/netsleuth.git
synced 2026-11-10 19:12:03 +03:00
Merge f4b801c773 into 8c99ac78b7
This commit is contained in:
commit
d025ca24fd
1 changed files with 12 additions and 2 deletions
|
|
@ -183,16 +183,26 @@ async def tier_fastcom(client: httpx.AsyncClient, cfg: Speedtest, timeout: float
|
||||||
targets = response.json().get("targets") or []
|
targets = response.json().get("targets") or []
|
||||||
samples: list[tuple[int, float]] = []
|
samples: list[tuple[int, float]] = []
|
||||||
on_net: bool | None = None
|
on_net: bool | None = None
|
||||||
|
|
||||||
|
valid_targets = []
|
||||||
for target in targets:
|
for target in targets:
|
||||||
url = target.get("url")
|
url = target.get("url")
|
||||||
if not url:
|
if not url:
|
||||||
continue
|
continue
|
||||||
location = (target.get("location") or {}).get("country")
|
location = (target.get("location") or {}).get("country")
|
||||||
on_net = on_net or bool(location)
|
on_net = on_net or bool(location)
|
||||||
began = time.perf_counter()
|
valid_targets.append(url)
|
||||||
|
|
||||||
|
async def _fetch(url: str) -> int:
|
||||||
body = await client.get(url, timeout=timeout)
|
body = await client.get(url, timeout=timeout)
|
||||||
body.raise_for_status()
|
body.raise_for_status()
|
||||||
samples.append((len(body.content), time.perf_counter() - began))
|
return len(body.content)
|
||||||
|
|
||||||
|
if valid_targets:
|
||||||
|
began = time.perf_counter()
|
||||||
|
results = await asyncio.gather(*(_fetch(url) for url in valid_targets))
|
||||||
|
samples.append((sum(results), time.perf_counter() - began))
|
||||||
|
|
||||||
return SpeedResult(
|
return SpeedResult(
|
||||||
method="fastcom",
|
method="fastcom",
|
||||||
download_mbps=throughput_from_samples(samples),
|
download_mbps=throughput_from_samples(samples),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue