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.33.141', 9001), ('10.1.33.141',9001)]
    #ip_port = [('10.1.53.240', 9001), ('10.1.53.240',9011), ('10.1.53.240',9021)]
    passwd = 'sanlie;123'

    r= connect.connectNeon(ip_port, passwd, 10)
    r_read = r.getRedisRead()

    #path1='/GPPD/workspace/'+sys.argv[1]+'/value' 
    path2='/GPPD/workspace/detector/'+sys.argv[1]+'/value' 
    #x1=r_read.get(path1)
    x2=r_read.get(path2)
    #mon=jsonArray.jsonDecoder(x1)
    mod=jsonArray.jsonDecoder(x2)
    #print "dim of monitor: ",numpy.array(mon).shape
    #print mon
    #print "dim of module: ",numpy.array(mod).shape
    a=0
    #b=0
    for ix in mod:
        a+=sum(ix)
        #print " counts:",sum(ix)
    #for iy in mod:
    #    b+=sum(iy)
    #    print " counts:",sum(iy)
    #print "monitor total: ",a," module total: ", b
    print " module total: ", a
    #path="/GPPD/workspace/MantidData/module131/d"
    #x=r_read.get(path)
    #x=jsonArray.jsonDecoder(x)
    #print x
