def test_multi_properties(self): '''Tests related to properties with a list of values ''' filename = 'coad/test/RTS-96.xml' coad = COAD(filename) # Get properties g = coad['Generator']['101-1'] props = { 'Mean Time to Repair': '50', 'Load Point': ['15.8', '16', '19.8', '20'], 'Heat Rate': ['15063', '15000', '14500', '14499'], 'Min Up Time': '1', 'Max Ramp Up': '3', 'Min Down Time': '1', 'Min Stable Level': '15.8', 'Units': '1', 'Start Cost Time': ['0', '1'], 'Maintenance Frequency': '2', 'Maintenance Rate': '3.84', 'Max Capacity': '20', 'Forced Outage Rate': '10' } self.assertEqual(g.get_properties()['System.System'], props) # Get property self.assertEqual(g.get_property('Load Point'), ['15.8', '16', '19.8', '20']) # Set property g.set_property('Load Point', ['a', 'b', 'c', 'd']) self.assertEqual(g.get_property('Load Point'), ['a', 'b', 'c', 'd']) # Set property with wrong length with self.assertRaises(Exception): g.set_property('Load Point', ['a', 'b', 'c']) # Set properties new_props = { 'Maintenance Rate': 'aaaa', 'Heat Rate': ['bbbb', 'cccc', 'dddd', 'eeee'] } g2 = coad['Generator']['123-3'] g2.set_properties(new_props) # Test save and load coad.save('coad/test/RTS-96_props_test.xml') saved_coad = COAD('coad/test/RTS-96_props_test.xml') props['Load Point'] = ['a', 'b', 'c', 'd'] g = saved_coad['Generator']['101-1'] self.assertEqual(g.get_properties()['System.System'], props) g2 = saved_coad['Generator']['123-3'] self.assertEqual(g2.get_property('Maintenance Rate'), new_props['Maintenance Rate']) self.assertEqual(g2.get_property('Heat Rate'), new_props['Heat Rate'])
def test_blank_elements(self): '''Make sure blank elements are saved properly ''' filename = 'coad/test/118-Bus_with_blanks.xml' pre = COAD(filename) cur = pre.dbcon.execute( "SELECT name FROM category WHERE category_id=49") val = cur.fetchone()[0] self.assertEqual(val, "") pre.save('coad/test/118-Bus_with_blanks_test.xml') post = COAD('coad/test/118-Bus_with_blanks_test.xml') cur = post.dbcon.execute( "SELECT name FROM category WHERE category_id=49") val = cur.fetchone()[0] self.assertEqual(val, "")
def test_modify_single_tagged_properties(self): '''Tests related to modifying tagged properties with a single value ''' filename = 'coad/test/RTS-96.xml' coad = COAD(filename) self.assertEqual( coad['Generator']['118-1'].get_properties()['Scenario.RT_UC'], {'Commit': '0'}) coad['Generator']['118-1'].set_property('Commit', 'totally_committed', 'Scenario.RT_UC') # Test that dynamic and enabled flag is not set for Unit Commitment Optimality self.assertEqual( coad['Generator'].valid_properties['System']['12']['is_dynamic'], 'false') self.assertEqual( coad['Generator'].valid_properties['System']['12']['is_enabled'], 'false') self.assertRaises(Exception, coad['Generator']['118-1'].set_property, 'Unit Commitment Optimality', 'I hate input masks', 'Scenario.RT_UC') # Make sure invalid assignment does not trigger is_dynamic=true self.assertEqual( coad['Generator'].valid_properties['System']['12']['is_dynamic'], 'false') self.assertEqual( coad['Generator'].valid_properties['System']['12']['is_enabled'], 'false') # This tag isn't set at all coad['Generator']['118-1'].set_property('Unit Commitment Optimality', 'Rounded Relaxation', 'Scenario.RT_UC') self.assertEqual( coad['Generator'].valid_properties['System']['12']['is_dynamic'], 'true') self.assertEqual( coad['Generator'].valid_properties['System']['12']['is_enabled'], 'true') coad.save('coad/test/RTS-96_props_test.xml') saved_coad = COAD('coad/test/RTS-96_props_test.xml') expected = { 'Commit': 'totally_committed', 'Unit Commitment Optimality': 'Rounded Relaxation' } self.assertEqual( saved_coad['Generator']['118-1'].get_properties() ['Scenario.RT_UC'], expected)
def test_single_properties(self): '''Tests related to properties with a single value ''' filename = 'coad/test/118-Bus.xml' coad = COAD(filename) # Get properties line = coad['Line']['126'] props = { 'Reactance': '0.0202', 'Max Flow': '9900', 'Min Flow': '-9900', 'Resistance': '0.00175' } self.assertEqual(line.get_properties()['System.System'], props) # Get property self.assertEqual(line.get_property('Max Flow'), '9900') # Set property line.set_property('Min Flow', '123456') self.assertEqual(line.get_property('Min Flow'), '123456') # Set properties new_props = { 'Reactance': 'aaaa', 'Max Flow': 'bbbb', 'Min Flow': 'cccc', 'Resistance': 'dddd' } line_a = coad['Line']['027'] line_a.set_properties(new_props) # Test save and load coad.save('coad/test/118-Bus_props_test.xml') solar = COAD('coad/test/118-Bus_props_test.xml') props['Min Flow'] = '123456' line = solar['Line']['126'] self.assertEqual(line.get_properties()['System.System'], props) line_a = coad['Line']['027'] self.assertEqual(line_a.get_properties()['System.System'], new_props)
import datetime from coad.COAD import COAD from coad.ModelUtil import datetime_to_plex coad = COAD('RTS-GMLC.xml') #7/14/2024 date_start = str(datetime_to_plex(datetime.datetime(2024, 7, 14, 0, 0))) new_horizon = coad['Horizon']['Base'].copy("Interesting Week") new_horizon["Step Count"] = "8" new_horizon["Date From"] = date_start new_horizon["Chrono Date From"] = date_start new_horizon["Chrono Step Count"] = "8" coad['Model']['DAY_AHEAD'].set_children(new_horizon) coad.save("one_week_model.xml")