2024-05-25 17:55:05 -04:00
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
|
|
|
|
|
|
class Speedtest(BaseModel):
|
|
|
|
type: str
|
|
|
|
timestamp: datetime
|
|
|
|
ping: "Ping"
|
|
|
|
download: "Bandwidth"
|
|
|
|
upload: "Bandwidth"
|
|
|
|
isp: str
|
|
|
|
interface: "Interface"
|
|
|
|
server: "Server"
|
|
|
|
result: "Result"
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def from_json(cls, data: dict) -> "Speedtest":
|
|
|
|
return cls(
|
|
|
|
type=data["type"],
|
|
|
|
timestamp=datetime.fromisoformat(data["timestamp"]),
|
|
|
|
ping=Ping(**data["ping"]),
|
|
|
|
download=Bandwidth(**data["download"]),
|
|
|
|
upload=Bandwidth(**data["upload"]),
|
|
|
|
isp=data["isp"],
|
|
|
|
interface=Interface(**data["interface"]),
|
|
|
|
server=Server(**data["server"]),
|
|
|
|
result=Result(**data["result"])
|
|
|
|
)
|
|
|
|
|
|
|
|
class Bandwidth(BaseModel):
|
|
|
|
bandwidth: float
|
|
|
|
bytes: int
|
|
|
|
elapsed: int
|
|
|
|
latency: "Latency"
|
|
|
|
|
|
|
|
class Interface(BaseModel):
|
|
|
|
internalIp: str
|
|
|
|
name: str
|
|
|
|
macAddr: str
|
|
|
|
isVpn: bool
|
|
|
|
externalIp: str
|
|
|
|
|
|
|
|
class Ping(BaseModel):
|
|
|
|
jitter: float
|
|
|
|
latency: float
|
|
|
|
low: float
|
|
|
|
high: float
|
|
|
|
|
|
|
|
class Latency(BaseModel):
|
|
|
|
iqm: float
|
|
|
|
low: float
|
|
|
|
high: float
|
|
|
|
jitter: float
|
|
|
|
|
|
|
|
class Server(BaseModel):
|
2024-05-25 17:56:40 -04:00
|
|
|
id: int
|
2024-05-25 17:55:05 -04:00
|
|
|
name: str
|
|
|
|
location: str
|
|
|
|
country: str
|
|
|
|
host: str
|
|
|
|
port: int
|
|
|
|
ip: str
|
|
|
|
|
2024-05-25 17:58:22 -04:00
|
|
|
class Result(BaseModel):
|
2024-05-25 17:55:05 -04:00
|
|
|
id: str
|
|
|
|
url: str
|
|
|
|
persisted: bool
|
|
|
|
|
|
|
|
@property
|
2024-05-25 17:58:22 -04:00
|
|
|
def image(self) -> str:
|
2024-05-25 17:55:05 -04:00
|
|
|
return self.url + ".png"
|