From 359b4b43c7bed75f160e38dff3514674d91cca8b Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Wed, 17 Jul 2019 09:53:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E9=AB=98Net=E7=B2=BE=E5=BA=A6?= =?UTF-8?q?=EF=BC=88=E8=99=BD=E7=84=B6=E6=B2=A1=E5=95=A5=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Common.py | 17 +++++++++-------- static/device.js | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Common.py b/Common.py index e40fcb1..9aa94e3 100644 --- a/Common.py +++ b/Common.py @@ -16,7 +16,7 @@ bypy = ByPy() doCleanTime = datetime.now() _clean_flag = None -network = { +network = [{ "currentTime": datetime.now(), "out": { "currentByte": psutil.net_io_counters().bytes_sent, @@ -24,12 +24,12 @@ network = { "in": { "currentByte": psutil.net_io_counters().bytes_recv, } -} +}] def updateNetwork(): global network - network = { + network.append({ "currentTime": datetime.now(), "out": { "currentByte": psutil.net_io_counters().bytes_sent, @@ -37,7 +37,8 @@ def updateNetwork(): "in": { "currentByte": psutil.net_io_counters().bytes_recv, } - } + }) + network = network[-2:] def getTimeDelta(a, b): @@ -83,11 +84,11 @@ def getCurrentStatus(): _disk = psutil.disk_usage(".") _mem = psutil.virtual_memory() _net = psutil.net_io_counters() - _delta= getTimeDelta(datetime.now(),network["currentTime"]) + _delta= getTimeDelta(datetime.now(),network[0]["currentTime"]) if 60 > _delta > 0: - _delta = getTimeDelta(datetime.now(), network["currentTime"]) - _inSpeed = (_net.bytes_recv - network["in"]["currentByte"]) / _delta - _outSpeed = (_net.bytes_sent - network["out"]["currentByte"]) / _delta + _delta = getTimeDelta(network[-1]["currentTime"], network[0]["currentTime"]) + _inSpeed = (network[-1]["in"]["currentByte"] - network[0]["in"]["currentByte"]) / _delta + _outSpeed = (network[-1]["out"]["currentByte"] - network[0]["out"]["currentByte"]) / _delta else: _outSpeed = 0 _inSpeed = 0 diff --git a/static/device.js b/static/device.js index 2d311b8..12ece79 100644 --- a/static/device.js +++ b/static/device.js @@ -23,4 +23,4 @@ function deviceUpdate(){ } deviceUpdate() -setInterval(deviceUpdate,4000) +setInterval(deviceUpdate,2000)