Exemplo n.º 1
0
 def get(self):
     user = self.get_current_user()
     dev_observed = Device_Observed()
     device_counts = dev_observed.count_user_devices(user.id)
     res_image = self.get_image_summary_info(user)
     res_data = self.get_data_summary_info(user)
     self.on_get_summery_info(res_image, res_data)
Exemplo n.º 2
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,
                )
Exemplo n.º 3
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,
                )
Exemplo n.º 4
0
 def get(self):
     user = self.get_current_user()
     print "home page"
     dev_observed = Device_Observed()
     device_counts = dev_observed.count_user_devices(user.id)
     res = task.get_summery_info(user)
     self.on_get_summery_info(res)
Exemplo n.º 5
0
    def get_image_summary_info(self, user):
        dev_observed = Device_Observed()
        res = {
            'user_name': user.name,
            'device_counts': dev_observed.count_user_devices(user.id),
            'device_info': []
        }
        devices = dev_observed.observed_devices(user.id)
        print devices
        pos = Position_Image()
        for dev in devices:
            contents_dev = {}
            print dev
            contents_dev['location'] = dev.location
            contents_dev['position_contents'] = []
            positions = pos.get_position_by_device_id(dev.id)
            if positions:
                for pos in positions:
                    img = Image()
                    image_count = img.count_by('where position_id = ?', pos.id)
                    contents_dev['position_contents'].append({
                        'position':
                        pos.position,
                        'duration':
                        pos.duration,
                        'image_count':
                        image_count,
                        'object_name':
                        pos.object_name
                    })
            res['device_info'].append(contents_dev)

        return res
Exemplo n.º 6
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)
Exemplo n.º 7
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)
Exemplo n.º 8
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,
        )
Exemplo n.º 9
0
 def on_login_success(self, resp):
     if resp:
         dev_observed = Device_Observed()
         if self.observed:
             dev_observed.observe(resp, self.device_id)
         else:
             dev_observed.unobserve(resp, self.device_id)
         return True
     return False
Exemplo n.º 10
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))
Exemplo n.º 11
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
Exemplo n.º 12
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
Exemplo n.º 13
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))
Exemplo n.º 14
0
def get_summery_info(user):
    dev_observed = Device_Observed()
    res = {'user_name': user.name, 'device_counts': dev_observed.count_user_devices(user.id), 'device_info': []}
    devices = dev_observed.observed_devices(user.id)
    print devices
    pos = Position()
    for dev in devices:
        contents_dev = {}
        print dev
        contents_dev['location'] = dev.location
        contents_dev['position_contents'] = []
        positions = pos.get_position_by_device_id(dev.id)
        if positions:
            for pos in positions:
                img = Image()
                image_count = img.count_by('where position_id = ?', pos.id)
                contents_dev['position_contents'].append({'position': pos.position,
                                                          'duration': pos.duration,
                                                          'image_count': image_count,
                                                          'object_name': pos.object_name})
        res['device_info'].append(contents_dev)

    return res
Exemplo n.º 15
0
from model.device_observed import Device_Observed
from model.image import Image
from model.position import Position_Image
from model.data import Data, Data_Table_Map
from model.user import User

import sys

def connect_db():
    import transwarp.db as dbutil
    dbutil.create_engine('sonic513', 'sonic513', 'co2_monitor', port=3306)

if __name__=="__main__":
    connect_db()
    dev = Device()
    dev.create_table()
    usr = User()
    usr.create_table()
    doed = Device_Observed()
    doed.create_table()
    dtm = Data_Table_Map()
    dtm.create_table()
    #img = Image()
    #img.create_table()
    #pos_image = Position_Image()
    #pos_image.create_table()
    #data = Data()
    #data.create_table()

    
# coding=utf-8
from model.device import Device
from model.user import User
from model.device_observed import Device_Observed
import sys

def connect_db():
    import transwarp.db as dbutil
    dbutil.create_engine('sonic513', 'sonic513', 'tobacco_monitor', port=3306)

if __name__=="__main__":
    connect_db()
    user_name = sys.argv[1]
    mac = sys.argv[2]
    dev = Device.find_first("where mac = ?", mac.strip())
    usr = User.find_first("where name = ?", user_name.strip())
    dev_obs = Device_Observed()
    if dev_obs.observe(usr.id, dev.id):
        print "dev observe success!"
    else:
        print "dev observe fail!"
Exemplo n.º 17
0
    def get(self, *args,**kwargs):
        usr = self.get_current_user()
        device_observed = Device_Observed()
        position = Position_Image()
        image = Image()
        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")

        positions = []
        for dev in devices:
            positions.extend(position.get_position_by_device_id(dev.id))
        current_position_id = self.get_argument('position_id', '')
        current_page = self.get_argument('page', '')
        if current_page:
            current_page = int(current_page)
        else:
            current_page = 1
            
        if current_position_id:
            current_position_id = current_position_id
        else:
            # positions = position.get_position_by_device_id(devices[0].id)
            if positions:
                current_position_id = positions[0].id
            else:
                current_position_id = 0
        total_image_num = image.count_by_position_id(current_position_id)
        total_page_num = total_image_num/IMAGE_NUMBER_FOR_PAGE+1
        start_image_num = (current_page - 1)*IMAGE_NUMBER_FOR_PAGE + 1

        if total_page_num < current_page:
            current_page = total_page_num

        images = image.find_by('order by id desc limit ? offset ?',
                               IMAGE_NUMBER_FOR_PAGE,
                               (current_page - 1)*IMAGE_NUMBER_FOR_PAGE)
        for img in images:
            img.created_at = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(img.created_at))
        # get the start and end page num
        if current_page > 3:
            start_page_num = current_page-3
        else:
            start_page_num = 1

        end_page_num = start_page_num+6
        if end_page_num>total_page_num:
            end_page_num = total_page_num
            start_page_num = end_page_num-6
            if start_page_num<1:
                start_page_num = 1

        end_image_num  = start_image_num+len(images)-1

        return self.render('browser.html',
                           page_name='browser',
                           positions=positions,
                           current_position_id=current_position_id,
                           current_page=current_page,
                           total_page_num=total_page_num,
                           total_image_num=total_image_num,
                           start_image_num=start_image_num,
                           end_image_num=end_image_num,
                           start_page_num=start_page_num,
                           end_page_num=end_page_num,
                           user_name=usr.name,
                           images=images
                           )
Exemplo n.º 18
0
    def get(self, *args, **kwargs):
        usr = self.get_current_user()
        device_observed = Device_Observed()
        position = Position_Image()
        image = Image()
        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")

        positions = []
        for dev in devices:
            positions.extend(position.get_position_by_device_id(dev.id))
        current_position_id = self.get_argument('position_id', '')
        current_page = self.get_argument('page', '')
        if current_page:
            current_page = int(current_page)
        else:
            current_page = 1

        if current_position_id:
            current_position_id = current_position_id
        else:
            # positions = position.get_position_by_device_id(devices[0].id)
            if positions:
                current_position_id = positions[0].id
            else:
                current_position_id = 0
        total_image_num = image.count_by_position_id(current_position_id)
        total_page_num = total_image_num / IMAGE_NUMBER_FOR_PAGE + 1
        start_image_num = (current_page - 1) * IMAGE_NUMBER_FOR_PAGE + 1

        if total_page_num < current_page:
            current_page = total_page_num

        images = image.find_by('order by id desc limit ? offset ?',
                               IMAGE_NUMBER_FOR_PAGE,
                               (current_page - 1) * IMAGE_NUMBER_FOR_PAGE)
        for img in images:
            img.created_at = time.strftime("%Y-%m-%d %H:%M:%S",
                                           time.localtime(img.created_at))
        # get the start and end page num
        if current_page > 3:
            start_page_num = current_page - 3
        else:
            start_page_num = 1

        end_page_num = start_page_num + 6
        if end_page_num > total_page_num:
            end_page_num = total_page_num
            start_page_num = end_page_num - 6
            if start_page_num < 1:
                start_page_num = 1

        end_image_num = start_image_num + len(images) - 1

        return self.render('browser.html',
                           page_name='browser',
                           positions=positions,
                           current_position_id=current_position_id,
                           current_page=current_page,
                           total_page_num=total_page_num,
                           total_image_num=total_image_num,
                           start_image_num=start_image_num,
                           end_image_num=end_image_num,
                           start_page_num=start_page_num,
                           end_page_num=end_page_num,
                           user_name=usr.name,
                           images=images)
Exemplo n.º 19
0
# coding=utf-8
from model.device import Device
from model.user import User
from model.device_observed import Device_Observed
import sys


def connect_db():
    import transwarp.db as dbutil
    dbutil.create_engine('sonic513', 'sonic513', 'co2_monitor', port=3306)


if __name__ == "__main__":
    connect_db()
    user_name = sys.argv[1]
    mac = sys.argv[2]
    dev = Device.find_first("where mac = ?", mac.strip())
    usr = User.find_first("where name = ?", user_name.strip())
    dev_obs = Device_Observed()
    if dev_obs.observe(usr.id, dev.id):
        print "dev observe success!"
    else:
        print "dev observe fail!"