本文整理汇总了Python中msg_configer.MSGConfiger.configOptionValue方法的典型用法代码示例。如果您正苦于以下问题:Python MSGConfiger.configOptionValue方法的具体用法?Python MSGConfiger.configOptionValue怎么用?Python MSGConfiger.configOptionValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类msg_configer.MSGConfiger
的用法示例。
在下文中一共展示了MSGConfiger.configOptionValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MSGWeatherDataRetriever
# 需要导入模块: from msg_configer import MSGConfiger [as 别名]
# 或者: from msg_configer.MSGConfiger import configOptionValue [as 别名]
class MSGWeatherDataRetriever(object):
"""
Retrieve national NOAA weather data relevant to the MSG project and save it
to local storage in the path given in the configuration file for [Weather
Data], weather_data_path.
Unzip the retrieved data and recompress the hourly data using gzip.
"""
def __init__(self):
self.configer = MSGConfiger()
self.pool = None
self.fileList = []
self.dateList = []
self.weatherUtil = MSGWeatherDataUtil()
global weatherDataPath
weatherDataPath = self.configer.configOptionValue(WEATHER_DATA, "weather_data_path")
global weatherDataURL
weatherDataURL = self.configer.configOptionValue(WEATHER_DATA, "weather_data_url")
global weatherDataPattern
weatherDataPattern = self.configer.configOptionValue(WEATHER_DATA, "weather_data_pattern")
def fileExists(self, filename):
# @todo Move to external module.
try:
with open(filename):
return True
except IOError, e:
# self.logger.log("IO Error: %s" % e, 'error')
return False
return False
示例2: MECODataAutoloader
# 需要导入模块: from msg_configer import MSGConfiger [as 别名]
# 或者: from msg_configer.MSGConfiger import configOptionValue [as 别名]
class MECODataAutoloader(object):
"""
Provide automated loading of MECO energy data from exports in gzip-compressed XML source data.
"""
def __init__(self):
"""
Constructor.
"""
self.logger = MSGLogger(__name__)
self.configer = MSGConfiger()
self.fileUtil = MSGFileUtil()
def newDataExists(self):
"""
Check the data autoload folder for the presence of new data.
:returns: True if new data exists.
"""
autoloadPath = self.configer.configOptionValue('MECO Autoload', 'meco_new_data_path')
if not self.fileUtil.validDirectory(autoloadPath):
raise Exception('InvalidDirectory', '%s' % autoloadPath)
patterns = ['*.gz']
matchCnt = 0
for root, dirs, filenames in os.walk(autoloadPath):
for pat in patterns:
for filename in fnmatch.filter(filenames, pat):
print filename
matchCnt += 1
if matchCnt > 0:
return True
else:
return False
def loadNewData(self):
"""
Load new data contained in the new data path.
"""
autoloadPath = self.configer.configOptionValue('MECO Autoload', 'meco_new_data_path')
command = self.configer.configOptionValue('MECO Autoload', 'data_load_command')
os.chdir(autoloadPath)
try:
subprocess.check_call(command, shell = True)
except subprocess.CalledProcessError, e:
self.logger.log("An exception occurred: %s" % e, 'error')
示例3: WeatherDataLoadingTester
# 需要导入模块: from msg_configer import MSGConfiger [as 别名]
# 或者: from msg_configer.MSGConfiger import configOptionValue [as 别名]
class WeatherDataLoadingTester(unittest.TestCase):
def setUp(self):
self.weatherUtil = MSGWeatherDataUtil()
self.logger = SEKLogger(__name__, 'DEBUG')
self.dbConnector = MSGDBConnector()
self.cursor = self.dbConnector.conn.cursor()
self.configer = MSGConfiger()
def testLoadDataSinceLastLoaded(self):
"""
Data should be loaded since the last data present in the database.
"""
pass
def testRetrieveDataSinceLastLoaded(self):
"""
Data since the last loaded date is retrieved.
"""
pass
def testGetLastLoadedDate(self):
myDate = self.weatherUtil.getLastDateLoaded(self.cursor).strftime(
"%Y-%m-%d %H:%M:%S")
pattern = '^(\d+-\d+-\d+\s\d+:\d+:\d+)$'
match = re.match(pattern, myDate)
assert match and (match.group(1) == myDate), "Date format is valid."
def testWeatherDataPattern(self):
myPattern = self.configer.configOptionValue('Weather Data',
'weather_data_pattern')
testString = """<A HREF="someURL">QCLCD201208.zip</A>"""
match = re.match(myPattern, testString)
self.logger.log("pattern = %s" % myPattern, 'info')
if match:
self.logger.log("match = %s" % match)
self.logger.log("match group = %s" % match.group(1))
else:
self.logger.log("match not found")
assert match and match.group(
1) == 'QCLCD201208.zip', "Download filename was matched."
def testWeatherDataURL(self):
myURL = self.configer.configOptionValue('Weather Data',
'weather_data_url')
pass
开发者ID:Hawaii-Smart-Energy-Project,项目名称:Maui-Smart-Grid,代码行数:53,代码来源:test_noaa_weather_data_loading.py
示例4: TestMSGDBConnect
# 需要导入模块: from msg_configer import MSGConfiger [as 别名]
# 或者: from msg_configer.MSGConfiger import configOptionValue [as 别名]
class TestMSGDBConnect(unittest.TestCase):
"""
These tests require a database connection to be available.
"""
def setUp(self):
self.connector = MSGDBConnector(True)
self.conn = self.connector.connectDB()
self.configer = MSGConfiger()
def test_init(self):
self.assertTrue(
isinstance(self.connector, msg_db_connector.MSGDBConnector),
"self.connection is an instance of MECODBConnector.")
def test_db_connection(self):
"""
DB can be connected to.
"""
self.assertIsNotNone(self.conn, 'DB connection not available.')
# Get the name of the database.
self.assertEqual(
self.configer.configOptionValue('Database', 'testing_db_name'),
self.connector.dbName, 'Testing DB name is not correct.')
def tearDown(self):
self.connector.closeDB(self.conn)
示例5: TestMECONotifier
# 需要导入模块: from msg_configer import MSGConfiger [as 别名]
# 或者: from msg_configer.MSGConfiger import configOptionValue [as 别名]
class TestMECONotifier(unittest.TestCase):
"""
Unit tests for the MECO Notifier.
"""
def setUp(self):
self.logger = MSGLogger(__name__)
self.notifier = MSGNotifier()
self.configer = MSGConfiger()
def tearDown(self):
pass
def testInit(self):
self.assertIsNotNone(self.notifier, "Notifier has been initialized.")
def testEmailServer(self):
"""
Test connecting to the email server.
"""
errorOccurred = False
user = self.configer.configOptionValue('Notifications', 'email_username')
password = self.configer.configOptionValue('Notifications',
'email_password')
server = smtplib.SMTP(
self.configer.configOptionValue('Notifications', 'email_smtp_server'))
try:
server.starttls()
except smtplib.SMTPException, e:
print "Exception = %s" % e
try:
server.login(user, password)
except smtplib.SMTPException, e:
print "Exception = %s" % e
示例6: TestMECOConfig
# 需要导入模块: from msg_configer import MSGConfiger [as 别名]
# 或者: from msg_configer.MSGConfiger import configOptionValue [as 别名]
class TestMECOConfig(unittest.TestCase):
def setUp(self):
self.configer = MSGConfiger()
def test_init(self):
# @todo Improve this test by using direct introspection instead of
# this roundabout method.
localConfiger = MSGConfiger()
self.assertIsInstance(self.configer, type(localConfiger))
def test_get_debugging(self):
"""
Verify the debugging option in the configuration file.
"""
debugging = self.configer.configOptionValue("Debugging", "debug")
if debugging is False:
self.assertFalse(debugging, "Debugging/debug is not set to False.")
elif debugging is True:
self.assertTrue(debugging, "Debugging/debug is not set to True.")
else:
self.assertTrue(False,
"Debugging/debug does not have a valid value.")
示例7: MSGDBExporter
# 需要导入模块: from msg_configer import MSGConfiger [as 别名]
# 或者: from msg_configer.MSGConfiger import configOptionValue [as 别名]
class MSGDBExporter(object):
"""
Export MSG DBs as SQL scripts.
Supports export to local storage and to cloud storage.
Usage:
from msg_db_exporter import MSGDBExporter
exporter = MSGDBExporter()
Public API:
exportDB(databases:List,
toCloud:Boolean,
testing:Boolean,
numChunks:Integer,
deleteOutdated:Boolean): Export a list of DBs to the cloud.
"""
# List of cloud files.
@property
def cloudFiles(self):
self._cloudFiles = self.driveService.files().list().execute()
return self._cloudFiles
@property
def driveService(self):
if self._driveService:
return self._driveService
if not self.credentialPath:
raise Exception("Credential path is required.")
storage = Storage(
'{}/google_api_credentials'.format(self.credentialPath))
self.googleAPICredentials = storage.get()
self.logger.log("Authorizing credentials.", 'info')
http = httplib2.Http()
http = self.googleAPICredentials.authorize(http)
self.logger.log("Authorized.", 'info')
self._driveService = build('drive', 'v2', http = http)
return self._driveService
def __init__(self):
"""
Constructor.
"""
self.logger = SEKLogger(__name__, 'DEBUG', useColor = False)
self.timeUtil = MSGTimeUtil()
self.configer = MSGConfiger()
self.fileUtil = MSGFileUtil()
self.pythonUtil = MSGPythonUtil() # for debugging
self.connector = MSGDBConnector()
self.conn = self.connector.connectDB()
self.cursor = self.conn.cursor()
self.dbUtil = MSGDBUtil()
self.notifier = SEKNotifier(connector = self.connector,
dbUtil = self.dbUtil,
user = self.configer.configOptionValue(
'Notifications', 'email_username'),
password = self.configer.configOptionValue(
'Notifications', 'email_password'),
fromaddr = self.configer.configOptionValue(
'Notifications', 'email_from_address'),
toaddr = self.configer.configOptionValue(
'Notifications', 'email_recipients'),
testing_toaddr =
self.configer.configOptionValue(
'Notifications',
'testing_email_recipients'),
smtp_server_and_port =
self.configer.configOptionValue(
'Notifications',
'smtp_server_and_port'))
# Google Drive parameters.
self.clientID = self.configer.configOptionValue('Export',
'google_api_client_id')
self.clientSecret = self.configer.configOptionValue('Export',
'google_api_client_secret')
self.oauthScope = 'https://www.googleapis.com/auth/drive'
self.oauthConsent = 'urn:ietf:wg:oauth:2.0:oob'
self.googleAPICredentials = ''
self.exportTempWorkPath = self.configer.configOptionValue('Export',
'db_export_work_path')
self.credentialPath = self.configer.configOptionValue('Export',
'google_api_credentials_path')
self.credentialStorage = Storage(
'{}/google_api_credentials'.format(self.credentialPath))
self._driveService = None
self._cloudFiles = None
#.........这里部分代码省略.........
示例8: MSGNotifier
# 需要导入模块: from msg_configer import MSGConfiger [as 别名]
# 或者: from msg_configer.MSGConfiger import configOptionValue [as 别名]
class MSGNotifier(object):
"""
Provides notification service functionality for MSG data processing.
Email settings are stored in the local configuration.
API:
sendNotificationEmail(msgBody, testing = False):
Send msgBody as a notification to the mailing list defined in the config file.
sendMailWithAttachments(msgBody, files = None, testing = False)
Send msgBody with files attached as a notification to the mailing list defined in the config file.
"""
def __init__(self):
"""
Constructor.
"""
self.config = MSGConfiger()
self.logger = MSGLogger(__name__, 'info')
self.notificationHeader = "This is a message from the Hawaii Smart " \
"Energy Project MSG Project notification " \
"system.\n\n"
self.noReplyNotice = """\n\nThis email account is not monitored. No
replies will originate from this account.\n\nYou are receiving this
message because you are on the recipient list for notifications for
the Hawaii Smart Energy Project."""
def sendNotificationEmail(self, msgBody, testing = False):
"""
This method is an alternative to the multipart method in
sendMailWithAttachments.
:param msgBody: The body of the message to be sent.
:param testing: True if running in testing mode.
:returns: True for success, False for an error.
"""
errorOccurred = False
user = self.config.configOptionValue('Notifications', 'email_username')
password = self.config.configOptionValue('Notifications',
'email_password')
fromaddr = self.config.configOptionValue('Notifications',
'email_fromaddr')
if testing:
toaddr = self.config.configOptionValue('Notifications',
'testing_email_recipients')
else:
toaddr = self.config.configOptionValue('Notifications',
'email_recipients')
server = smtplib.SMTP(
self.config.configOptionValue('Notifications', 'email_smtp_server'))
try:
server.starttls()
except smtplib.SMTPException as detail:
errorOccurred = True
self.logger.log("Exception during SMTP STARTTLS: {}".format(detail),
'ERROR')
try:
server.login(user, password)
except smtplib.SMTPException as detail:
errorOccurred = True
self.logger.log("Exception during SMTP login: %s" % detail, 'ERROR')
senddate = datetime.now().strftime('%Y-%m-%d')
subject = "HISEP Notification"
msgHeader = "Date: {}\r\nFrom: {}\r\nTo: {}\r\nSubject: {" \
"}\r\nX-Mailer: My-Mail\r\n\r\n".format(
senddate, fromaddr, toaddr, subject)
msgBody = self.notificationHeader + msgBody
msgBody += self.noReplyNotice
try:
self.logger.log("Send email notification.", 'INFO')
server.sendmail(fromaddr, toaddr, msgHeader + msgBody)
server.quit()
except smtplib.SMTPException as detail:
errorOccurred = True
self.logger.log("Exception during SMTP sendmail: {}".format(detail),
'ERROR')
return errorOccurred != True
def sendMailWithAttachments(self, msgBody, files = None, testing = False):
"""
Send email along with attachments.
:param msgBody: String containing the body of the messsage to send.
:param files: List of file paths. This is a mutable argument that
#.........这里部分代码省略.........
示例9: MSGDBConnector
# 需要导入模块: from msg_configer import MSGConfiger [as 别名]
# 或者: from msg_configer.MSGConfiger import configOptionValue [as 别名]
dbConnector = MSGDBConnector()
cursor = dbConnector.conn.cursor()
weatherUtil = MSGWeatherDataUtil()
timeUtil = MSGTimeUtil()
msg = "Downloading NOAA weather data (%s)." % timeUtil.conciseNow()
print msg
MSG_BODY = "%s\n" % msg
msg = "Last loaded date is %s." % weatherUtil.datePart(datetime=weatherUtil.getLastDateLoaded(cursor))
print msg
MSG_BODY += "%s\n" % msg
retriever = MSGWeatherDataRetriever()
configer = MSGConfiger()
WEATHER_DATA_PATH = configer.configOptionValue("Weather Data", "weather_data_path")
msg = "Using URL %s." % weatherDataURL
print msg
MSG_BODY += "%s\n" % msg
msg = "Using pattern %s." % weatherDataPattern
print msg
MSG_BODY += "%s\n" % msg
global logger
# @todo verify this usage
logger = SEKLogger(__name__)
weatherDataURL = configer.configOptionValue("Weather Data", "weather_data_url")
示例10: TestMECONotifier
# 需要导入模块: from msg_configer import MSGConfiger [as 别名]
# 或者: from msg_configer.MSGConfiger import configOptionValue [as 别名]
class TestMECONotifier(unittest.TestCase):
"""
Unit tests for the MECO Notifier.
"""
def setUp(self):
self.logger = SEKLogger(__name__)
self.notifier = MSGNotifier()
self.configer = MSGConfiger()
def tearDown(self):
pass
def testInit(self):
self.assertIsNotNone(self.notifier, "Notifier has been initialized.")
def testEmailServer(self):
"""
Test connecting to the email server.
"""
errorOccurred = False
user = self.configer.configOptionValue("Notifications", "email_username")
password = self.configer.configOptionValue("Notifications", "email_password")
server = smtplib.SMTP(self.configer.configOptionValue("Notifications", "smtp_server_and_port"))
try:
server.starttls()
except smtplib.SMTPException as detail:
self.logger.log("Exception: {}".format(detail))
try:
server.login(user, password)
except smtplib.SMTPException as detail:
self.logger.log("Exception: {}".format(detail))
self.assertFalse(errorOccurred, "No errors occurred during SMTP setup.")
def testSendEmailNotification(self):
"""
Send a test notification by email.
"""
if SEND_EMAIL:
success = self.notifier.sendNotificationEmail(
"This is a message from testSendEmailNotification.", testing=True
)
self.assertTrue(success, "Sending an email notification did not produce an" " exception.")
else:
self.assertTrue(True, "Email is not sent when SEND_EMAIL is False.")
def testSendEmailAttachment(self):
"""
Send a test notification with attachment by email.
"""
if SEND_EMAIL:
body = "Test message"
testDataPath = self.configer.configOptionValue("Testing", "test_data_path")
file = os.path.join(testDataPath, "graph.png")
success = self.notifier.sendMailWithAttachments(body, [file], testing=True)
success = success != True
self.assertTrue(success, "Sending an email notification did not produce an" " exception.")
else:
self.assertTrue(True, "Email is not sent when SEND_EMAIL is False.")
示例11: MSGDBExporterTester
# 需要导入模块: from msg_configer import MSGConfiger [as 别名]
# 或者: from msg_configer.MSGConfiger import configOptionValue [as 别名]
class MSGDBExporterTester(unittest.TestCase):
"""
Unit tests for the MSG Cloud Exporter.
"""
def setUp(self):
self.logger = SEKLogger(__name__, 'DEBUG')
self.configer = MSGConfiger()
self.exporter = MSGDBExporter()
self.testDir = 'db_exporter_test'
self.uncompressedTestFilename = 'meco_v3_test_data.sql'
self.compressedTestFilename = 'meco_v3_test_data.sql.gz'
self.exportTestDataPath = self.configer.configOptionValue('Testing',
'export_test_data_path')
self.fileUtil = MSGFileUtil()
self.fileChunks = []
self.testDataFileID = ''
self.pyUtil = MSGPythonUtil()
self.timeUtil = MSGTimeUtil()
conn = None
try:
conn = MSGDBConnector().connectDB()
except Exception as detail:
self.logger.log("Exception occurred: {}".format(detail), 'error')
exit(-1)
self.logger.log("conn = {}".format(conn), 'debug')
self.assertIsNotNone(conn)
# Create a temporary working directory.
try:
os.mkdir(self.testDir)
except OSError as detail:
self.logger.log(
'Exception during creation of temp directory: %s' % detail,
'ERROR')
def tearDown(self):
"""
Delete all test items.
"""
REMOVE_TEMPORARY_FILES = True
if REMOVE_TEMPORARY_FILES:
try:
self.logger.log("Removing local test files {}, {}.".format(
self.uncompressedTestFilename, self.compressedTestFilename),
'debug')
os.remove(os.path.join(os.getcwd(), self.testDir,
self.uncompressedTestFilename))
os.remove(os.path.join(os.getcwd(), self.testDir,
self.compressedTestFilename))
except OSError as detail:
self.logger.log(
'Exception while removing temporary files: {}'.format(
detail), 'SILENT')
try:
os.remove(os.path.join(os.getcwd(), self.testDir,
self.compressedTestFilename))
except OSError as detail:
self.logger.log(
'Exception while removing temporary files: {}'.format(
detail), 'SILENT')
try:
for f in self.fileChunks:
os.remove(f)
except OSError as detail:
self.logger.log(
'Exception while removing temporary files: {}'.format(
detail), 'DEBUG')
try:
os.rmdir(self.testDir)
except OSError as detail:
self.logger.log(
'Exception while removing directory: {}'.format(detail),
'ERROR')
# Keep deleting from the cloud until there are no more to delete.
def deleteFromCloud():
self.logger.log("deleting from cloud", 'debug')
try:
fileIDToDelete = self.exporter.fileIDForFileName(
self.compressedTestFilename)
if fileIDToDelete is None:
return
self.logger.log("file ID to delete: {}".format(fileIDToDelete),
'DEBUG')
self.exporter.driveService.files().delete(
fileId = '{}'.format(fileIDToDelete)).execute()
deleteFromCloud()
except (TypeError, http.HttpError) as e:
self.logger.log('Delete not successful: {}'.format(e), 'DEBUG')
deleteFromCloud()
#.........这里部分代码省略.........
示例12: processCommandLineArguments
# 需要导入模块: from msg_configer import MSGConfiger [as 别名]
# 或者: from msg_configer.MSGConfiger import configOptionValue [as 别名]
processCommandLineArguments()
filename = COMMAND_LINE_ARGS.filename
success = True
anyFailure = False
connector = MSGDBConnector(testing = COMMAND_LINE_ARGS.testing)
conn = connector.connectDB()
cur = conn.cursor()
dbUtil = MSGDBUtil()
notifier = MSGNotifier()
msgBody = ''
configer = MSGConfiger()
if COMMAND_LINE_ARGS.testing:
dbName = configer.configOptionValue("Database", "testing_db_name")
else:
dbName = configer.configOptionValue("Database", "db_name")
msg = ("Loading Meter Location History data in file %s to database %s.\n" % (
filename, dbName))
sys.stderr.write(msg)
msgBody += msg
f = open(filename, "r")
reader = csv.reader(f)
data = []
cols = ["meter_name", "mac_address", "installed", "uninstalled", "location",
"address", "city", "latitude", "longitude", "service_point_id",
"service_point_height", "service_point_latitude",
开发者ID:Hawaii-Smart-Energy-Project,项目名称:Maui-Smart-Grid,代码行数:33,代码来源:insertMECOMeterLocationHistoryData.py
示例13: MSGConfiger
# 需要导入模块: from msg_configer import MSGConfiger [as 别名]
# 或者: from msg_configer.MSGConfiger import configOptionValue [as 别名]
import fnmatch
from msg_configer import MSGConfiger
from msg_notifier import MSGNotifier
import argparse
from sek.logger import SEKLogger
import gzip
from msg_noaa_weather_data_parser import MSGNOAAWeatherDataParser
from msg_noaa_weather_data_inserter import MSGNOAAWeatherDataInserter
from msg_db_connector import MSGDBConnector
from msg_time_util import MSGTimeUtil
from msg_noaa_weather_data_util import MSGWeatherDataUtil
configer = MSGConfiger()
logger = SEKLogger(__name__, 'info')
binPath = MSGConfiger.configOptionValue(configer, "Executable Paths",
"msg_bin_path")
COMMAND_LINE_ARGS = None
msgBody = ''
notifier = MSGNotifier()
dataParser = MSGNOAAWeatherDataParser()
inserter = MSGNOAAWeatherDataInserter()
timeUtil = MSGTimeUtil()
def processCommandLineArguments():
global COMMAND_LINE_ARGS
argParser = argparse.ArgumentParser(
description = 'Perform recursive insertion of compressed weather data'
' contained in the current directory to the MECO '
'database specified in the configuration file.')
argParser.add_argument('--email', action = 'store_true', default = False,
开发者ID:Hawaii-Smart-Energy-Project,项目名称:Maui-Smart-Grid,代码行数:34,代码来源:insertCompressedNOAAWeatherData.py
示例14: MSGDataAggregator
# 需要导入模块: from msg_configer import MSGConfiger [as 别名]
# 或者: from msg_configer.MSGConfiger import configOptionValue [as 别名]
class MSGDataAggregator(object):
"""
Use for continuous data aggregation of diverse data types relevant to the
Maui Smart Grid project.
Four data types are supported:
1. Irradiance
2. Temperature/Humidity (weather)
3. Circuit
4. eGauge
The general data form conforms to
1. timestamp, subkey_id, val1, val2, val3, ...
2. timestamp, val1, val2, val3, ...
Case (2) is handled within the same space as (1) by testing for the
existence of subkeys.
Current aggregation consists of averaging over **15-min intervals**.
Aggregation is performed in-memory and saved to the DB. The time range is
delimited by start date and end date where the values are included in the
range. The timestamps for aggregation intervals are the last timestamp in a
respective series.
* Aggregation subkeys are values such as eGauge IDs or circuit numbers.
Aggregation is being implemented externally for performance and flexibility
advantages over alternative approaches such as creating a view. It may be
rolled into an internal function at future time if that proves to be
beneficial.
Usage:
from msg_data_aggregator import MSGDataAggregator
aggregator = MSGDataAggregator()
API:
aggregateAllData(dataType = dataType)
aggregateNewData(dataType = dataType)
"""
def __init__(self, exitOnError=True, commitOnEveryInsert=False, testing=False):
"""
Constructor.
:param testing: if True, the testing DB will be connected instead of
the production DB.
"""
self.logger = SEKLogger(__name__, "info")
self.configer = MSGConfiger()
self.conn = MSGDBConnector().connectDB()
self.cursor = self.conn.cursor()
self.dbUtil = MSGDBUtil()
self.notifier = MSGNotifier()
self.mathUtil = MSGMathUtil()
self.timeUtil = MSGTimeUtil()
self.nextMinuteCrossing = {}
self.nextMinuteCrossingWithoutSubkeys = None
self.exitOnError = exitOnError
self.commitOnEveryInsert = commitOnEveryInsert
section = "Aggregation"
tableList = [
"irradiance",
"agg_irradiance",
"weather",
"agg_weather",
"circuit",
"agg_circuit",
"egauge",
"agg_egauge",
]
self.dataParams = {
"weather": ("agg_weather", "timestamp", ""),
"egauge": ("agg_egauge", "datetime", "egauge_id"),
"circuit": ("agg_circuit", "timestamp", "circuit"),
"irradiance": ("agg_irradiance", "timestamp", "sensor_id"),
}
self.columns = {}
# tables[datatype] gives the table name for datatype.
self.tables = {t: self.configer.configOptionValue(section, "{}_table".format(t)) for t in tableList}
for t in self.tables.keys():
self.logger.log("t:{}".format(t), "DEBUG")
try:
self.columns[t] = self.dbUtil.columnsString(self.cursor, self.tables[t])
except TypeError as error:
self.logger.log("Ignoring missing table: Error is {}.".format(error), "error")
def existingIntervals(self, aggDataType="", timeColumnName=""):
"""
Retrieve the existing aggregation intervals for the given data type.
#.........这里部分代码省略.........
示例15: MECOPlotting
# 需要导入模块: from msg_configer import MSGConfiger [as 别名]
# 或者: from msg_configer.MSGConfiger import configOptionValue [as 别名]
class MECOPlotting(object):
"""
Provides plotting services to MECO data processing.
"""
def __init__(self, testing = False):
"""
Constructor.
:param testing: Use testing mode if True.
"""
self.reader = MECODBReader(testing)
self.configer = MSGConfiger()
self.dpi = 300
def plotReadingAndMeterCounts(self, databaseName = None):
"""
Create a plot of reading and meter counts.
Save the plot to local storage.
:param databaseName: Name of the database being used to generate the
plot.
"""
matplotlib.pyplot.ioff()
dates, readingCounts, meterCounts = self.reader.readingAndMeterCounts()
newDates = matplotlib.dates.date2num(dates)
plt.xticks(rotation = 'vertical')
plt.xlabel('Date')
plt.ylabel('Counts')
plt.plot_date(newDates, readingCounts, 'yo:', aa = True,
label = 'Readings/Meter')
plt.plot_date(newDates, meterCounts, 'ro:', aa = True, label = 'Meters')
plt.legend(loc = 'best')
localtime = time.asctime(time.localtime(time.time()))
databaseMsg = ''
if databaseName:
databaseMsg = " for Database %s" % databaseName
plt.title(
'Reading Count per Meter and Meter Count by Day%s'
'\nCreated on %s' %
(databaseMsg, localtime))
fig = matplotlib.pyplot.gcf()
fig.set_size_inches(18.5, 11.5)
ax = fig.add_subplot(1, 1, 1)
ax.set_axisbelow(True)
ax.grid(b = True, which = 'major', color = '#dddddd', linestyle = '-')
plotPath = self.configer.configOptionValue("Data Paths", "plot_path")
pylab.savefig('%s/ReadingAndMeterCounts.png' % plotPath, dpi = self.dpi)