2019-08-23 23:27:45 +08:00
|
|
|
from visdom import Visdom
|
|
|
|
import random
|
|
|
|
import numpy as np
|
2019-09-17 23:20:24 +08:00
|
|
|
import os
|
|
|
|
import time
|
2019-08-23 23:27:45 +08:00
|
|
|
|
|
|
|
|
|
|
|
def InitVisdom():
|
2019-09-17 23:20:24 +08:00
|
|
|
# nohub python3 -m visdom.server > visdom.server.log 2 > &1
|
|
|
|
# subprocess.Popen("python3 -m visdom.server > visdom.server.log 2>&1", shell=True)
|
|
|
|
|
|
|
|
os.popen("python3 -m visdom.server > visdom.server.log 2>&1")
|
|
|
|
time.sleep(3) # to wait vindom.server started
|
|
|
|
# viz = Visdom()
|
|
|
|
# assert viz.check_connection()
|
|
|
|
# viz.close()
|
|
|
|
print("Connect http://localhost:8097")
|
|
|
|
|
2019-08-23 23:27:45 +08:00
|
|
|
|
2019-11-28 21:06:06 +08:00
|
|
|
class Line(object):
|
2019-09-17 23:20:24 +08:00
|
|
|
def __init__(self, windows, name, size):
|
2019-08-23 23:27:45 +08:00
|
|
|
super(Line, self).__init__()
|
2019-09-17 23:20:24 +08:00
|
|
|
self.name = name
|
|
|
|
self.size = size
|
|
|
|
self.win = windows
|
|
|
|
|
|
|
|
def __init__(self, windows):
|
2019-08-23 23:27:45 +08:00
|
|
|
super(Line, self).__init__()
|
2019-09-17 23:20:24 +08:00
|
|
|
self.name = str(random.random())
|
|
|
|
self.size = 0
|
|
|
|
self.win = windows
|
|
|
|
|
|
|
|
def __init__(self, windows, name):
|
2019-08-23 23:27:45 +08:00
|
|
|
super(Line, self).__init__()
|
2019-09-17 23:20:24 +08:00
|
|
|
self.name = name
|
|
|
|
self.size = 0
|
|
|
|
self.win = windows
|
|
|
|
|
2019-09-23 10:02:01 +08:00
|
|
|
def AppendData(self, y, x=None):
|
|
|
|
self.win.AppendData(self, y, x)
|
2019-09-20 12:48:45 +08:00
|
|
|
|
|
|
|
|
2019-11-28 21:06:06 +08:00
|
|
|
class LineWin(object):
|
2019-08-23 23:27:45 +08:00
|
|
|
def __init__(self):
|
|
|
|
super(LineWin, self).__init__()
|
|
|
|
self.viz = Visdom()
|
|
|
|
self.name = str(random.random())
|
|
|
|
self.win = self.viz.line(
|
|
|
|
X=np.array([0]),
|
|
|
|
Y=np.array([0]),
|
|
|
|
name=self.name
|
|
|
|
)
|
|
|
|
self.data = np.array([])
|
2019-09-17 23:20:24 +08:00
|
|
|
|
|
|
|
def AppendLine(self, y):
|
|
|
|
if not isinstance(y, list):
|
2019-08-23 23:27:45 +08:00
|
|
|
y = [y]
|
|
|
|
linename = str(random.random())
|
|
|
|
self.viz.line(
|
|
|
|
X=np.array(range(len(y))),
|
|
|
|
Y=np.array(y),
|
|
|
|
opts=dict(markercolor=np.array([50]),
|
2019-09-17 23:20:24 +08:00
|
|
|
markersymbol='dot',),
|
2019-08-23 23:27:45 +08:00
|
|
|
win=self.win,
|
|
|
|
update="new",
|
|
|
|
name=linename,
|
|
|
|
)
|
2019-09-17 23:20:24 +08:00
|
|
|
return Line(linename, len(y))
|
2019-08-23 23:27:45 +08:00
|
|
|
|
2019-09-23 10:02:01 +08:00
|
|
|
def AppendData(self, line, y, x=None):
|
|
|
|
y = [y]
|
|
|
|
Y = np.array(y).reshape((-1))
|
|
|
|
X = []
|
|
|
|
if x:
|
2019-09-20 12:48:45 +08:00
|
|
|
x = [x]
|
2019-09-23 10:02:01 +08:00
|
|
|
X = np.array(X).reshape((-1))
|
|
|
|
else:
|
|
|
|
X = np.array(range(line.size, line.size+len(Y)))
|
|
|
|
|
2019-09-20 12:48:45 +08:00
|
|
|
self.viz.line(
|
|
|
|
Y=Y,
|
|
|
|
X=X,
|
|
|
|
win=self.win,
|
|
|
|
update="append",
|
|
|
|
name=line.name
|
|
|
|
)
|
|
|
|
line.size = line.size + len(y)
|