Last active
July 2, 2020 01:52
-
-
Save metalefty/3100922a4a55cb5ebe45472596eb210c to your computer and use it in GitHub Desktop.
speedtest-cliで蓄積した速度測定データをいい感じに表示するやつ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
スクリーンショット