コード例 #1
0
ファイル: test_replay.py プロジェクト: NSLS-II/replay
def setup():
    mds_setup()
    fs_setup()
    # set up the temperature ramp events
    global hdr_temp_ramp, ev_temp_ramp
    temperature_ramp.run()
    hdr_temp_ramp = db[-1]
    ev_temp_ramp = db.fetch_events(hdr_temp_ramp)
    global hdr_img_scalar, ev_img_scalar
    image_and_scalar.run()
    hdr_img_scalar = db[-1]
    ev_img_scalar = db.fetch_events(hdr_img_scalar)
コード例 #2
0
ファイル: model.py プロジェクト: NSLS-II/replay
 def scan_id_changed(self, changed):
     self.headers = DataBroker.find_headers(scan_id=self.scan_id)
     self.search_info = "Requested scan id: {}. Found: {}".format(
         self.scan_id, len(self.headers))
コード例 #3
0
def blank_events(header):
    "Return a list of unfilled events."
    from dataportal.broker import DataBroker as db
    raw_events = list(db.fetch_events(header, fill=False))
    raw_events.reverse()
    return raw_events
コード例 #4
0
ファイル: model.py プロジェクト: licode/dataportal
def get_events(run_header):
    return DataBroker.fetch_events(run_header)
コード例 #5
0
ファイル: model.py プロジェクト: NSLS-II/replay
def get_events(run_header):
    return DataBroker.fetch_events(run_header)
コード例 #6
0
ファイル: test_replay.py プロジェクト: NSLS-II/replay
def test_replay_persistence():
    rs1 = mdsapi.insert_run_start(
        time=ttime.time(), beamline_id='replay testing', scan_id=1,
        beamline_config=mdsapi.insert_beamline_config({}, ttime.time()))
    events1 = temperature_ramp.run(rs1)
    rs2 = mdsapi.insert_run_start(
        time=ttime.time(), beamline_id='replay testing', scan_id=2,
        beamline_config=mdsapi.insert_beamline_config({}, ttime.time()))
    events2 = temperature_ramp.run(rs2)
    dbfile = os.path.join(tempfile.gettempdir(), str(uuid.uuid1()) + '.db')

    h = History(dbfile)
    # making sure that replay and the test suite are pointing at the same
    # sql db is good mmmmkay?
    replay.history = h

    # set up some state for the first run start
    scan_id1 = random.randint(50000, 10000000)
    hdr_update_rate1 = random.randint(50000, 10000000)
    num_to_retrieve1 = random.randint(10, 20)
    # store some state
    state1 = {'x': 'Tsam', 'y': ['Tsam', 'point_det'], 'x_is_index': True}
    h.put(six.text_type(rs1.uid), state1)
    returned_state = h.get(six.text_type(rs1.uid))
    h.put('WatchForHeadersModel', {'update_rate': hdr_update_rate1})
    h.put('ScanIDSearchModel', {'scan_id': scan_id1})
    h.put('GetLastModel', {'num_to_retrieve': num_to_retrieve1})
    # store some more state
    h.put(six.text_type(rs2.uid), {'y': ['Tsam', 'point_det'],
                                  'x_is_index': True})

    # open up replay
    app = QtApplication()
    ui = replay.create(replay.define_live_params())
    ui.title = ('Testing replay by manually triggering various models. '
                'Sit back and enjoy the show!')
    ui.show()
    hdr1 = db.find_headers(uid=rs1.uid)[0]
    ui.muxer_model.header = hdr1
    # start replay so that it will stop in 4 seconds
    app.timed_call(4000, app.stop)
    app.start()

    try:
        # check that the observer between the muxer model and the scalar collection
        # is working properly
        assert (six.text_type(ui.scalar_collection.dataframe_uid) ==
                six.text_type(rs1.uid))
        # check that the scalar collection is correctly loading plotting state
        assert ui.scalar_collection.x == state1['x']
        # check that the scalar collection is correctly loading plotting state
        assert ui.scalar_collection.x_is_index == state1['x_is_index']
        y_matches = True
        for y in ui.scalar_collection.y:
            if y not in state1['y']:
                y_matches = False
        # make sure that the datasets that should be plotted are plotting
        assert y_matches
        # make sure that no extra datasets are plotting
        assert len(ui.scalar_collection.y) == len(state1['y'])
        # check state in the "live" mode
        assert ui.watch_headers_model.update_rate == hdr_update_rate1
        # check state loading in the search by scan_id model
        assert ui.scan_id_model.scan_id == scan_id1
        # check state loading in the get_last_model
        assert ui.get_last_model.num_to_retrieve == num_to_retrieve1
    except AssertionError:
        # make sure the app gets destroyed, even if there is an AssertionError
        # as this will cause problems later
        ui.close()
        app.destroy()
        raise

    # store some state for the 2nd header that differs from the first
    state2 = {'x': 'point_det', 'y': ['Tsam'], 'x_is_index': False}
    h.put(six.text_type(rs2.uid), state2)
    hdr2 = db.find_headers(_id=rs2.uid)[0]
    ui.muxer_model.header = hdr2


    # make sure that the things that are display are the things that we think
    # should be displayed. This requires starting/stopping replay
    app.timed_call(4000, app.stop)
    app.start()
    try:
        # check that the observer between the muxer model and the scalar collection
        # is working properly
        assert six.text_type(ui.scalar_collection.dataframe_uid) == six.text_type(rs2.uid)
        # check that the scalar collection is correctly loading plotting state
        assert ui.scalar_collection.x == state2['x']
        # check that the scalar collection is correctly loading plotting state
        assert ui.scalar_collection.x_is_index == state2['x_is_index']
        # check that the scalar collection is correctly loading plotting state
        for y in ui.scalar_collection.y:
            if y not in state2['y']:
                y_matches = False
        # make sure that the datasets that should be plotted are plotting
        assert y_matches
        # make sure that no extra datasets are plotting
        assert len(ui.scalar_collection.y) == len(state2['y'])
    except AssertionError:
        # make sure the app gets destroyed, even if there is an AssertionError
        # as this will cause problems later
        ui.close()
        app.destroy()
        raise

    def use_ram_state():
        # now set the plot state to be 'ram'
        ui.scalar_collection.use_ram_state = True
    app.timed_call(500, use_ram_state)
    app.timed_call(1000, app.stop)
    app.start()
    # make sure that it updated the disk state correctly and that no unexpected
    # updates happened
    assert ui.scalar_collection.use_disk_state == False
    assert ui.scalar_collection.use_ram_state == True

    # change the header back to the first header
    ui.muxer_model.header = hdr1
    # start/stop replay again
    app.timed_call(1000, app.stop)
    app.start()

    # make sure that the updates triggered correctly. It should now match the
    # state from the second run header
    try:
        # check that the observer between the muxer model and the scalar collection
        # is working properly
        assert six.text_type(ui.scalar_collection.dataframe_uid) == six.text_type(rs1.uid)
        # check that the scalar collection is correctly loading plotting state
        assert ui.scalar_collection.x == state2['x']
        # check that the scalar collection is correctly loading plotting state
        assert ui.scalar_collection.x_is_index == state2['x_is_index']
        # check that the scalar collection is correctly loading plotting state
        for y in ui.scalar_collection.y:
            if y not in state2['y']:
                y_matches = False
        # make sure that the datasets that should be plotted are plotting
        assert y_matches
        # make sure that no extra datasets are plotting
        assert len(ui.scalar_collection.y) == len(state2['y'])
    except AssertionError:
        # make sure the app gets destroyed, even if there is an AssertionError
        # as this will cause problems later
        ui.close()
        app.destroy()
        raise

    def use_disk_state():
        # now set the plot state to be 'ram'
        ui.scalar_collection.use_disk_state = True
    ui.scalar_collection.use_disk_state = True
    # make sure that the switch took place
    app.timed_call(500, use_disk_state)
    app.timed_call(1000, app.stop)
    app.start()
    # make sure that it updated the disk state correctly and that no unexpected
    # updates happened
    assert ui.scalar_collection.use_disk_state == True
    assert ui.scalar_collection.use_ram_state == False

    # the original state for run header 2 is now the state for run header 2.
    # Let's change the state for run header 2 on disk and switch back.
    h.put(six.text_type(rs2.uid), state1)
    ui.muxer_model.header = hdr2
    app.timed_call(1000, app.stop)
    app.start()    # make sure that the things that are display are the things that we think
    # should be displayed. This requires starting/stopping replay
    try:
        # check that the observer between the muxer model and the scalar collection
        # is working properly
        assert six.text_type(ui.scalar_collection.dataframe_uid) == six.text_type(rs2.uid)
        # check that the scalar collection is correctly loading plotting state
        assert ui.scalar_collection.x == state1['x']
        # check that the scalar collection is correctly loading plotting state
        assert ui.scalar_collection.x_is_index == state1['x_is_index']
        # check that the scalar collection is correctly loading plotting state
        for y in ui.scalar_collection.y:
            if y not in state1['y']:
                y_matches = False
        # make sure that the datasets that should be plotted are plotting
        assert y_matches
        # make sure that no extra datasets are plotting
        assert len(ui.scalar_collection.y) == len(state1['y'])
    except AssertionError:
        # make sure the app gets destroyed, even if there is an AssertionError
        # as this will cause problems later
        ui.close()
        app.destroy()
        raise

    ui.close()
    app.destroy()
コード例 #7
0
def blank_events(header):
    "Return a list of unfilled events."
    from dataportal.broker import DataBroker as db
    raw_events = list(db.fetch_events(header, fill=False))
    raw_events.reverse()
    return raw_events