Skip to content

Instantly share code, notes, and snippets.

@metalefty
Last active July 2, 2020 01:52
Show Gist options
  • Select an option

  • Save metalefty/3100922a4a55cb5ebe45472596eb210c to your computer and use it in GitHub Desktop.

Select an option

Save metalefty/3100922a4a55cb5ebe45472596eb210c to your computer and use it in GitHub Desktop.
speedtest-cliで蓄積した速度測定データをいい感じに表示するやつ
#!/usr/bin/env python3
import csv
import sys
import numpy as np
from matplotlib import pyplot
from datetime import datetime, timezone
from dateutil.parser import parse
from matplotlib import dates as mdates
data = []
with open(sys.argv[1], 'r') as f:
reader = csv.reader(f)
for row in reader:
if len(row) == 8:
row[0] = int(row[0])
row[3] = parse(row[3]).astimezone()
row[4] = float(row[4])
row[5] = float(row[5])
row[6] = int(float(row[6]))
row[7] = int(float(row[7]))
data.append(row)
download = np.array([])
upload = np.array([])
ping = np.array([])
date = []
for d in data:
date.append(d[3])
ping = np.append(ping, d[5])
download = np.append(download, d[6])
upload = np.append(upload, d[7])
# bps to Mbps
download = download / 1000000
upload = upload / 1000000
# plot
pyplot.rcParams['timezone'] = "Asia/Tokyo" # これシステムタイムゾーンにしたい
fig = pyplot.figure()
pyplot.ylabel("Throughput [Mbps]")
pyplot.xticks(rotation=90)
# download / upload
axis1 = fig.add_subplot(111)
axis1.xaxis.set_major_formatter(mdates.DateFormatter("%m-%d %H:%M"))
axis1.xaxis.set_major_locator(mdates.HourLocator(interval=3))
axis1.xaxis.set_minor_locator(mdates.HourLocator(interval=1))
line1, = axis1.plot(date, download, color="green", label="download")
line2, = axis1.plot(date, upload, color="red", label="upload")
# RTT
axis2 = axis1.twinx()
line3, = axis2.plot(date, ping, color="gray", label="RTT")
axis2.set_ylabel("Round Trip Time [ms]")
axis2.set_ylim([0, 150])
# combine legend
pyplot.legend((line1, line2, line3), ('download', 'upload', 'RTT'))
# title
axis1.set_title("speedtest result [%s]" % data[0][2])
pyplot.tight_layout()
pyplot.plot()
pyplot.show()
@metalefty

Copy link
Copy Markdown
Author

スクリーンショット

93-14277-ocn-speed 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment