import redis
import jsonArray
import time
import numpy as np
from numpy import *
import random
from redis.sentinel import Sentinel

if __name__ == '__main__':
    # ======Try to connect NEON server
    #ip="10.1.33.141"
    sentinel=Sentinel([('10.1.53.240', 9001),('10.1.53.240', 9011),('10.1.53.240', 9021)], socket_timeout=0.1)
    r=sentinel.master_for('neonmaster', socket_timeout=20, password='sanlie;123')
    moduleList=['module1', 'module2', 'module3',  'module4', 'module5', 'module6', 'module7', 'module8', 'module9', 'module10']
 
    '''
    path="/SANS/workspace/detector/"
    npid=1500
    ntof=2501
    mtof=[]
    for i in range(ntof):
        mtof.append(i*16)
    v=[[] for k in range(npid)]
    for i in range(npid):
        for j in range(ntof-1):
            v[i].append(random.randint(0,100))
    v1=jsonArray.jsonEncoder(v)
    '''
    #set monitor
    num=0
    npid=1024
    ntof=2501
    mpid=[]
    for i in range(npid):
        mpid.append(i+1)
    mtof=[]
    for i in range(ntof):
        mtof.append(i*16)
    r.set("/SANS/workspace/monitor1/pid",jsonArray.jsonEncoder(mpid))
    r.set("/SANS/workspace/monitor1/tof",jsonArray.jsonEncoder(mtof))
    v=[[] for k in range(npid)]
    for i in range(npid):
        for j in range(ntof-1):
            v[i].append(random.randint(0,100))
    r.set("/SANS/workspace/monitor1/value",jsonArray.jsonEncoder(v))
    
    r.set("/SANS/workspace/monitor2/tof",jsonArray.jsonEncoder(mtof))
    r.set("/SANS/workspace/monitor3/tof",jsonArray.jsonEncoder(mtof))
    npid=1
    v=[[] for k in range(npid)]
    for i in range(npid):
        for j in range(ntof-1):
            v[i].append(random.randint(0,100))
    r.set("/SANS/workspace/monitor2/value",jsonArray.jsonEncoder(v))
    r.set("/SANS/workspace/monitor3/value",jsonArray.jsonEncoder(v))
    
    print "finish set test data!"


