class NewDataAggregator(object): """ Perform aggregation of new data for a set of predefined data types (self .rawTypes). """ def __init__(self): """ Constructor. """ self.logger = SEKLogger(__name__, 'DEBUG') self.aggregator = MSGDataAggregator() self.notifier = MSGNotifier() self.rawTypes = [x.name for x in list(MSGAggregationTypes)] self.connector = MSGDBConnector() self.conn = self.connector.connectDB() self.cursor = self.conn.cursor() self.dbUtil = MSGDBUtil() def sendNewDataNotification(self, result = None, testing = False): """ Sending notification reporting on new data being available since the last time new data was reported. :param result: list of dicts containing aggregation results as provided by MSGDataAggregator::aggregateNewData. :param testing: Use testing mode when True. """ self.logger.log('result {}'.format(result), 'debug') lastReportDate = self.notifier.lastReportDate( MSGNotificationHistoryTypes.MSG_DATA_AGGREGATOR) if not lastReportDate: lastReportDate = "never" if not result: msgBody = '\nNew data has NOT been aggregated in {}. No result ' \ 'was obtained. This is an error that should be ' \ 'investigated.'.format(self.connector.dbName) else: msgBody = '\nNew data has been aggregated in {}.'.format( self.connector.dbName) msgBody += '\n\n' for i in range(len(result)): msgBody += 'The new data count for type {} is {} readings' \ '.\n'.format(result[i].keys()[0], result[i].values()[0]) msgBody += '\n\n' msgBody += 'The last report date was %s.' % lastReportDate msgBody += '\n\n' self.notifier.sendNotificationEmail(msgBody, testing = testing) self.notifier.recordNotificationEvent( MSGNotificationHistoryTypes.MSG_DATA_AGGREGATOR) def aggregateNewData(self): """ :return: list of dicts obtained from MSGDataAggregator::aggregateNewData. """ result = map(self.aggregator.aggregateNewData, self.rawTypes) self.logger.log('result {}'.format(result)) return result
class NewDataAggregator(object): """ Perform aggregation of new data for a set of predefined data types (self .rawTypes). """ def __init__(self): """ Constructor. """ self.logger = SEKLogger(__name__, 'DEBUG') self.aggregator = MSGDataAggregator() self.notifier = MSGNotifier() self.rawTypes = [x.name for x in list(MSGAggregationTypes)] self.connector = MSGDBConnector() self.conn = self.connector.connectDB() self.cursor = self.conn.cursor() self.dbUtil = MSGDBUtil() def sendNewDataNotification(self, result=None, testing=False): """ Sending notification reporting on new data being available since the last time new data was reported. :param result: list of dicts containing aggregation results as provided by MSGDataAggregator::aggregateNewData. :param testing: Use testing mode when True. """ self.logger.log('result {}'.format(result), 'debug') lastReportDate = self.notifier.lastReportDate( MSGNotificationHistoryTypes.MSG_DATA_AGGREGATOR) if not lastReportDate: lastReportDate = "never" if not result: msgBody = '\nNew data has NOT been aggregated in {}. No result ' \ 'was obtained. This is an error that should be ' \ 'investigated.'.format(self.connector.dbName) else: msgBody = '\nNew data has been aggregated in {}.'.format( self.connector.dbName) msgBody += '\n\n' for i in range(len(result)): msgBody += 'The new data count for type {} is {} readings' \ '.\n'.format(result[i].keys()[0], result[i].values()[0]) msgBody += '\n\n' msgBody += 'The last report date was %s.' % lastReportDate msgBody += '\n\n' self.notifier.sendNotificationEmail(msgBody, testing=testing) self.notifier.recordNotificationEvent( MSGNotificationHistoryTypes.MSG_DATA_AGGREGATOR) def aggregateNewData(self): """ :return: list of dicts obtained from MSGDataAggregator::aggregateNewData. """ result = map(self.aggregator.aggregateNewData, self.rawTypes) self.logger.log('result {}'.format(result)) return result