Beispiel #1
0
    def post(self):
        jdatas = json.loads(self.request.body)
        for jdata in jdatas:

            device_mac = jdata['mac']
            data_content = jdata['data_content']
            #insert the new data to redis
            r = redis.Redis()
            r.set("col_datas_%s" % (device_mac), data_content)
            #get the last table in redis and if there is not a record in redis and get the newest record in the table map
            index = r.get("last_data_table_index")
            if not index:
                index = Data_Table_Map.get_last_table_index()
            print "last index:", index
            dtm = Data_Table_Map.find_first("where `index`=?", int(index))
            #print "add last index table!:----------",dtm.index
            if dtm == None:
                Data_Table_Map.add_table(index)

            #parse the data
            #insert into the table
            #if the line of table more than 20w records then create a new table and update table map in the database
            date = data_content['date']
            content = data_content['content']
            dev = Device()
            dev = dev.get_device_by_mac(device_mac)
            DataParser.get_instance().parse_dev(index, dev.id, dev.dev_type,
                                                content)
        self.write('ok')
Beispiel #2
0
    def img_upload(self, device_mac, device_pos, created_at, meta):
        if device_mac == "":
            return False

        if device_pos == "":
            return False
        dev = Device()
        pos = Position_Image()
        #print "upload_img",device_mac,device_pos

        device_id = dev.get_device_by_mac(device_mac)
        position_id = pos.get_position_id(device_id, device_pos)
        print "upload", device_id, position_id
        upload_path = os.path.join(get_pwd_dir(), CAPTURED_DIR)
        filename = meta['filename']
        filename = os.path.basename(filename)
        print filename, '----', upload_path

        filepath = os.path.join(upload_path, filename)
        with open(filepath, 'wb') as up:
            up.write(meta['body'])

        img = Image()
        img.path = filename
        img.position_id = position_id
        img.created_at = created_at
        img_id = img.create()
        r = redis.Redis()
        r.set('image_path_%s_%s' % (device_mac, device_pos), img.path)
        print img_id
        if not img_id:
            return False
        return True
def img_upload(device_mac, device_pos,created_at, meta):
    if device_mac == "":
        return False

    if device_pos == "":
        return False
    dev = Device()
    pos = Position()
    #print "upload_img",device_mac,device_pos

    device_id = dev.get_device_by_mac(device_mac)
    position_id = pos.get_position_id(device_id, device_pos)
    print "upload",device_id,position_id
    upload_path = os.path.join(getPWDDir(), CAPTURED_DIR)
    filename = meta['filename']
    filename = os.path.basename(filename)
    print filename,'----',upload_path

    filepath = os.path.join(upload_path, filename)
    with open(filepath, 'wb') as up:
        up.write(meta['body'])

    img = Image()
    img.path = filename
    img.position_id = position_id
    img.created_at = created_at
    img_id = img.create()
    print img_id
    if not img_id:
        return False
    return True
Beispiel #4
0
    def post(self):
        jdatas = json.loads(self.request.body)
        for jdata in jdatas:

            device_mac = jdata['mac']
            data_content = jdata['data_content']
            #insert the new data to redis
            r=redis.Redis()
            r.set("col_datas_%s"%(device_mac), data_content)
            #get the last table in redis and if there is not a record in redis and get the newest record in the table map
            index = r.get("last_data_table_index")
            if not index:
                index = Data_Table_Map.get_last_table_index()
            print "last index:", index
            dtm = Data_Table_Map.find_first("where `index`=?", int(index))
            #print "add last index table!:----------",dtm.index
            if dtm == None:
                Data_Table_Map.add_table(index)
            
            #parse the data
            #insert into the table
            #if the line of table more than 20w records then create a new table and update table map in the database
            date = data_content['date']
            content = data_content['content']
            dev = Device()
            dev = dev.get_device_by_mac(device_mac)
            DataParser.get_instance().parse_dev(index, dev.id, dev.dev_type,  content)
        self.write('ok')
    def post(self):
        jdatas = json.loads(self.request.body)
        #device_mac = self.get_argument('mac', '')
        device_mac = jdatas['mac']

        dev = Device()
        device_id = dev.get_device_by_mac(device_mac)
        #position_infos = self.get_argument('positions', [])
        position_infos = jdatas['positions']

        for pos_info in position_infos:
            position = pos_info['position']
            object_name = pos_info['object_name']
            duration = pos_info['duration']
            pos = Position()
            pos.device_id = device_id
            pos.position = position
            pos.object_name = object_name
            pos.duration = duration
            pos_id = pos.create()
            print pos_id
            if not pos_id:
                self.write('fail')
                return
        self.write('ok')
    def post(self):
        jdatas = json.loads(self.request.body)
        device_mac = jdatas['mac']
        #device_mac = self.get_argument('mac','')
        dev = Device()
        self.device_id = dev.get_device_by_mac(device_mac)
        if self.device_id == None:
            self.write("fail")
            return

        #self.observed = self.get_argument('observed',False)
        #user_name = self.get_argument('user_name','')
        #user_password = self.get_argument('user_password','')

        self.observed = jdatas['observed']
        print "observed", self.observed
        user_name = jdatas['user_name']
        user_password = jdatas['user_password']

        res = task.user_login(user_name, user_password)
        if self.on_login_success(res):
            self.write("ok")
            return

        self.write('fail')
 def post(self):
     jdatas = json.loads(self.request.body)
     #device_mac = self.get_argument('mac', '')
     #device_location = self.get_argument('location', '')
     device_mac = jdatas['mac']
     device_location = jdatas['location']
     print device_mac,'location:',device_location
     dev = Device()
     dev.mac=get_md5(device_mac)
     dev.location=device_location
     if None == dev.get_device_by_mac(device_mac):
         device_id = dev.create()
     else:
         device_id = dev.update_info()
     print device_id
     if not device_id:
         self.write('fail')
         return
     self.write('ok')