Exemplo n.º 1
0
def test_simulation_no_duplicate_measurement_timestamps(
        gridappsd_client: GridAPPSD):
    num_measurements = 0
    timestamps = set()

    def measurement(sim, timestamp, measurement):
        nonlocal num_measurements
        num_measurements += 1
        assert timestamp not in timestamps
        timestamps.add(timestamp)

    gapps = gridappsd_client
    sim = Simulation(gapps, base_config())
    sim.add_onmeasurement_callback(measurement)
    sim.start_simulation()
    sim.run_loop()

    # did we get a measurement?
    assert num_measurements > 0

    # if empty then we know the simulation did not work.
    assert timestamps
Exemplo n.º 2
0
    timestamp = message['message']['timestamp']
    _log.info("{timestamp} simulation publish number: {sim_publish_number} timestamp: {timestamp}".format(timestamp=timestamp,
                                                                                                          sim_publish_number=sim_publish_number))
    # print('SIMULATED MESSAGE IS HERE!')
    # measurements = message['message']['measurements']
    # timestamp = message['message']['timestamp']
    # for k, v in measurements.items():
    #
    #     v['timestamp'] = timestamp
    #     # v['class'] = sensor_test[k]['class']
    #     # v['type'] = sensor_test[k]['type']
    #     sim_output.append(v)


sim.add_onstart_callback(onstart)
sim.add_onmeasurement_callback(onmeasurment)
sim.add_ontimestep_callback(ontimestep)
sim.add_oncomplete_callback(onfinishsimulation)
sim.start_simulation()
read_topic = t.service_output_topic("gridappsd-sensor-simulator", sim.simulation_id)
_log.debug("Reading topic for sensor output {read_topic}".format(read_topic=read_topic))
gapps.subscribe(read_topic, on_simulated_output)

try:

    while True:
        if sim_complete:
            # print("sim output")
            # pprint(sim_output)
            break
        sleep(0.1)