def test_bad_header(): # Exercise the code path that results in a 'badly formatted header' # in this case it works by inserting three run stops # one comes from the temperature_ramp.run() command # then two more come from stop1 and stop2 start = insert_run_start(time=ttime.time(), scan_id=8985, owner='docbrown', beamline_id='example', beamline_config=insert_beamline_config({}, time=0.)) ev = temperature_ramp.run(start) stop1 = insert_run_stop(start, time=ttime.time()) stop2 = insert_run_stop(start, time=ttime.time()) hdr = db[-1]
def mock_run_start(run_start_uid=None, sleep=0, make_run_stop=True): if run_start_uid is None: blc_uid = insert_beamline_config({}, time=get_time()) run_start_uid = insert_run_start(time=get_time(), scan_id=1, beamline_id='example', uid=str(uuid.uuid4()), beamline_config=blc_uid) # these events are already the sanitized version, not raw mongo objects events = func(run_start_uid, sleep) # Infer the end run time from events, since all the times are # simulated and not necessarily based on the current time. time = max([event['time'] for event in events]) if make_run_stop: run_stop_uid = insert_run_stop(run_start_uid, time=get_time(), exit_status='success') run_stop, = find_run_stops(uid=run_stop_uid) return events
def mock_run_start(run_start_uid=None, sleep=0, make_run_stop=True): if run_start_uid is None: run_start_uid = insert_run_start(time=get_time(), scan_id=1, beamline_id='example', uid=str(uuid.uuid4())) # these events are already the sanitized version, not raw mongo objects events = func(run_start_uid, sleep) # Infer the end run time from events, since all the times are # simulated and not necessarily based on the current time. time = max([event['time'] for event in events]) if make_run_stop: run_stop_uid = insert_run_stop(run_start_uid, time=time, exit_status='success', uid=str(uuid.uuid4())) run_stop, = find_run_stops(uid=run_stop_uid) return events
func = np.cos num = 1000 start = 0 stop = 10 sleep_time = .1 for idx, i in enumerate(np.linspace(start, stop, num)): data = { 'linear_motor': i, 'Tsam': i + 5, 'scalar_detector': func(i) + np.random.randn() / 100 } ts = {k: time.time() for k in data} e = insert_event(descriptor=descriptor, seq_num=idx, time=time.time(), timestamps=ts, data=data, uid=str(uuid.uuid4())) insert_run_stop(run_start, time=time.time(), uid=str(uuid.uuid4())) last_run = next(find_last()) try: if str(last_run.uid) != str(run_start): print("find_last() is broken") except AttributeError as ae: print(ae) res_2 = find_events(descriptor=descriptor) if not res_2: print("find_events() is broken")
uid=br["uid"], ) event_descs = db.event_descriptor.find({"begin_run_id": br["_id"]}) max_time = 0.0 for e_desc in event_descs: the_e_desc = insert_event_descriptor( run_start=the_run_start, data_keys=e_desc["data_keys"], time=e_desc["time"], uid=e_desc["uid"] ) events = db.event.find({"descriptor_id": e_desc["_id"]}) for ev in events: if ev["time"] > max_time: max_time = ev["time"] insert_event( event_descriptor=the_e_desc, time=ev["time"], data=ev["data"], seq_num=ev["seq_num"], uid=ev["uid"] ) insert_run_stop(run_start=the_run_start, time=float(max_time), exit_status="success", reason=None, uid=None) run_start_mapping = dict() run_starts = db.run_start.find() for rs in run_starts: time = rs.pop("time") beamline_id = rs.pop("beamline_id") bcfg_id = beamline_cfg_mapping[rs.pop("beamline_config_id")] owner = rs.pop("owner") scan_id = rs.pop("scan_id") uid = rs.pop("uid") trashed = rs.pop("time_as_datetime") my_run_start = insert_run_start( time=time, beamline_id=beamline_id, beamline_config=bcfg_id, owner=owner, scan_id=scan_id, uid=uid ) run_start_mapping[rs["_id"]] = my_run_start
def define_parser(): parser = argparse.ArgumentParser(description='Launch a data viewer') parser.add_argument('time', nargs='?', default=0, help="Sleep duration between scan steps") return parser if __name__ == '__main__': parser = define_parser() args = parser.parse_args() sleep_time = float(args.time) try: last_start_event = next(find_last()) scan_id = int(last_start_event.scan_id)+1 except IndexError: scan_id = 1 scan_id = str(scan_id) custom = {'plotx': 'linear_motor', 'ploty': ['total_img_sum'], 'moon': 'full'} # insert the run start run_start_uid = insert_run_start(scan_id=scan_id, time=ttime.time(), beamline_id='csx', custom=custom, uid=str(uuid.uuid4())) events = run(run_start_uid=run_start_uid, sleep=sleep_time, make_run_stop=False) run_stop = insert_run_stop(run_start=run_start_uid, time=ttime.time(), reason='run completed', exit_status='success', uid=str(uuid.uuid4()))
# keys and serves as header for set of Event(s) descriptor = insert_descriptor(data_keys=data_keys, time=time.time(), run_start=run_start, uid=str(uuid.uuid4())) func = np.cos num = 1000 start = 0 stop = 10 sleep_time = .1 for idx, i in enumerate(np.linspace(start, stop, num)): data = {'linear_motor': i, 'Tsam': i + 5, 'scalar_detector': func(i) + np.random.randn() / 100} ts = {k: time.time() for k in data} e = insert_event(descriptor=descriptor, seq_num=idx, time=time.time(), timestamps=ts, data=data, uid=str(uuid.uuid4())) insert_run_stop(run_start, time=time.time(), uid=str(uuid.uuid4())) last_run = next(find_last()) try: if str(last_run.uid) != str(run_start): print("find_last() is broken") except AttributeError as ae: print(ae) res_2 = find_events(descriptor=descriptor) if not res_2: print("find_events() is broken")
def _end_run(self, arg): state = arg.get('state', 'success') bre = arg['run_start'] mds.insert_run_stop(bre, time.time(), exit_status=state) self.logger.info('End Run...')
the_e_desc = insert_event_descriptor(run_start=the_run_start, data_keys=e_desc['data_keys'], time=e_desc['time'], uid=e_desc['uid']) events = db.event.find({'descriptor_id': e_desc['_id']}) for ev in events: if ev['time'] > max_time: max_time = ev['time'] insert_event(event_descriptor=the_e_desc, time=ev['time'], data=ev['data'], seq_num=ev['seq_num'], uid=ev['uid']) insert_run_stop(run_start=the_run_start, time=float(max_time), exit_status='success', reason=None, uid=None) run_start_mapping = dict() run_starts = db.run_start.find() for rs in run_starts: time = rs.pop('time') beamline_id = rs.pop('beamline_id') bcfg_id = beamline_cfg_mapping[rs.pop('beamline_config_id')] owner = rs.pop('owner') scan_id = rs.pop('scan_id') uid = rs.pop('uid') trashed = rs.pop('time_as_datetime') my_run_start = insert_run_start(time=time, beamline_id=beamline_id,