Beispiel #1
0
 def get_unassigned_chips(self):
         """
         Returns a list of all devices that have not been assigned to a group
         @rtype: array
         @return: an xml file containing the addresses of devices which belong to group 0 ('unassigned')
         """
         query = self.cursor.execute('select distinct address from chip where group_id=0').fetchall()
         res = []
         i = 0
         xml = XMLGenerator()
         while(i<len(query)):
                 xml.add_unassigned_board(str(query[i][0]))
                 i+=1
         return xml.print_xml()
Beispiel #2
0
 def get_times(self,chip_id,table):
         """
         Returns the first and last entry of a specified device in a sensor measurements table
         @type chip_id: string
         @param chip_id: the address of the device
         @type table: string
         @param table: the table containing sensor readings
         @rtype: string
         @return: an xml file containing the query result
         """
         xml = XMLGenerator()
         if(self.check_table_name(table)==1 and self.check_chip(chip_id)==1):
                 query = self.cursor.execute('select min(time),max(time) from '+table+' where chip_addr=?',(chip_id,)).fetchone()
                 xml.add_new_data_element(str(chip_id),('mintime','maxtime'),(query[0],query[1]))
         return xml.print_xml()
Beispiel #3
0
 def get_unassigned_chips(self):
     """
             Returns a list of all devices that have not been assigned to a group
             @rtype: array
             @return: an xml file containing the addresses of devices which belong to group 0 ('unassigned')
             """
     query = self.cursor.execute(
         'select distinct address from chip where group_id=0').fetchall()
     res = []
     i = 0
     xml = XMLGenerator()
     while (i < len(query)):
         xml.add_unassigned_board(str(query[i][0]))
         i += 1
     return xml.print_xml()
Beispiel #4
0
 def get_measurements(self,table,start,end,step,group_id=None,boards=[]):
         """
         Returns an xml file containing the averaged sensor readings from a specified group or device for a given period of time
             - If no devices specified, queries all devices that have provided sensor readings
             - if no group specified, queries all groups
         @type table: string
         @param table: the type of sensor measurements to be queried
         @type start: number
         @param start: the start time of the period which is queried
         @type end: number
         @param end: the end time of the period which is queried
         @type step: number
         @param step: the number of steps at which to average the data. 
         @type group_id : number
         @param group_id: the group which will be queried
         @type boards: array
         @param boards: the devices which will be queried for data
         @rtype: string
         @return: an xml file containing the results of the query                
         """
         xml = XMLGenerator()
         if(self.check_table_name(table)==1):
                 tm = round((end-start)/step)
                 if(boards==[]):
                         chips = self.get_chips()
                         query = []
                         for x in chips:
                                 if(group_id == None):
                                         query = self.cursor.execute('select avg(value),(ROUND(time/?)) as gtime, time from '+table+',chip where chip_addr=? and chip.address='+table+'.chip_addr and time>? and time<? group by (gtime)',(tm,x,start,end)).fetchall()
                                 else:
                                         query = self.cursor.execute('select avg(value),(ROUND(time/?)) as gtime, time from '+table+',chip where chip_addr=? and chip.group_id=? and chip.address='+table+'.chip_addr and time>? and time<? group by (gtime)',(tm,x,group_id,start,end)).fetchall()
                                 xml.add_new_board(x,table)
                                 for y in query:
                                         xml.add_board_value(table,y[0],y[2])
                                                                             
                 else:
                         query = []
                         for x in boards:
                                 #Query for a single board
                                 if(group_id == None):
                                         query = self.cursor.execute('select avg(value),(ROUND(time/?)) as gtime, time from '+table+',chip where chip_addr=? and chip.address='+table+'.chip_addr and time>? and time<? group by (gtime)',(tm,x,start,end)).fetchall()
                                 else:
                                         query = self.cursor.execute('select avg(value),(ROUND(time/?)) as gtime, time from '+table+',chip where chip_addr=? and chip.group_id=? and chip.address='+table+'.chip_addr and time>? and time<? group by (gtime)',(tm,x,group_id,start,end)).fetchall()
                                 xml.add_new_board(x,'temp')
                                 for y in query:
                                         xml.add_board_temp(y[0],y[2])                                       
                 
         return xml.print_xml()
Beispiel #5
0
 def get_groups(self, xml_stat):
         """
         Returns a list of the existing groups
         @type xml_stat: number
         @param xml_stat: flag for xml parsing. If 1, create an xml file with the results. Otherwise, do not create an xml file
         @return: a list (in xml format or not) containing all existing groups
         """
         if(xml_stat == 1):
                 xml = XMLGenerator()
         query = self.cursor.execute('select * from chip_group').fetchall()
         if(xml_stat == 1):
                 for x in query:
                         xml.add_group(x[0],x[1])
                 return xml.print_xml()
         else:
                 res = []
                 for x in query:
                         res.append((x[0],x[1]))
                 return res
Beispiel #6
0
 def get_times(self, chip_id, table):
     """
             Returns the first and last entry of a specified device in a sensor measurements table
             @type chip_id: string
             @param chip_id: the address of the device
             @type table: string
             @param table: the table containing sensor readings
             @rtype: string
             @return: an xml file containing the query result
             """
     xml = XMLGenerator()
     if (self.check_table_name(table) == 1
             and self.check_chip(chip_id) == 1):
         query = self.cursor.execute(
             'select min(time),max(time) from ' + table +
             ' where chip_addr=?', (chip_id, )).fetchone()
         xml.add_new_data_element(str(chip_id), ('mintime', 'maxtime'),
                                  (query[0], query[1]))
     return xml.print_xml()
Beispiel #7
0
    def get_chips_xml(self, group_id):
        """
                Queries for all devices belonging to a specified group and returns an xml file
                @type group_id: number
                @param group_id: the group id
                @rtype: string
                @return: the xml-parsed result of the query
                """
        xml = XMLGenerator()
        query = []
        query = self.cursor.execute('select * from chip where group_id=?',
                                    (group_id, )).fetchall()
        group_name = self.get_group_name(group_id)
        if (group_name != ''):
            xml.add_group(group_id, group_name)
            for x in query:
                if (str(x[6]) == group_id):
                    xml.add_new_board(x[1], 'test', x[2], x[4], x[5])

        return xml.print_xml()
Beispiel #8
0
 def get_chips_xml(self,group_id):
         """
         Queries for all devices belonging to a specified group and returns an xml file
         @type group_id: number
         @param group_id: the group id
         @rtype: string
         @return: the xml-parsed result of the query
         """
         xml = XMLGenerator()
         query = []
         query = self.cursor.execute('select * from chip where group_id=?',(group_id,)).fetchall()
         group_name = self.get_group_name(group_id)
         if(group_name!=''):
                 xml.add_group(group_id,group_name)
                 for x in query:
                         if(str(x[6]) == group_id):
                                 xml.add_new_board(x[1],'test',x[2],x[4],x[5])
                 
         return xml.print_xml()
 def get_user_settings(self):
     xml = XMLGenerator()
     xml.add_user_setting('mintemp',self.mintemp)
     xml.add_user_setting('maxtemp',self.maxtemp)
     return xml.print_xml()
Beispiel #10
0
    def get_measurements(self,
                         table,
                         start,
                         end,
                         step,
                         group_id=None,
                         boards=[]):
        """
                Returns an xml file containing the averaged sensor readings from a specified group or device for a given period of time
                    - If no devices specified, queries all devices that have provided sensor readings
                    - if no group specified, queries all groups
                @type table: string
                @param table: the type of sensor measurements to be queried
                @type start: number
                @param start: the start time of the period which is queried
                @type end: number
                @param end: the end time of the period which is queried
                @type step: number
                @param step: the number of steps at which to average the data. 
                @type group_id : number
                @param group_id: the group which will be queried
                @type boards: array
                @param boards: the devices which will be queried for data
                @rtype: string
                @return: an xml file containing the results of the query                
                """
        xml = XMLGenerator()
        if (self.check_table_name(table) == 1):
            tm = round((end - start) / step)
            if (boards == []):
                chips = self.get_chips()
                query = []
                for x in chips:
                    if (group_id == None):
                        query = self.cursor.execute(
                            'select avg(value),(ROUND(time/?)) as gtime, time from '
                            + table +
                            ',chip where chip_addr=? and chip.address=' +
                            table +
                            '.chip_addr and time>? and time<? group by (gtime)',
                            (tm, x, start, end)).fetchall()
                    else:
                        query = self.cursor.execute(
                            'select avg(value),(ROUND(time/?)) as gtime, time from '
                            + table +
                            ',chip where chip_addr=? and chip.group_id=? and chip.address='
                            + table +
                            '.chip_addr and time>? and time<? group by (gtime)',
                            (tm, x, group_id, start, end)).fetchall()
                    xml.add_new_board(x, table)
                    for y in query:
                        xml.add_board_value(table, y[0], y[2])

            else:
                query = []
                for x in boards:
                    #Query for a single board
                    if (group_id == None):
                        query = self.cursor.execute(
                            'select avg(value),(ROUND(time/?)) as gtime, time from '
                            + table +
                            ',chip where chip_addr=? and chip.address=' +
                            table +
                            '.chip_addr and time>? and time<? group by (gtime)',
                            (tm, x, start, end)).fetchall()
                    else:
                        query = self.cursor.execute(
                            'select avg(value),(ROUND(time/?)) as gtime, time from '
                            + table +
                            ',chip where chip_addr=? and chip.group_id=? and chip.address='
                            + table +
                            '.chip_addr and time>? and time<? group by (gtime)',
                            (tm, x, group_id, start, end)).fetchall()
                    xml.add_new_board(x, 'temp')
                    for y in query:
                        xml.add_board_temp(y[0], y[2])

        return xml.print_xml()