import jsonArray
import time
import json
#from redis.sentinel import Sentinel
import connect
import sys
import matplotlib.pyplot as plt

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.53.240', 9001), ('10.1.53.240',9001)]
    #ip_port =  [('10.1.34.116', 9001), ('10.1.34.116',9001)]
    passwd = 'sanlie;123'
    r= connect.connectNeon(ip_port, passwd, 10)
    r_read = r.getRedisRead()
    name=sys.argv[1]
    path="/SANS/workspace/MantidData/"+name+"/d"
    path2="/SANS/workspace/MantidData/"+name+"/intensity"
    #path="/SANS/workspace/MantidData/"+name+"/tof"
    #path2="/SANS/workspace/MantidData/"+name+"/counts"
    json_x=r_read.get(path)
    json_y=r_read.get(path2)

    x=jsonArray.jsonDecoder(json_x)
    y=jsonArray.jsonDecoder(json_y)
    print len(x),len(y)
    plt.plot(x,y)
    plt.show()
 
