def __init__ (self, ws_client, serial_client, robot_id, server_ip):
        self.ws_client = ws_client
        self.serial_client = serial_client
        self.robot_id = robot_id
        self.server_ip = server_ip
        self.count = 0
        self.goTime = False
        self.last = 0        

        print 'Creating input array...'
        self.sensorData = np.zeros((100,15), dtype = 'f') 
        self.index = 0

        print 'Opening classifier...'
        f = open('presenceClassifier0.15.0b2.pkl', 'r') 

        print 'Training...'
        self.isInterested = Predictor(f)
class HandlerForDataFromSerialModelX():
    def __init__ (self, ws_client, serial_client, robot_id, server_ip):
        self.ws_client = ws_client
        self.serial_client = serial_client
        self.robot_id = robot_id
        self.server_ip = server_ip
        self.count = 0
        self.goTime = False
        self.last = 0        

        print 'Creating input array...'
        self.sensorData = np.zeros((100,15), dtype = 'f') 
        self.index = 0

        print 'Opening classifier...'
        f = open('presenceClassifier0.15.0b2.pkl', 'r') 

        print 'Training...'
        self.isInterested = Predictor(f)

       

    # cfs[1] = BUMPS WHEEL DROPS STATE - bumpleft(1), bumpright(2), wheelcaster(14), wheelleft(15), wheelright(16)
    # cfs[2] = WALL SIGNAL STATE - wallir(13)
    # cfs[3] = CLIFF LEFT SIGNAL STATE - lccliffir(5) or lcliffir(6)
    # cfs[4] = CLIFF FRONT LEFT SIGNAL STATE - lccliffir(5) or lcliffir(6)
    # cfs[5] = CLIFF FRONT RIGHT SIGNAL STATE - rccliffir(8) or rcliffir(9)
    # cfs[6] = CLIFF RIGHT SIGNAL STATE - rccliffir(8) or rcliffir(9)
    #
    # ana[1] = piezoret - photo(7)
    # ana[2] = thermret - rearir1(10)
    # ana[3] = lightret - rearer2(11)
    # ana[4] = ultra range - NA
    #
    # itc[1] = irtherm1 - irtherm1(3)
    # itc[2] = irtherm2 - irtherm2(4)

    # ******************************************************

    # sensorData[0] = bumpleft    - #cfs[1] bit 1
    #           [1] = bumpright   - #cfs[1] bit 0
    #           [2] = irtherm1    - #itc[1]
    #           [3] = irtherm2    - #itc[2]
    #           [4] = lccliffir   - #cfs[4]
    #           [5] = lcliffir    - #cfs[3]
    #           [6] = photo       - #ana[1]
    #           [7] = rccliffir   - #cfs[5]
    #           [8] = rcliffir    - #cfs[6]
    #           [9] = rearir1     - #ana[2]
    #          [10] = rearir2     - #ana[3]
    #          [11] = wallir      - #cfs[2] 
    #          [12] = wheelcaster - #cfs[1] bit 4
    #          [13] = wheelleft   - #cfs[1] bit 3
    #          [14] = wheelright  - #cfs[1] bit 2

    def process(self, message):
        if RobotInfo.model_x:
            print 'Streaming...'
            messArray = message.split()
            if '#cfs' in messArray and self.count == 0:            
                self.sensorData[self.index][0]  = (0 if (int(messArray[1])/2)%2 == 0 else 1)  # separate out from bumpstate
                self.sensorData[self.index][1]  = (0 if (int(messArray[1])/1)%2 == 0 else 1)  # ditto
                self.sensorData[self.index][4]  = int(messArray[4])  
                self.sensorData[self.index][5]  = int(messArray[3])
                self.sensorData[self.index][7]  = int(messArray[5]) 
                self.sensorData[self.index][8]  = int(messArray[6])  
                self.sensorData[self.index][11] = int(messArray[2])
                self.sensorData[self.index][12] = (0 if (int(messArray[1])/16)%2 == 0 else 1) # separate
                self.sensorData[self.index][13] = (0 if (int(messArray[1])/8)%2 == 0 else 1) # separate
                self.sensorData[self.index][14] = (0 if (int(messArray[1])/4)%2 == 0 else 1) # separate
            elif '#itc' in messArray and self.count == 1:
                self.sensorData[self.index][2] = float(messArray[1])
                self.sensorData[self.index][3] = float(messArray[2])
            elif '#ana' in messArray and self.count == 2:
                #self.circleArray[0][self.index] = time.time()
                self.sensorData[self.index][6] = int(messArray[1])
                self.sensorData[self.index][9] = int(messArray[2])
                self.sensorData[self.index][10] = int(messArray[3])

            if ('#cfs' in messArray) or ('#ana' in messArray) or ('#itc' in messArray):
                #print messArray
                #print("count = ", self.count, ", index = ", self.index)
                #print self.sensorData[self.index]
                #print self.sensorData
                self.count += 1
            if self.count > 2:
                if self.goTime == True and (time.time() - self.last > 3):
                    print('****************************************')
                    print(self.isInterested.predict(self.sensorData))
                    print('****************************************')
                    self.last = time.time()
                    np.savetxt('sensorData.txt',self.sensorData,fmt='%.1f')
                self.count = 0
                self.index += 1
            if self.index > 99:
                self.index = 0
                self.goTime = True