# Path: myDevices/utils/logger.py
# def exception(message):
#     if checkFlood(message):
#         return
#     LOGGER.exception(message)
# 
# def info(message):
#     # if checkFlood(message):
#     #     return
#     LOGGER.info(message)
# 
# def warn(message):
#     if checkFlood(message):
#         return
#     LOGGER.warn(message)
# 
# def error(message, *args, **kwargs):
#     if checkFlood(message):
#         return
#     LOGGER.error(message, *args, **kwargs)
# 
# def debug(message):
#     outerFrame = getouterframes(currentframe())[1][0]
#     (args, _, _, values) = getargvalues(outerFrame)
#     argsValue = ''
#     
#     for i in args:
#         if i is 'self':
#             continue
#         argsValue += "(%s=%s)" % (i, str(values[i]))
#     
#     stack = extract_stack()
#     (filename, line, procname, text) = stack[-2]
#     LOGGER.debug(str(filename) + ' ' + str(procname) + str(argsValue) + ':' + str(line) + '> '  + str(message))
# 
# def setDebug():
#     LOGGER.setLevel(DEBUG)
#     return
# 
# def logJson(message, category = ''):
#     if debugEnabled() == False:
#         return
#     if checkFlood(message):
#         return
#     try:
#         if category not in jsonData:
#             jsonData[category] = []
#         if len(jsonData[category]) > MAX_JSON_ITEMS_PER_CATEGORY:
#             del jsonData[category][0]
#         #2016-03-23 03:53:16 - myDevices - INFO -
#         message = str(datetime.today()) + ' - myDevices - INFO - ' + message
#         jsonData[category].append(message)
#         rotatorJson()
#     except Exception as ex:
#         exception("logJson failed")


from myDevices.utils.logger import exception, info, warn, error, debug, setDebug, logJson
from json import loads, dumps
from time import time
from datetime import datetime, timedelta
from sqlite3 import connect
from operator import itemgetter
from os import rename
from sys import argv
        return avg_array

    def CalculateNetworkSpeedAverages(self, current_avgs, new_sample, count):
        try:
            if 'NetworkSpeed' not in current_avgs:
                if 'NetworkSpeed' in new_sample:
                    current_avgs['NetworkSpeed'] = new_sample['NetworkSpeed']
                    return           
            if new_sample['NetworkSpeed'] != 'None':
                if current_avgs['NetworkSpeed'] == 'None':
                    current_avgs['NetworkSpeed'] = new_sample['NetworkSpeed']
                else:
                    current_avgs['NetworkSpeed'] = str(self.CalculateAverage(float(current_avgs['NetworkSpeed']), float(new_sample['NetworkSpeed']), count))
        except:
            exception('Error calculating network speed average')
                
    def CalculateSystemInfoAverages(self, current_avgs, new_sample, count):
        try:
            if 'SystemInfo' not in new_sample or new_sample['SystemInfo'] is None:
                return
            if 'SystemInfo' not in current_avgs:
                current_avgs['SystemInfo'] = new_sample['SystemInfo']
                return       
            #Calculate CPU averages
            try:
                if 'CpuLoad' not in current_avgs['SystemInfo']:
                    current_avgs['SystemInfo']['CpuLoad'] = new_sample['SystemInfo']['CpuLoad']
                else:        
                    current_avgs['SystemInfo']['CpuLoad'] = self.CalculateSubItemAverages(current_avgs['SystemInfo']['CpuLoad'], new_sample['SystemInfo']['CpuLoad'], count)
            except KeyError as e:

# Path: myDevices/utils/logger.py
# def exception(message):
#     if checkFlood(message):
#         return
#     LOGGER.exception(message)
# 
# def info(message):
#     # if checkFlood(message):
#     #     return
#     LOGGER.info(message)
# 
# def warn(message):
#     if checkFlood(message):
#         return
#     LOGGER.warn(message)
# 
# def error(message, *args, **kwargs):
#     if checkFlood(message):
#         return
#     LOGGER.error(message, *args, **kwargs)
# 
# def debug(message):
#     outerFrame = getouterframes(currentframe())[1][0]
#     (args, _, _, values) = getargvalues(outerFrame)
#     argsValue = ''
#     
#     for i in args:
#         if i is 'self':
#             continue
#         argsValue += "(%s=%s)" % (i, str(values[i]))
#     
#     stack = extract_stack()
#     (filename, line, procname, text) = stack[-2]
#     LOGGER.debug(str(filename) + ' ' + str(procname) + str(argsValue) + ':' + str(line) + '> '  + str(message))
# 
# def setDebug():
#     LOGGER.setLevel(DEBUG)
#     return
# 
# def logJson(message, category = ''):
#     if debugEnabled() == False:
#         return
#     if checkFlood(message):
#         return
#     try:
#         if category not in jsonData:
#             jsonData[category] = []
#         if len(jsonData[category]) > MAX_JSON_ITEMS_PER_CATEGORY:
#             del jsonData[category][0]
#         #2016-03-23 03:53:16 - myDevices - INFO -
#         message = str(datetime.today()) + ' - myDevices - INFO - ' + message
#         jsonData[category].append(message)
#         rotatorJson()
#     except Exception as ex:
#         exception("logJson failed")


# Path: myDevices/utils/history.py
from myDevices.utils.logger import exception, info, warn, error, debug, setDebug, logJson
from json import loads, dumps
from time import time
from datetime import datetime, timedelta
from sqlite3 import connect
from operator import itemgetter
from os import rename
from sys import argv

        return avg_array

    def CalculateNetworkSpeedAverages(self, current_avgs, new_sample, count):
        try:
            if 'NetworkSpeed' not in current_avgs:
                if 'NetworkSpeed' in new_sample:
                    current_avgs['NetworkSpeed'] = new_sample['NetworkSpeed']
                    return           
            if new_sample['NetworkSpeed'] != 'None':
                if current_avgs['NetworkSpeed'] == 'None':
                    current_avgs['NetworkSpeed'] = new_sample['NetworkSpeed']
                else:
                    current_avgs['NetworkSpeed'] = str(self.CalculateAverage(float(current_avgs['NetworkSpeed']), float(new_sample['NetworkSpeed']), count))
        except:
            exception('Error calculating network speed average')
                
    def CalculateSystemInfoAverages(self, current_avgs, new_sample, count):
        try:
            if 'SystemInfo' not in new_sample or new_sample['SystemInfo'] is None:
                return
            if 'SystemInfo' not in current_avgs:
                current_avgs['SystemInfo'] = new_sample['SystemInfo']
                return       
            #Calculate CPU averages
            try:
                if 'CpuLoad' not in current_avgs['SystemInfo']:
                    current_avgs['SystemInfo']['CpuLoad'] = new_sample['SystemInfo']['CpuLoad']
                else:        
                    current_avgs['SystemInfo']['CpuLoad'] = self.CalculateSubItemAverages(current_avgs['SystemInfo']['CpuLoad'], new_sample['SystemInfo']['CpuLoad'], count)
            except KeyError as e:

                debug('KeyError: {}'.format(e))