import jsonArray
import time
import json
#from redis.sentinel import Sentinel
import connect
import sys
import numpy
if __name__ == '__main__':
    # ======Try to connect NEON server
  
    #sentinel=Sentinel([('10.1.53.240', 9001),('10.1.53.240', 9011),('10.1.53.240', 9021)], socket_timeout=0.1)
    #sentinel=Sentinel([('10.1.33.141', 9001),('10.1.33.141', 9011),('10.1.33.141', 9021)], socket_timeout=0.1)
    #r=sentinel.master_for('neonmaster', socket_timeout=20, password='sanlie;123')
    ip_port =  [('10.1.34.116', 9001), ('10.1.34.116',9001)]
    #ip_port =  [('10.1.53.240', 9001), ('10.1.53.240',9001)]
    passwd = 'sanlie;123'
    r= connect.connectNeon(ip_port, passwd, 10)
    r_read = r.getRedisRead()

    #name=sys.argv[1]
    path='/SANS/workspace/MantidData/detector/tof' 
    path2='/SANS/workspace/MantidData/detector/counts' 
    #path="/SANS/workspace/MantidData/trans/wavelength"
    #path2="/SANS/workspace/MantidData/trans/transmission"
    #path='/SANS/workspace/MantidData/raw/q' 
    #path2='/SANS/workspace/MantidData/raw/intensity' 
    path='/SANS/workspace/MantidData/xy_image/x' 
    path1='/SANS/workspace/MantidData/xy_image/y' 
    path2='/SANS/workspace/MantidData/xy_image/value' 
    #path='/SANS/workspace/MantidData/monitor1/xy_image/x' 
    #path1='/SANS/workspace/MantidData/monitor1/xy_image/y' 
    #path2='/SANS/workspace/MantidData/monitor1/xy_image/value' 
    #path='/SANS/workspace/MantidData/monitor2/wavelength' 
    #path2='/SANS/workspace/MantidData/monitor2/intensity' 
    #path='/SANS/workspace/MantidData/tube58/xy_image/x' 
    #path1='/SANS/workspace/MantidData/tube1/xy_image/y' 
    path2='/SANS/workspace/MantidData/tube63/xy_image/value' 
    #path='/SANS/workspace/MantidData/IQxy/x 
    #path1='/SANS/workspace/MantidData/IQxy/y' 
    #path2='/SANS/workspace/MantidData/IQxy/counts' 
    #x=r_read.get(path)
    #x1=r_read.get(path1)
    y=r_read.get(path2)
    y=jsonArray.jsonDecoder(y)
    for ix in y[0]:
	print ix
    print sum(y[0])
    #printonArray.jsonDecoderx
    #print len(jsonArray.jsonDecoder(x))
    #print (jsonArray.jsonDecoder(x1))
    #value=jsonArray.jsonDecoder(y)
    #for ix in value:
    #	print ix

    #print (jsonArray.jsonDecoder(x1))
    #print sum(jsonArray.jsonDecoder(y))
    #print numpy.array(x).shape, numpy.array(y).shape
    #print numpy.array(x1).shape

