def setUp(self): self.reader = MECODBReader() self.connector = MSGDBConnector(True) self.conn = self.connector.connectDB() self.inserter = MECODBInserter() self.util = MSGDBUtil() self.lastSeqVal = None self.tableName = 'MeterData' self.colName = 'meter_data_id' self.deleter = MECODBDeleter()
def setUp(self): self.i = MECODBInserter() self.util = MSGDBUtil() self.connector = MSGDBConnector(True) self.deleter = MECODBDeleter() self.reader = MECODBReader() self.lastSeqVal = None self.conn = self.connector.connectDB() self.sampleTableName = 'MeterData' self.sampleDict = {'MeterName': '100001', 'UtilDeviceID': '100001', 'MacID': '00:00:00:00:00:00:00:00'} self.keyName = 'meter_data_id'
def __init__(self, testing = False): """ Constructor. :param testing: Use testing mode if True. """ self.reader = MECODBReader(testing) self.configer = MSGConfiger() self.dpi = 300
class TestMECODBRead(unittest.TestCase): def setUp(self): self.reader = MECODBReader() self.connector = MSGDBConnector(True) self.conn = self.connector.connectDB() self.inserter = MECODBInserter() self.util = MSGDBUtil() self.lastSeqVal = None self.tableName = 'MeterData' self.colName = 'meter_data_id' self.deleter = MECODBDeleter() def testMECODBReadCanBeInited(self): self.assertIsNotNone(self.reader) def testSelectRecord(self): """ Insert and retrieve a record to test the ability to select a record. """ print "testSelectRecord:" print "self.conn = %s" % self.conn sampleDict = { 'MeterName': '100001', 'UtilDeviceID': '100001', 'MacID': '00:00:00:00:00:00:00:00' } self.inserter.insertData(self.conn, self.tableName, sampleDict) self.lastSeqVal = self.util.getLastSequenceID(self.conn, self.tableName, self.colName) print "lastSeqVal = %s" % self.lastSeqVal row = self.reader.selectRecord(self.conn, self.tableName, self.colName, self.lastSeqVal) self.assertEqual(row[self.colName], self.lastSeqVal) def tearDown(self): # Delete the record that was inserted. if self.lastSeqVal != None: self.deleter.deleteRecord(self.conn, self.tableName, self.colName, self.lastSeqVal) self.connector.closeDB(self.conn)
class TestMECODBRead(unittest.TestCase): def setUp(self): self.reader = MECODBReader() self.connector = MSGDBConnector(True) self.conn = self.connector.connectDB() self.inserter = MECODBInserter() self.util = MSGDBUtil() self.lastSeqVal = None self.tableName = 'MeterData' self.colName = 'meter_data_id' self.deleter = MECODBDeleter() def testMECODBReadCanBeInited(self): self.assertIsNotNone(self.reader) def testSelectRecord(self): """ Insert and retrieve a record to test the ability to select a record. """ print "testSelectRecord:" print "self.conn = %s" % self.conn sampleDict = {'MeterName': '100001', 'UtilDeviceID': '100001', 'MacID': '00:00:00:00:00:00:00:00'} self.inserter.insertData(self.conn, self.tableName, sampleDict) self.lastSeqVal = self.util.getLastSequenceID(self.conn, self.tableName, self.colName) print "lastSeqVal = %s" % self.lastSeqVal row = self.reader.selectRecord(self.conn, self.tableName, self.colName, self.lastSeqVal) self.assertEqual(row[self.colName], self.lastSeqVal) def tearDown(self): # Delete the record that was inserted. if self.lastSeqVal != None: self.deleter.deleteRecord(self.conn, self.tableName, self.colName, self.lastSeqVal) self.connector.closeDB(self.conn)
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)
class TestMECODBInserter(unittest.TestCase): """ Unit tests for the MECO XML Parser. """ def setUp(self): self.i = MECODBInserter() self.util = MSGDBUtil() self.connector = MSGDBConnector(True) self.deleter = MECODBDeleter() self.reader = MECODBReader() self.lastSeqVal = None self.conn = self.connector.connectDB() self.sampleTableName = 'MeterData' self.sampleDict = {'MeterName': '100001', 'UtilDeviceID': '100001', 'MacID': '00:00:00:00:00:00:00:00'} self.keyName = 'meter_data_id' def testMECODBInserterCanBeInited(self): localInserter = MECODBInserter() self.assertIsInstance(self.i, type(localInserter)) def testInsertionToMeterDataTable(self): """ Data can be written to the Meter Data table. """ # Insert some values. self.i.insertData(self.conn, self.sampleTableName, self.sampleDict) # Retrieve the last fetched value. self.lastSeqVal = self.util.getLastSequenceID(self.conn, self.sampleTableName, self.keyName) print "lastSeqVal = %s" % self.lastSeqVal row = self.reader.selectRecord(self.conn, self.sampleTableName, self.keyName, self.lastSeqVal) self.assertEqual(row[self.keyName], self.lastSeqVal) def test_fkey_value_is_correct(self): """ Verify that the fkey value used during insertion is correct. """ def testInsertionsSums(self): """ """ pass def tearDown(self): # Delete the record that was inserted. if self.lastSeqVal != None: self.deleter.deleteRecord(self.conn, self.sampleTableName, self.keyName, self.lastSeqVal) self.connector.closeDB(self.conn)