Exemple #1
0
    def get(self):
        usr = self.get_current_user()
        device_observed = Device_Observed()
        devices = device_observed.observed_devices(usr.id)
        if not devices or len(devices) < 1:
            return self.render('no_devices.html',
                               user_name=usr.name,
                               page_name="browser")

        sel_device_id = self.get_argument('sel_device_id', '')
        sel_device = Device.get(sel_device_id)
        if sel_device_id == '':
            sel_device = devices[0]

        owners = DataParser.get_instance().get_owners(sel_device.dev_type)
        sel_owner = self.get_argument('owner', '')
        if sel_owner == '':
            sel_owner = owners[0]

        data_infos = DataParser.get_instance().get_data_types(
            sel_device.dev_type, sel_owner)
        if data_infos and len(data_infos) > 1:
            sel_data_info = data_infos[0]
        else:
            sel_data_info = None
        return self.render('history.html',
                           page_name='history',
                           devices=devices,
                           sel_device=sel_device,
                           sel_owner=sel_owner,
                           owners=owners,
                           data_infos=data_infos,
                           sel_data=sel_data_info,
                           user_name=usr.name)
Exemple #2
0
    def get(self,*args, **kwargs):
        usr = self.get_current_user()
        device_observed = Device_Observed()
        devices = device_observed.observed_devices(usr.id)
        if not devices or len(devices) < 1:
            return self.render('no_devices.html', user_name=usr.name, page_name="browser")
        sel_device_id = self.get_argument('sel_device_id','')

        if sel_device_id == "":
            dev = devices[0]
        else:
            dev =Device.get(sel_device_id)
        owners = DataParser.get_instance().get_owners(dev.dev_type)
        sel_owner = self.get_argument('owner','')
        if sel_owner == "":
            sel_owner = owners[0]

        datas_infos = DataParser.get_instance().get_data_types(dev.dev_type, sel_owner)






        #print sel_owner, owners
        return self.render('preview.html',
                page_name='preview',
                devices = devices,
                sel_dev=dev,
                sel_owner=sel_owner,
                owners = owners,
                datas_infos = datas_infos,
                user_name=usr.name,
                )
Exemple #3
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')
Exemple #4
0
    def get(self):
        usr = self.get_current_user()
        device_observed = Device_Observed()
        devices = device_observed.observed_devices(usr.id)
        if not devices or len(devices) < 1:
            return self.render('no_devices.html', user_name=usr.name, page_name="browser")

        sel_device_id = self.get_argument('sel_device_id','')
        sel_device = Device.get(sel_device_id)
        if sel_device_id == '':
            sel_device = devices[0]

        owners = DataParser.get_instance().get_owners(sel_device.dev_type)
        sel_owner = self.get_argument('owner','')
        if sel_owner == '':
            sel_owner = owners[0]


        data_infos = DataParser.get_instance().get_data_types(sel_device.dev_type, sel_owner)
        if data_infos and len(data_infos)>1:
            sel_data_info = data_infos[0]
        else:
            sel_data_info = None
        return self.render('history.html',
                           page_name = 'history',
                           devices = devices,
                           sel_device = sel_device,
                           sel_owner = sel_owner,
                           owners = owners,
                           data_infos =data_infos,
                           sel_data = sel_data_info,
                           user_name=usr.name)
Exemple #5
0
    def get(self, *args, **kwargs):
        usr = self.get_current_user()
        device_observed = Device_Observed()
        devices = device_observed.observed_devices(usr.id)
        if not devices or len(devices) < 1:
            return self.render('no_devices.html',
                               user_name=usr.name,
                               page_name="browser")
        sel_device_id = self.get_argument('sel_device_id', '')

        if sel_device_id == "":
            dev = devices[0]
        else:
            dev = Device.get(sel_device_id)
        owners = DataParser.get_instance().get_owners(dev.dev_type)
        sel_owner = self.get_argument('owner', '')
        if sel_owner == "":
            sel_owner = owners[0]

        datas_infos = DataParser.get_instance().get_data_types(
            dev.dev_type, sel_owner)

        #print sel_owner, owners
        return self.render(
            'preview.html',
            page_name='preview',
            devices=devices,
            sel_dev=dev,
            sel_owner=sel_owner,
            owners=owners,
            datas_infos=datas_infos,
            user_name=usr.name,
        )
Exemple #6
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')
Exemple #7
0
    def get(self,*args, **kwargs):
        usr = self.get_current_user()
        device_observed = Device_Observed()
        devices = device_observed.observed_devices(usr.id)
        position = Position_Data()
        if not devices or len(devices) < 1:
            return self.render('no_devices.html', user_name=usr.name, page_name="browser")
        positions = []
        sel_device_id = self.get_argument('sel_device_id','')
        if sel_device_id == "":
            dev = devices[0]
        else:
            dev =Device.get(sel_device_id)

        datas_infos = DataParser.get_instance().get_data_types(dev.dev_type)



        return self.render('preview.html',
                page_name='preview',
                devices = devices,
                sel_dev=dev,
                datas_infos = datas_infos,
                user_name=usr.name,
                )
Exemple #8
0
    def get(self):
        dev_id = self.get_argument('dev_id', '')
        type_id = self.get_argument('type_id', '')
        owner = self.get_argument('owner', '')
        start_time = self.get_argument('start_time') + ':00'
        start_time = time.mktime(time.strptime(start_time,
                                               '%Y-%m-%d %H:%M:%S'))
        end_time = self.get_argument('end_time') + ':00'
        end_time = time.mktime(time.strptime(end_time, '%Y-%m-%d %H:%M:%S'))
        tables = Data_Table_Map.get_tables(start_time, end_time)

        if type_id != "":
            res = self.get_data_info(tables, type_id, dev_id, owner,
                                     start_time, end_time)
            self.write(json.dumps(res))
        else:
            dev = Device.get(dev_id)
            datas_info = DataParser.get_instance().get_data_types(
                dev.dev_type, owner)
            #print "tables:---------",len(tables),start_time, end_time, tables
            reses = []
            for di in datas_info:
                #print di['type_id']
                reses.append(
                    self.get_data_info(tables, di['type_id'], dev_id,
                                       di['owner'], start_time, end_time))
            self.write(json.dumps(reses))
Exemple #9
0
 def get_data_info(self, tables, type_id, dev_id, owner, start_time,
                   end_time):
     data_list = []
     for table in tables:
         data_list.extend(
             Data.find_by(
                 'where device_id = ? and type_id = ? and owner= ? and created_at between ? and ?',
                 dev_id,
                 type_id,
                 owner,
                 start_time,
                 end_time,
                 sub_name=str(table.index)))
     res = {}
     dev = Device.get(dev_id)
     data_info = DataParser.get_instance().get_data_type(
         dev.dev_type, type_id, owner)
     res['name'] = data_info['name']
     res['type_id'] = data_info['type_id']
     res['unit'] = data_info['unit']
     res['values'] = []
     for data_item in data_list:
         res['values'].append(
             [data_item.created_at * 1000, data_item.value])
     return res
Exemple #10
0
 def post(self):
     dev_id = self.get_argument('dev_id','')
     dev = Device.get(dev_id)
     if dev:
         dev_type = dev.dev_type
         res = DataParser.get_instance().get_owners(dev_type)
         res = json.dumps(res)
         self.write(res)
Exemple #11
0
 def post(self):
     dev_id = self.get_argument('dev_id', '')
     dev = Device.get(dev_id)
     if dev:
         dev_type = dev.dev_type
         res = DataParser.get_instance().get_owners(dev_type)
         res = json.dumps(res)
         self.write(res)
Exemple #12
0
 def get(self, *args, **kwargs):
     sel_device_id = self.get_argument('sel_device_id','')
     dev = Device.get(sel_device_id)
     if dev:
         r  = redis.Redis()
         data_content = r.get("col_datas_%s" %(dev.mac))
         data_content = eval(data_content)
         res = DataParser.get_instance().parse_to_json(dev.dev_type, data_content['content'], data_content['date']*1000, dev.id)
         res = json.dumps(res)
         self.write(res)
         return self.finish()
Exemple #13
0
    def get_data_info(self, tables, type_id, dev_id, start_time, end_time):
        data_list = []
        for table in tables:
            data_list.extend(Data.find_by('where device_id = ? and type_id = ? and created_at between ? and ?', dev_id, type_id, start_time, end_time, sub_name = str(table.index)))

        dev  = Device.get(dev_id)
        data_info = DataParser.get_instance().get_data_type(dev.dev_type, type_id)

        if data_info['duration'] == 0:
            return self.deal_for_single(data_list, data_info)

        if data_info['duration'] > 0:
            return self.deal_for_accumulate(data_list, data_info)
Exemple #14
0
    def get(self, *args, **kwargs):
        sel_device_id = self.get_argument('sel_device_id','')
        dev = Device.get(sel_device_id)
        if dev:
            r  = redis.Redis()
            data_content = r.get("col_datas_%s" %(dev.mac))

            data_content = eval(data_content)
            res = DataParser.get_instance().parse_to_json(dev.dev_type, data_content['content'], data_content['date']*1000)
            #print "res:",res
            res = json.dumps(res)
            self.write(res)
            return self.finish()
Exemple #15
0
    def post(self):
        usr = self.get_current_user()
        device_observed = Device_Observed()
        devices = device_observed.observed_devices(usr.id)
        if not devices or len(devices) < 1:
            return self.render('no_devices.html', user_name=usr.name, page_name="browser")

        sel_device_id = self.get_argument('sel_device_id','')
        sel_device = Device.get(sel_device_id)
        if sel_device_id == '':
            sel_device = devices[0]

        data_infos = DataParser.get_instance().get_data_types(sel_device.dev_type)
        return self.write(json.dumps(data_infos))
Exemple #16
0
 def get_data_summary_info(self, user):
     dev_observed = Device_Observed()
     devices = dev_observed.observed_devices(user.id)
     r  = redis.Redis()
     reses = []
     for dev in devices:
         data_content = r.get("col_datas_%s" %(dev.mac))
         data_content = eval(data_content)
         print "data_content:",type(data_content)
         if data_content:
             res = DataParser.get_instance().parse_to_json(dev.dev_type, data_content['content'], data_content['date'])
             res['location'] = dev.location
             reses.append(res)
     return reses
Exemple #17
0
 def get_data_info(self, tables, type_id, dev_id, owner, start_time, end_time):
     data_list = []
     for table in tables:
         data_list.extend(Data.find_by('where device_id = ? and type_id = ? and owner= ? and created_at between ? and ?', dev_id, type_id, owner, start_time, end_time, sub_name = str(table.index)))
     res = {}
     dev  = Device.get(dev_id)
     data_info = DataParser.get_instance().get_data_type(dev.dev_type, type_id, owner)
     res['name'] = data_info['name']
     res['type_id'] = data_info['type_id']
     res['unit'] = data_info['unit']
     res['values'] = []
     for data_item in data_list:
         res['values'].append([data_item.created_at*1000, data_item.value])
     return res
Exemple #18
0
 def get_data_summary_info(self, user):
     dev_observed = Device_Observed()
     devices = dev_observed.observed_devices(user.id)
     r  = redis.Redis()
     reses = []
     for dev in devices:
         data_content = r.get("col_datas_%s" %(dev.mac))
         if data_content:
             data_content = eval(data_content)
             print "data_content:",type(data_content)
             res = DataParser.get_instance().parse_to_json(dev.dev_type, data_content['content'], data_content['date'])
             rd = {"location":dev.location, 'content':res}
             #res['location'] = dev.location
             reses.append(rd)
     return reses
Exemple #19
0
    def post(self):
        usr = self.get_current_user()
        device_observed = Device_Observed()
        devices = device_observed.observed_devices(usr.id)
        if not devices or len(devices) < 1:
            return self.render('no_devices.html',
                               user_name=usr.name,
                               page_name="browser")

        sel_device_id = self.get_argument('sel_device_id', '')
        sel_device = Device.get(sel_device_id)
        if sel_device_id == '':
            sel_device = devices[0]

        data_infos = DataParser.get_instance().get_data_types(
            sel_device.dev_type)
        return self.write(json.dumps(data_infos))
Exemple #20
0
    def get(self):
        dev_id = self.get_argument('dev_id','')
        type_id = self.get_argument('type_id','')
        start_time=self.get_argument('start_time')+':00'
        start_time = time.mktime(time.strptime(start_time, '%Y-%m-%d %H:%M:%S'))
        end_time=self.get_argument('end_time')+':00'
        end_time = time.mktime(time.strptime(end_time, '%Y-%m-%d %H:%M:%S'))
        tables = Data_Table_Map.get_tables(start_time, end_time)

        if type_id != "":
            res = self.get_data_info(tables, type_id, dev_id, start_time, end_time)
            self.write(json.dumps(res))
        else:
            dev = Device.get(dev_id)
            datas_info = DataParser.get_instance().get_data_types(dev.dev_type)
            #print "tables:---------",datas_info
            reses = []
            for di in datas_info:
                #print di['type_id']
                reses.append(self.get_data_info(tables, di['type_id'], dev_id, start_time, end_time))
            self.write(json.dumps(reses))
Exemple #21
0
    def get_data_info(self, tables, type_id, dev_id, start_time, end_time):
        data_list = []
        for table in tables:
            data_list.extend(
                Data.find_by(
                    'where device_id = ? and type_id = ? and created_at between ? and ?',
                    dev_id,
                    type_id,
                    start_time,
                    end_time,
                    sub_name=str(table.index)))

        dev = Device.get(dev_id)
        data_info = DataParser.get_instance().get_data_type(
            dev.dev_type, type_id)

        if data_info['duration'] == 0:
            return self.deal_for_single(data_list, data_info)

        if data_info['duration'] > 0:
            return self.deal_for_accumulate(data_list, data_info)
Exemple #22
0
 def get(self):
     self.write(json.dumps(DataParser.get_instance().get_chart_info()))
     self.finish()
Exemple #23
0
 def get(self, *args, **kwargs):
     proj_type = self.get_argument('proj_type','')
     self.write(DataParser.get_instance().get_chart_info(proj_type))
     self.finish()
Exemple #24
0
 def get(self):
     self.write(json.dumps(DataParser.get_instance().get_chart_info()))
     self.finish()
Exemple #25
0
 def get(self, *args, **kwargs):
     proj_type = self.get_argument('proj_type', '')
     self.write(DataParser.get_instance().get_chart_info(proj_type))
     self.finish()