|
1 | | -#import json |
2 | | -#import logging |
3 | | -#import os |
4 | | -#import sys |
5 | | -#import time |
6 | | -#import pytest |
7 | | -#from datetime import datetime, timezone |
| 1 | +import json |
| 2 | +import logging |
| 3 | +import os |
| 4 | +import sys |
| 5 | +import time |
| 6 | +import pytest |
| 7 | +from datetime import datetime, timezone |
8 | 8 |
|
9 | | -#logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) |
| 9 | +logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) |
10 | 10 |
|
11 | | -#from gridappsd import GridAPPSD, topics as t |
12 | | -#from gridappsd.simulation import Simulation, PowerSystemConfig, SimulationArgs, SimulationConfig |
| 11 | +from gridappsd import GridAPPSD, topics as t |
| 12 | +from gridappsd.simulation import Simulation, PowerSystemConfig, SimulationArgs, SimulationConfig |
13 | 13 |
|
14 | | -#simulation_is_complete = False |
15 | | -#measurements_received = 0 |
| 14 | +simulation_is_complete = False |
| 15 | +measurements_received = 0 |
16 | 16 |
|
17 | | -#@pytest.fixture |
18 | | -#def createGadObject(): |
19 | | -# gad_user = os.environ.get('GRIDAPPSD_USER') |
20 | | -# if gad_user is None: |
21 | | -# os.environ['GRIDAPPSD_USER'] = 'system' |
22 | | -# gad_password = os.environ.get('GRIDAPPSD_PASSWORD') |
23 | | -# if gad_password is None: |
24 | | -# os.environ['GRIDAPPSD_PASSWORD'] = 'manager' |
25 | | -# return GridAPPSD() |
| 17 | +@pytest.fixture |
| 18 | +def createGadObject(): |
| 19 | + gad_user = os.environ.get('GRIDAPPSD_USER') |
| 20 | + if gad_user is None: |
| 21 | + os.environ['GRIDAPPSD_USER'] = 'system' |
| 22 | + gad_password = os.environ.get('GRIDAPPSD_PASSWORD') |
| 23 | + if gad_password is None: |
| 24 | + os.environ['GRIDAPPSD_PASSWORD'] = 'manager' |
| 25 | + return GridAPPSD() |
26 | 26 |
|
27 | | -#def test_createSimulations(createGadObject): |
28 | | -# gadObj = createGadObject |
29 | | -# response = gadObj.query_model_info() |
30 | | -# models = response.get("data", {}).get("models", {}) |
31 | | -# start_time = int(datetime(year=2025, month=1, day=1, hour=0, minute=0, second=0, microsecond=0, tzinfo=timezone.utc).timestamp()) |
32 | | -# simulationArgs = SimulationArgs(start_time=f"{start_time}", |
33 | | -# duration="120", |
34 | | -# run_realtime=False, |
35 | | -# pause_after_measurements=False) |
36 | | -# sim_config = SimulationConfig(simulation_config=simulationArgs) |
37 | | -# modelsToRun = [ |
38 | | -# "49AD8E07-3BF9-A4E2-CB8F-C3722F837B62", # IEEE 13 Node Test Feeder |
39 | | -# "C1C3E687-6FFD-C753-582B-632A27E28507" # IEEE 123 Node Test Feeder |
40 | | -# ] |
41 | | -# for m in models: |
42 | | -# if m.get("modelId") not in modelsToRun: |
43 | | -# continue |
44 | | -# line_name = m.get("modelId") |
45 | | -# subregion_name = m.get("subRegionId") |
46 | | -# region_name = m.get("regionId") |
47 | | -# psc = PowerSystemConfig(Line_name=line_name, |
48 | | -# SubGeographicalRegion_name=subregion_name, |
49 | | -# GeographicalRegion_name=region_name) |
50 | | -# sim_config.power_system_configs.append(psc) |
51 | | -# sim_obj = Simulation(gapps=gadObj, run_config=sim_config) |
52 | | -# def on_measurement(sim, ts, m): |
53 | | -# global measurements_received |
54 | | -# measurements_received += 1 |
55 | | -# def on_simulation_complete(sim): |
56 | | -# global simulation_is_complete |
57 | | -# simulation_is_complete = True |
58 | | -# sim_obj.add_onmeasurement_callback(on_measurement) |
59 | | -# sim_obj.add_oncomplete_callback(on_simulation_complete) |
60 | | -# sim_obj.start_simulation() |
61 | | -# while not simulation_is_complete: |
62 | | -# time.sleep(1) |
63 | | -# assert measurements_received == 1 |
64 | | -# gadObj.disconnect() |
| 27 | +def test_createSimulations(createGadObject): |
| 28 | + gadObj = createGadObject |
| 29 | + response = gadObj.query_model_info() |
| 30 | + models = response.get("data", {}).get("models", {}) |
| 31 | + start_time = int(datetime(year=2025, month=1, day=1, hour=0, minute=0, second=0, microsecond=0, tzinfo=timezone.utc).timestamp()) |
| 32 | + simulationArgs = SimulationArgs(start_time=f"{start_time}", |
| 33 | + duration="120", |
| 34 | + run_realtime=False, |
| 35 | + pause_after_measurements=False) |
| 36 | + sim_config = SimulationConfig(simulation_config=simulationArgs) |
| 37 | + modelsToRun = [ |
| 38 | + "49AD8E07-3BF9-A4E2-CB8F-C3722F837B62", # IEEE 13 Node Test Feeder |
| 39 | + "C1C3E687-6FFD-C753-582B-632A27E28507" # IEEE 123 Node Test Feeder |
| 40 | + ] |
| 41 | + for m in models: |
| 42 | + if m.get("modelId") not in modelsToRun: |
| 43 | + continue |
| 44 | + line_name = m.get("modelId") |
| 45 | + subregion_name = m.get("subRegionId") |
| 46 | + region_name = m.get("regionId") |
| 47 | + psc = PowerSystemConfig(Line_name=line_name, |
| 48 | + SubGeographicalRegion_name=subregion_name, |
| 49 | + GeographicalRegion_name=region_name) |
| 50 | + sim_config.power_system_configs.append(psc) |
| 51 | + sim_obj = Simulation(gapps=gadObj, run_config=sim_config) |
| 52 | + def on_measurement(sim, ts, m): |
| 53 | + global measurements_received |
| 54 | + measurements_received += 1 |
| 55 | + def on_simulation_complete(sim): |
| 56 | + global simulation_is_complete |
| 57 | + simulation_is_complete = True |
| 58 | + sim_obj.add_onmeasurement_callback(on_measurement) |
| 59 | + sim_obj.add_oncomplete_callback(on_simulation_complete) |
| 60 | + sim_obj.start_simulation() |
| 61 | + while not simulation_is_complete: |
| 62 | + time.sleep(1) |
| 63 | + assert measurements_received == 1 |
| 64 | + gadObj.disconnect() |
0 commit comments