In [2]:
import server
import importlib
importlib.reload(server)
from server import *
In [95]:
a = TSDBOp_SimSearch_TS('TSfromID')
a['ts'] = [np.array((1,2,3)),np.array((2,3,4))]
In [94]:
a.to_json()
Out[94]:
In [ ]:
In [2]:
d = {0:'moon',1:'sun'}
json_d = json.dumps(d)
print(json_d)
s = serialize(json_d)
In [3]:
ds = Deserializer()
print(ds.ready())
ds.append(s)
print(ds.ready())
ds.append(s)
print(ds.ready())
print(ds.deserialize())
print(ds.ready())
print(ds.buf)
print(ds.deserialize())
print(ds.ready())
In [ ]:
In [4]:
#d2 = {'op':'simsearch_ts','ts':[list(range(10)),list(range(10))]}
#d2 = {'op':'simsearch_id','id':12}
d2 = {'op':'TSfromID','id':12}
#d2 = {'op':'other','id':12}
s2 = serialize(json.dumps(d2))
d2,s2
#TSDBOp('with_ts')
Out[4]:
In [5]:
deserializer = Deserializer()
deserializer.append(s2)
deserializer.ready()
msg = deserializer.deserialize()
print(msg)
status = TSDBStatus.OK # until proven otherwise.
response = TSDBOp_Return(status, None) # until proven otherwise.
In [6]:
status,response
Out[6]:
In [7]:
try:
tsdbop = TSDBOp.from_json(msg)
except TypeError as e:
status = TSDBStatus.INVALID_OPERATION
response = TSDBOp_Return(TSDBStatus.INVALID_OPERATION, None)
print('error here')
else:
tsdbop
In [8]:
response,status
Out[8]:
In [9]:
isinstance(tsdbop, TSDBOp_SimSearch_TS),isinstance(tsdbop, TSDBOp_SimSearch_ID),isinstance(tsdbop, TSDBOp_TSfromID)
Out[9]:
In [10]:
type(tsdbop)
Out[10]:
In [11]:
tsdbop
Out[11]:
In [12]:
tsdbop['id']
Out[12]:
In [13]:
self.deserializer.append(data)
if self.deserializer.ready():
msg = self.deserializer.deserialize()
status = TSDBStatus.OK # until proven otherwise.
response = TSDBOp_Return(status, None) # until proven otherwise.
try:
tsdbop = TSDBOp.from_json(msg)
except TypeError as e:
response = TSDBOp_Return(TSDBStatus.INVALID_OPERATION, None)
if status is TSDBStatus.OK:
if isinstance(tsdbop, TSDBOp_withTS):
response = self._with_ts(tsdbop)
elif isinstance(tsdbop, TSDBOp_withID):
response = self._with_id(tsdbop)
else:
response = TSDBOp_Return(TSDBStatus.UNKNOWN_ERROR, tsdbop['op'])
serialize(response.to_json())
In [ ]:
In [ ]:
In [ ]:
In [14]:
import numpy as np
from socket import *
def recv_into(arr, source):
view = memoryview(arr).cast('B')
while len(view):
nrecv = source.recv_into(view)
print("recieved", nrecv)
view = view[nrecv:]
c = socket(AF_INET, SOCK_STREAM)
#c.bind(('',25001))
c.connect(('localhost', 25000))
a = np.zeros(shape=50000000, dtype=float)
print(a[0:10])
recv_into(a, c)
print(a[0:10])
print(c)
In [ ]:
from socket import *
import numpy as np
def send_from(arr, dest):
view = memoryview(arr).cast('B')
while len(view):
nsent = dest.send(view)
view = view[nsent:]
s = socket(AF_INET, SOCK_STREAM)
s.bind(('', 25000))
s.listen(1)
c,addr = s.accept()
print(c)
print(addr)
print(s)
a = np.arange(0.0, 50000000.0)
send_from(a, c)
In [5]:
%%file echo_client_custom.py
import sys
from socket import socket, AF_INET, SOCK_STREAM
s = socket(AF_INET, SOCK_STREAM)
s.connect(('localhost', 20000))
s.send(sys.argv[1].encode())
print(s.recv(8192))
In [15]:
from Similarity.find_most_similar import find_most_similiar
In [16]:
sys.path
Out[16]:
In [50]:
import MessageFormatting
import importlib
importlib.reload(MessageFormatting)
from MessageFormatting import *
In [51]:
from timeseries.ArrayTimeSeries import ArrayTimeSeries as ts
import numpy as np
from scipy.stats import norm
t = np.arange(0.0, 1.0, 0.01)
v = norm.pdf(t, 100, 100) + 1000*np.random.randn(100)
ts_test = ts(t, v)
d2 = {'op':'storeTS','id':1000,'ts':[[1,2,3], [-1,3,-10]],'courtesy':'please'}
#d2 = {'op':'TSfromID','id':1000,'courtesy':'please'}
#d2 = {'op':'simsearch_id','id':12,'n_closest':2,'courtesy':'please'}
#d2 = {'op':'simsearch_ts','ts':[list(ts_test.times()), list(ts_test.values())],'courtesy':'please'}
s2 = serialize(json.dumps(d2))
In [52]:
s2
Out[52]:
In [53]:
import sys
from socket import socket, AF_INET, SOCK_STREAM
s = socket(AF_INET, SOCK_STREAM)
s.connect(('localhost', 20000))
s.send(s2)
msg = s.recv(8192)
print(msg)
In [46]:
ds = Deserializer()
ds.append(msg)
ds.ready()
response = ds.deserialize()
#print(response)
if 'ts' in response:
a = response['ts']
elif 'id' in response:
a = response['id']
print(response)
print(a)
In [26]:
print(a)
In [35]:
a = b = 0
In [37]:
Out[37]:
In [28]:
response['ts']
Out[28]:
In [239]:
def dic_fun(**kwargs):
a = {}
for k,v in kwargs.items():
a[k]=v
print(a)
In [240]:
dic_fun(a=12,b=17)
In [3]:
import MessageFormatting
import importlib
importlib.reload(MessageFormatting)
from MessageFormatting import *
In [265]:
d2 = {'op':'simsearch_ts','ts':[[1,2,3],[4,5,6]],'courtesy':'please'}
d2 = {'op':'simsearch_id','id':12,'courtesy':'please','n_closest':12}
d2 = {'op':'TSfromID','id':12,'courtesy':'please'}
c = TSDBOp.from_json(d2)
c
Out[265]:
In [ ]:
In [ ]:
In [72]:
ds = Deserializer()
ds.append(msg)
ds.deserialize()
In [69]:
msg
Out[69]:
In [65]:
json.dumps('success!')
Out[65]:
In [73]:
#json.loads(TSDBOp.to_json('success!'))
In [4]:
from Similarity.find_most_similar import find_most_similiar
In [5]:
sys.path
Out[5]:
In [28]:
os.getcwd()
Out[28]:
In [29]:
os.path.dirname(os.path.abspath(__file__))
In [121]:
from StorageManager import FileStorageManager
In [ ]:
sm = File