(self)
return hourReport
Return statistics per hour of the day
Return statistics per hour of the day
Return statistics per hour of the day
def reportByHour(self):
        """Return statistics per hour of the day"""
        condition = "unixtime > '{}%'".format(self.periodFilter)
        timeColumns = "strftime('%H', unixtime) as hour,count(*) as count"
        group = "group by hour"
        order = "order by hour"
        query = "select {} from connections where {} {} {}".format(
            timeColumns, condition, group, order)
        cursor = self.conn.execute(query)

        # First pass, get the max value
        hourReport = None
        maxCon = 0
        for row in cursor:
            maxCon = max(maxCon, row[1])

        # Build the hour report only if required
        if maxCon != 0:

            # Initialise the hour report to an array with all possible hours
            hourReport = []
            for h in range(0, 24):
                empty = { 'hour': h, 'count': 0 }
                hourReport.append(empty)

            cursor = self.conn.execute(query)
            for row in cursor:
                line = {}
                hour = int(row[0])
                line['hour'] = hour
                line['count'] = int(20 * int(row[1]) / maxCon)
                hourReport[hour] = line

        return hourReport
def reportByHour ( self ) : condition = "unixtime > '{}%'" . format ( self . periodFilter ) timeColumns = "strftime('%H', unixtime) as hour,count(*) as count" group = "group by hour" order = "order by hour" query = "select {} from connections where {} {} {}" . format ( timeColumns , condition , group , order ) cursor = self . conn . execute ( query ) # First pass, get the max value hourReport = None maxCon = 0 for row in cursor : maxCon = max ( maxCon , row [ 1 ] ) # Build the hour report only if required if maxCon != 0 : # Initialise the hour report to an array with all possible hours hourReport = [ ] for h in range ( 0 , 24 ) : empty = { 'hour' : h , 'count' : 0 } hourReport . append ( empty ) cursor = self . conn . execute ( query ) for row in cursor : line = { } hour = int ( row [ 0 ] ) line [ 'hour' ] = hour line [ 'count' ] = int ( 20 * int ( row [ 1 ] ) / maxCon ) hourReport [ hour ] = line return hourReport