In [1]:
import json
import datetime
In [2]:
import pandas
In [3]:
%matplotlib inline
from matplotlib import pyplot as plt
import matplotlib.ticker as mtick
In [4]:
data = [json.loads(s) for s in open("cfjs2017_2017-09-23.json").read().split("\n") if s]
data += [json.loads(s) for s in open("cfjs2017_2017-09-24.json").read().split("\n") if s]
In [5]:
def path_get(obj, *args):
if obj and args:
return path_get(obj.get(args[0]), *args[1:])
if obj or isinstance(obj, (int, float)):
return obj
return None
In [6]:
ifaces = ["wwan0"] + ["wlan%d" % s for s in range(8)]
cols = '''ipkts
ierrs
opkts
oerrs
colls
in_octets
out_octets
in_drops
out_discards
in_unknown_protos'''.split()
absolutes = []
counters = []
for n in range(1,11):
dev = "dev%02d" % n
absolutes += [(dev, "dialup_device", "signal_quality")]
for iface in ifaces:
for field in cols:
counters += [(dev, "interface", iface, field)]
for d in range(1, 14):
absolutes += [(dev, "wlan_ap_scan_force", str(d))]
for hz in ("2g", "5g"):
for ssid in "cfjs2017 cfjs2017_5g cfjs_lan".split():
absolutes += [(dev, "wlan_client_count", hz, ssid)]
In [7]:
amat = [[path_get(row, *p) for p in absolutes] for row in data]
cmat = [[path_get(row, *p) for p in counters] for row in data]
In [8]:
lcol = len(cols)
ldev = len(cols)*9
wlan_io = [k+ldev*i+lcol*j for i in range(10) for j in range(1,9) for k in (5,6)]
[counters[i] for i in wlan_io]
Out[8]:
異常値を除去。
In [9]:
#mat[176][724] = None
#mat[176][726] = None
#mat[176][678] = None
for i in range(len(counters)):
cmat[120][i] = None
cmat[124][i] = None
cmat[177][i] = None
cmat[287][i] = None
cmat[329][i] = None
cmat[387][i] = None
cmat[409][i] = None
cmat[463][i] = None
for i in range(550,609):
cmat[176][i] = None
for i in range(540,609):
cmat[238][i] = None
for i in range(540,609):
cmat[239][i] = None
for i in range(540,609):
cmat[240][i] = None
for i in range(90, 789):
cmat[462][i] = None
for i in range(90,339):
cmat[488][i] = None
In [10]:
a = pandas.DataFrame(amat)
c = pandas.DataFrame(cmat)
In [11]:
tm = [datetime.datetime.strptime(row["@timestamp"], "%Y-%m-%dT%H:%M:%S.%f") for row in data]
t = pandas.Series(tm)
In [12]:
plt.figure(figsize=(15,8))
plt.gca().yaxis.set_major_formatter(mtick.FormatStrFormatter('%.0f'))
x=plt.plot(t,c)
In [13]:
c2=c.fillna(method="ffill").fillna(0).diff()
In [14]:
for i in range(c2.shape[0]):
for j in range(c2.shape[1]):
if c2.iloc[i,j] < 0:
print(i,j,c2.iloc[i,j])
In [15]:
c2[c2<0] = 0
In [16]:
plt.figure(figsize=(15,8))
plt.gca().yaxis.set_major_formatter(mtick.FormatStrFormatter('%.0f'))
x=plt.plot(t, c2.iloc[:,wlan_io].cumsum())
In [17]:
plt.figure(figsize=(15,8))
plt.gca().yaxis.set_major_formatter(mtick.FormatStrFormatter('%.0f'))
x=plt.plot(t, c2.iloc[:,wlan_io]/300*8)
In [18]:
plt.figure(figsize=(15,8))
plt.gca().yaxis.set_major_formatter(mtick.FormatStrFormatter('%.0f'))
c3 = pandas.DataFrame([c2.iloc[:,wlan_io[16*i:16*(i+1)]].sum(axis=1).cumsum() for i in range(10)])
x = plt.plot(tm, c3.T)
In [19]:
plt.figure(figsize=(15,8))
plt.gca().yaxis.set_major_formatter(mtick.FormatStrFormatter('%.0f'))
c3 = pandas.DataFrame([c2.iloc[:,wlan_io[16*i:16*(i+1)]].sum(axis=1)/300*8 for i in range(10)])
x = plt.plot(tm, c3.T)
In [20]:
plt.figure(figsize=(15,8))
plt.gca().yaxis.set_major_formatter(mtick.FormatStrFormatter('%.0f'))
c4 = pandas.concat([c2.iloc[:,wlan_io[0:160:2]].sum(axis=1), c2.iloc[:,wlan_io[1:160:2]].sum(axis=1)], axis=1)
x=plt.plot(tm, c4.cumsum())
In [21]:
plt.figure(figsize=(15,8))
plt.gca().yaxis.set_major_formatter(mtick.FormatStrFormatter('%.0f'))
c4 = pandas.concat([c2.iloc[:,wlan_io[0:160:2]].sum(axis=1), c2.iloc[:,wlan_io[1:160:2]].sum(axis=1)], axis=1)
x=plt.plot(tm, c4/300*8)
In [22]:
plt.figure(figsize=(15,8))
plt.gca().yaxis.set_major_formatter(mtick.FormatStrFormatter('%.0f'))
x=plt.plot(t, c2.iloc[:,wlan_io].cumsum().sum(axis=1))
In [23]:
"{:,}".format(list(c2.iloc[:,wlan_io].cumsum().sum(axis=1))[-1])
Out[23]:
これに別途数えていない部分で 4.5 G 使用していたので、合計 83 G 程度使ったようだ。やはり 2 日目のほうがおとなしい。
In [24]:
plt.figure(figsize=(15,8))
plt.gca().yaxis.set_major_formatter(mtick.FormatStrFormatter('%.0f'))
x=plt.plot(t, c2.iloc[:,wlan_io].cumsum().sum(axis=1).diff()/300*8)
ピークで 40Mbps 以上出てるので、ADSL だとダメだったかもね。
In [ ]: