Esempio n. 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)
Esempio n. 2
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)
Esempio n. 3
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
Esempio n. 4
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,
                )
Esempio n. 5
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))
Esempio n. 6
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,
        )
Esempio n. 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,
                )
Esempio n. 8
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)
Esempio n. 9
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)
Esempio n. 10
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()
Esempio n. 11
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()
Esempio n. 12
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)
Esempio n. 13
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
Esempio n. 14
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))
Esempio n. 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))
Esempio n. 16
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)
Esempio n. 17
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))