Пример #1
0
 def setUp(self):
     self.kWh = BaseUnit('kiloWatt hour', 'kWh')
     self.joule = Unit(self.kWh, 1.0/3600000.0, 'Joule', 'J')
     self.length = 10778
     dt = [datetime(2000, 1, 1) + timedelta(hours=i) for i in xrange(self.length)]
     self.val = np.random.normal(3600000.0, 360000.0, self.length)
     self.dataset = Dataset(dt, self.val, self.joule, 'energy')
Пример #2
0
class testDataset(unittest.TestCase):
    """A test class for the Dataset module"""
    
    def setUp(self):
        self.kWh = BaseUnit('kiloWatt hour', 'kWh')
        self.joule = Unit(self.kWh, 1.0/3600000.0, 'Joule', 'J')
        self.length = 10778
        dt = [datetime(2000, 1, 1) + timedelta(hours=i) for i in xrange(self.length)]
        self.val = np.random.normal(3600000.0, 360000.0, self.length)
        self.dataset = Dataset(dt, self.val, self.joule, 'energy')

    def testBasicAttributes(self):
        self.assertEqual(self.dataset.unit, self.kWh)
        assert_array_almost_equal(self.kWh.to_unit(self.dataset.data()['value'], self.joule), self.val)
        self.assertEqual(self.dataset.commodity, 'energy')

    def testInterpolation(self):
        original = self.dataset.data()
        hourly = self.dataset.data(resolution=60*60)
        self.assertEqual(len(hourly), len(original))
        self.assertEqual(len(hourly), self.length)