Skip to content

Commit

Permalink
Jitter
Browse files Browse the repository at this point in the history
  • Loading branch information
Ketok4321 committed Sep 3, 2023
1 parent 8b3bdb5 commit 5bdbb46
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 25 deletions.
8 changes: 6 additions & 2 deletions src/speedtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,15 @@ async def check_server(server):
async def ping(server): #TODO: jitter and other stuff
async with aiohttp.ClientSession() as session:
pings = []
for _ in range(10):
jitters = []
for i in range(10):
start = time.time()
async with session.get(server.pingURL, headers=HEADERS) as _:
pings.append(time.time() - start)
return sum(pings) / len(pings) * 1000

if i != 0:
jitters.append(abs(pings[i] - pings[i - 1]))
return sum(pings) / len(pings) * 1000, sum(jitters) / len(jitters) * 1000

async def download(server, total):
async with aiohttp.ClientSession() as session:
Expand Down
6 changes: 3 additions & 3 deletions src/speedtest_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ async def do_run(self):
try:
view = self.win.test_view

_ping = await ping(self.server)
_ping, jitter = await ping(self.server)

GLib.idle_add(setattr, view, "ping", str(round(_ping)) + "ms")
GLib.idle_add(view.update_ping, _ping, jitter)

GLib.idle_add(view.progress.remove_css_class, "up")
GLib.idle_add(view.progress.add_css_class, "dl")
Expand Down Expand Up @@ -76,7 +76,7 @@ def update(self, gauge, part_two):
value = self.total[0] / current_duration

if current_duration > 1:
view.updateGauge(gauge, value)
view.update_gauge(gauge, value)
view.progress.set_fraction(current_duration / DURATION * 0.5 + (0.5 if part_two else 0.0))

return not self.stop_event.is_set()
Expand Down
1 change: 0 additions & 1 deletion src/ui/gauge.blp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ template $Gauge : Box {
orientation: vertical;
valign: end;
halign: center;
margin-bottom: 16;

Label {
valign: center;
Expand Down
59 changes: 41 additions & 18 deletions src/ui/views/test.blp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,56 @@ template $TestView : Box {
styles [ "osd" ]
}

[overlay]
Box {
orientation: vertical;
spacing: 16;
halign: center;
valign: end;
margin-bottom: 16;

Box {
orientation: vertical;

Label {
label: "Ping:";
styles [ "title-2" ]
}

Label {
label: bind template.ping;
styles [ "title-3" ]
}
}

Box {
orientation: vertical;

Label {
label: "Jitter:";
styles [ "title-2" ]
}

Label {
label: bind template.jitter;
styles [ "title-3" ]
}
}
}

Box {
orientation: vertical;

Label title {
label: bind template.server;
margin-top: 8;
styles [ "title-3" ]
}

Box {
orientation: horizontal;
spacing: 64;
margin-bottom: 16;

$Gauge download {
label: "Download:";
Expand All @@ -28,23 +68,6 @@ template $TestView : Box {
styles [ "dl" ]
}

Box {
orientation: vertical;
valign: end;
width-request: 80;
margin-bottom: 16;

Label {
label: "Ping:";
styles [ "title-2" ]
}

Label {
label: bind template.ping;
styles [ "title-3" ]
}
}

$Gauge upload {
label: "Upload:";
vexpand: true;
Expand Down
8 changes: 7 additions & 1 deletion src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,19 @@ class TestView(Gtk.Box):
download = Gtk.Template.Child()
upload = Gtk.Template.Child()
ping = GObject.Property(type=str, default="...")
jitter = GObject.Property(type=str, default="...")
server = GObject.Property(type=str)

progress = Gtk.Template.Child()

def __init__(self, **kwargs):
super().__init__(**kwargs)

def update_ping(self, ping, jitter):
self.ping = str(round(ping)) + "ms"
self.jitter = str(round(jitter)) + "ms"

def updateGauge(self, object, speed):
def update_gauge(self, object, speed):
speedMb = round(speed / 125_000, 1)
object.value = str(speedMb) + "Mbps"
object.fill = min(speedMb / 100, 1.0)
Expand All @@ -56,6 +61,7 @@ def reset(self):
obj.value = "..."
obj.fill = 0.0
self.ping = "..."
self.jitter = "..."
self.progress.set_fraction(0.0)

@Gtk.Template(resource_path="/xyz/ketok/Speedtest/ui/views/offline.ui")
Expand Down

0 comments on commit 5bdbb46

Please sign in to comment.