In [2]:
import server
import importlib
importlib.reload(server)
from server import *



ImportErrorTraceback (most recent call last)
<ipython-input-2-a21ba1726b55> in <module>()
----> 1 import server
      2 import importlib
      3 importlib.reload(server)
      4 from server import *

ImportError: No module named 'server'

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]:
{'op': 'simsearch_ts', 'ts': '[[1, 2, 3], [2, 3, 4]]'}

In [ ]:


In [2]:
d = {0:'moon',1:'sun'}
json_d = json.dumps(d)
print(json_d)
s = serialize(json_d)


{"0": "moon", "1": "sun"}

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())


False
True
True
{'0': 'moon', '1': 'sun'}
True
b'\x1d\x00\x00\x00{"0": "moon", "1": "sun"}'
{'0': 'moon', '1': 'sun'}
False

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]:
({'id': 12, 'op': 'TSfromID'}, b' \x00\x00\x00{"op": "TSfromID", "id": 12}')

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.


{'op': 'TSfromID', 'id': 12}

In [6]:
status,response


Out[6]:
(<TSDBStatus.OK: 0>,
 {'op': None, 'payload': None, 'status': <TSDBStatus.OK: 0>})

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]:
({'op': None, 'payload': None, 'status': <TSDBStatus.OK: 0>},
 <TSDBStatus.OK: 0>)

In [9]:
isinstance(tsdbop, TSDBOp_SimSearch_TS),isinstance(tsdbop, TSDBOp_SimSearch_ID),isinstance(tsdbop, TSDBOp_TSfromID)


Out[9]:
(False, False, True)

In [10]:
type(tsdbop)


Out[10]:
server.TSDBOp_TSfromID

In [11]:
tsdbop


Out[11]:
{'id': 12, 'op': 'TSfromID'}

In [12]:
tsdbop['id']


Out[12]:
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())



NameErrorTraceback (most recent call last)
<ipython-input-13-da97ea3839d2> in <module>()
----> 1 self.deserializer.append(data)
      2 if self.deserializer.ready():
      3     msg = self.deserializer.deserialize()
      4     status = TSDBStatus.OK  # until proven otherwise.
      5     response = TSDBOp_Return(status, None)  # until proven otherwise.

NameError: name 'self' is not defined

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)



ConnectionRefusedErrorTraceback (most recent call last)
<ipython-input-14-2794851af8b8> in <module>()
     12 c = socket(AF_INET, SOCK_STREAM)
     13 #c.bind(('',25001))
---> 14 c.connect(('localhost', 25000))
     15 a = np.zeros(shape=50000000, dtype=float)
     16 print(a[0:10])

ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

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))


Overwriting echo_client_custom.py

In [15]:
from Similarity.find_most_similar import find_most_similiar

In [16]:
sys.path


Out[16]:
['D:\\Dropbox (HNL)\\coursework\\CS207\\project\\cs207project\\timeseries',
 'D:\\Dropbox (HNL)\\coursework\\CS207\\project\\cs207project',
 'D:\\Dropbox (HNL)\\coursework\\CS207\\project\\cs207project\\timeseries\\Similarity',
 'D:\\Dropbox (HNL)\\coursework\\CS207\\project\\cs207project\\timeseries',
 'D:\\Dropbox (HNL)\\coursework\\CS207\\project\\cs207project/cs207rbtree',
 'D:\\Dropbox (HNL)\\coursework\\CS207\\project\\cs207project\\timeseries\\Similarity',
 'D:\\Dropbox (HNL)\\coursework\\CS207\\project\\cs207project\\timeseries',
 'D:\\Dropbox (HNL)\\coursework\\CS207\\project\\cs207project/timeseries',
 'D:\\Dropbox (HNL)\\coursework\\CS207\\project\\cs207project',
 'D:\\Dropbox (HNL)\\coursework\\CS207\\project\\cs207project/timeseries',
 'D:\\Dropbox (HNL)\\coursework\\CS207\\project\\cs207project',
 '',
 'C:\\Users\\Andrew\\Anaconda2\\envs\\py35\\python35.zip',
 'C:\\Users\\Andrew\\Anaconda2\\envs\\py35\\DLLs',
 'C:\\Users\\Andrew\\Anaconda2\\envs\\py35\\lib',
 'C:\\Users\\Andrew\\Anaconda2\\envs\\py35',
 'C:\\Users\\Andrew\\Anaconda2\\envs\\py35\\lib\\site-packages',
 'C:\\Users\\Andrew\\Anaconda2\\envs\\py35\\lib\\site-packages\\Sphinx-1.4.1-py3.5.egg',
 'C:\\Users\\Andrew\\Anaconda2\\envs\\py35\\lib\\site-packages\\win32',
 'C:\\Users\\Andrew\\Anaconda2\\envs\\py35\\lib\\site-packages\\win32\\lib',
 'C:\\Users\\Andrew\\Anaconda2\\envs\\py35\\lib\\site-packages\\Pythonwin',
 'C:\\Users\\Andrew\\Anaconda2\\envs\\py35\\lib\\site-packages\\setuptools-23.0.0-py3.5.egg',
 'C:\\Users\\Andrew\\Anaconda2\\envs\\py35\\lib\\site-packages\\IPython\\extensions',
 'C:\\Users\\Andrew\\.ipython']

This is the client!!


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]:
b'X\x00\x00\x00{"ts": [[1, 2, 3], [-1, 3, -10]], "op": "storeTS", "courtesy": "please", "id": 1000}'

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)


b''

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)


{'ts': [[1.0, 2.0, 3.0], [-1.0, 3.0, -10.0]], 'op': 'TSfromID', 'id': 'TSfromID'}
[[1.0, 2.0, 3.0], [-1.0, 3.0, -10.0]]

In [26]:
print(a)


[[0.0, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2, 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3, 0.31, 0.32, 0.33, 0.34, 0.35000000000000003, 0.36, 0.37, 0.38, 0.39, 0.4, 0.41000000000000003, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47000000000000003, 0.48, 0.49, 0.5, 0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.5700000000000001, 0.58, 0.59, 0.6, 0.61, 0.62, 0.63, 0.64, 0.65, 0.66, 0.67, 0.68, 0.6900000000000001, 0.7000000000000001, 0.71, 0.72, 0.73, 0.74, 0.75, 0.76, 0.77, 0.78, 0.79, 0.8, 0.81, 0.8200000000000001, 0.8300000000000001, 0.84, 0.85, 0.86, 0.87, 0.88, 0.89, 0.9, 0.91, 0.92, 0.93, 0.9400000000000001, 0.9500000000000001, 0.96, 0.97, 0.98, 0.99], [1127.1131566751444, 235.53611960156977, -1409.6098565742689, 839.473370073991, 646.9677781558846, 25.062594224841835, -1266.1953274834784, 70.3890653764745, -323.7545094066559, -1045.2512604362594, 1527.1985473950917, -442.8039199772306, -310.9786558083676, 147.9336817871847, -322.69162598123444, -913.9816807375735, 784.9755648952946, 189.77069031279137, -133.95744243155005, -1259.3634805168463, 377.89266314670135, 743.3900151543947, 904.9303606212005, -1329.7712337756827, -917.4557534772443, 397.4720141501753, -414.36907127334325, -75.17091570183925, 130.67353168430225, 1079.40764233454, -182.83126331642416, -209.06669072479698, 1768.9390108876644, 283.86067653547417, -79.20023947265287, -326.8651017157752, -1811.520060678046, 1341.9366079838403, -876.0822788446994, 420.6543089986855, 125.85986064922989, -147.52655573143576, -686.0716025876123, 210.53484911787257, 1010.1655499199687, 746.8813034079874, -961.4034513915976, 94.16565343116791, 281.91490747598556, -598.9547946802209, -2026.7606852125352, 195.03786297232628, -774.3609799821896, 44.61770837726509, -219.58119270988715, -293.90132367325407, 368.35003804130173, -3161.591253833328, 452.72178811373414, -1813.501225335874, 141.65635781883387, -113.09280707570224, -377.4943887604286, -7.573291263267661, 1390.5927074545727, -794.1376750219523, 753.3069418032869, -739.7432079892726, 1551.5193661044152, 2302.467406377997, -415.63387038750534, -427.5350507344195, 148.72357106522304, -184.24261499584264, 161.4195327766866, 615.0435918495264, -613.8729811020719, -180.44165325252428, -733.8030222792847, -683.8482150851615, 1229.6980857836031, -1389.939584945777, -187.12410600762303, 75.78985676158278, 431.11168780198096, -530.2294556632507, 938.5942119020069, -909.7628332856483, 686.9091504286832, -1121.3814879641766, 696.8793303526429, 290.54792380774114, 800.0589412011678, 882.2042104004615, -635.6053360978294, 1079.4368871182671, 1869.8061901555623, -182.83860516917318, -157.3664626363793, 877.26594995064]]

In [35]:
a = b = 0

In [37]:



Out[37]:
True

In [28]:
response['ts']


Out[28]:
'[[0.0, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2, 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3, 0.31, 0.32, 0.33, 0.34, 0.35000000000000003, 0.36, 0.37, 0.38, 0.39, 0.4, 0.41000000000000003, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47000000000000003, 0.48, 0.49, 0.5, 0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.5700000000000001, 0.58, 0.59, 0.6, 0.61, 0.62, 0.63, 0.64, 0.65, 0.66, 0.67, 0.68, 0.6900000000000001, 0.7000000000000001, 0.71, 0.72, 0.73, 0.74, 0.75, 0.76, 0.77, 0.78, 0.79, 0.8, 0.81, 0.8200000000000001, 0.8300000000000001, 0.84, 0.85, 0.86, 0.87, 0.88, 0.89, 0.9, 0.91, 0.92, 0.93, 0.9400000000000001, 0.9500000000000001, 0.96, 0.97, 0.98, 0.99], [784.047869922633, -1174.9231708464652, -1966.3103681137839, 980.3240258839023, -2005.128793082871, -1718.5167723862435, -1005.7897775823137, 253.83697308070728, -516.9164428747807, -691.8627732917718, -1018.0514446949568, 1207.117057401863, -217.2850431344638, 166.42734615438022, -1005.9346911951684, 1129.5206285149002, 864.7039496143278, 916.5792553876568, 149.76178280164416, -1434.784874814774, -1462.6511282348463, -42.96385252980836, -1832.6524452680328, -966.8274583460005, 63.571229873074095, 22.257484205567142, -1355.9855428758178, 1620.628956221186, -2246.61436984552, 1248.8039001656537, 1276.4617309956027, -263.95277252281136, -380.5008597990493, 223.7502333000687, -2305.4717926764915, 1067.9226395643727, -1497.115445536819, 699.1487675992436, -19.59993914211486, 645.6477268929578, 1866.5892303348244, 721.2608398144066, 174.93570002449007, 768.1326492064247, -2591.96781528898, -1042.6920539912753, 1548.6642163369233, 384.4477254102571, -227.1452801911582, 1150.5533485239778, 554.176223201529, 1332.8195312047856, 431.988057337248, -394.57010715755297, 220.47730433822466, -1541.7371151786365, 149.86900103964203, 1334.8554947187752, -995.3154657252343, -1480.969665323349, 71.87904479271711, 72.31957581398083, -907.8971782847793, -231.58701023714545, 1614.9601910186873, -830.9622218378348, -394.1369866549737, 937.7444329139763, -707.7062294345999, 132.14713375549402, -720.707519125737, -957.7010951418883, -477.3916499427225, -1087.9408780257106, -619.9524776744939, 443.25755952750666, 1069.9157032260036, -246.27291686810904, 460.8055987355616, -100.46430195889127, 10.439997180768854, 842.8879079302458, 258.2900679524329, 989.3759691926422, 119.48571087971942, 1267.2240588282523, 1417.133448135833, 1332.3841758647413, -962.993291558631, 1603.8035684135184, 678.443144189365, 582.5705819463498, -1230.8554700606396, 652.0167653230992, 954.0896249991256, 781.3292058672001, 1244.7657538042718, 570.9256354213856, 218.75640392117978, 161.78403951821448]]'

Above is the output I'm getting- still need to discuss interpolation and also adding in the parameter for number of timeseries to find


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)


{'b': 17, 'a': 12}

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]:
{'id': 12, 'op': 'TSfromID'}

In [ ]:


In [ ]:


In [72]:
ds = Deserializer()
ds.append(msg)
ds.deserialize()


Invalid JSON object received:
success!

In [69]:
msg


Out[69]:
b'\x0c\x00\x00\x00success!'

In [65]:
json.dumps('success!')


Out[65]:
'"success!"'

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]:
['D:\\Dropbox (HNL)\\coursework\\CS207\\project\\cs207project\\timeseries',
 'D:\\Dropbox (HNL)\\coursework\\CS207\\project\\cs207project/cs207rbtree',
 'D:\\Dropbox (HNL)\\coursework\\CS207\\project\\cs207project\\timeseries\\Similarity',
 'D:\\Dropbox (HNL)\\coursework\\CS207\\project\\cs207project\\timeseries',
 'D:\\Dropbox (HNL)\\coursework\\CS207\\project\\cs207project/cs207rbtree',
 'D:\\Dropbox (HNL)\\coursework\\CS207\\project\\cs207project\\timeseries\\Similarity',
 'D:\\Dropbox (HNL)\\coursework\\CS207\\project\\cs207project\\timeseries',
 'D:\\Dropbox (HNL)\\coursework\\CS207\\project\\cs207project/timeseries',
 'D:\\Dropbox (HNL)\\coursework\\CS207\\project\\cs207project',
 'D:\\Dropbox (HNL)\\coursework\\CS207\\project\\cs207project/timeseries',
 'D:\\Dropbox (HNL)\\coursework\\CS207\\project\\cs207project',
 '',
 'C:\\Users\\Andrew\\Anaconda2\\envs\\py35\\python35.zip',
 'C:\\Users\\Andrew\\Anaconda2\\envs\\py35\\DLLs',
 'C:\\Users\\Andrew\\Anaconda2\\envs\\py35\\lib',
 'C:\\Users\\Andrew\\Anaconda2\\envs\\py35',
 'C:\\Users\\Andrew\\Anaconda2\\envs\\py35\\lib\\site-packages',
 'C:\\Users\\Andrew\\Anaconda2\\envs\\py35\\lib\\site-packages\\Sphinx-1.4.1-py3.5.egg',
 'C:\\Users\\Andrew\\Anaconda2\\envs\\py35\\lib\\site-packages\\win32',
 'C:\\Users\\Andrew\\Anaconda2\\envs\\py35\\lib\\site-packages\\win32\\lib',
 'C:\\Users\\Andrew\\Anaconda2\\envs\\py35\\lib\\site-packages\\Pythonwin',
 'C:\\Users\\Andrew\\Anaconda2\\envs\\py35\\lib\\site-packages\\setuptools-23.0.0-py3.5.egg',
 'C:\\Users\\Andrew\\Anaconda2\\envs\\py35\\lib\\site-packages\\IPython\\extensions',
 'C:\\Users\\Andrew\\.ipython']

In [28]:
os.getcwd()


Out[28]:
'D:\\Dropbox (HNL)\\coursework\\CS207\\project\\cs207project\\TimeseriesDB'

In [29]:
os.path.dirname(os.path.abspath(__file__))



NameErrorTraceback (most recent call last)
<ipython-input-29-0e75f935e925> in <module>()
----> 1 os.path.dirname(os.path.abspath(__file__))

NameError: name '__file__' is not defined

In [121]:
from StorageManager import FileStorageManager

In [ ]:
sm = File