コード例 #1
0
ファイル: test_commands.py プロジェクト: licode/metadatastore
def test_custom_warn():

    run_start_uid = str(uuid.uuid4())

    warnings.simplefilter('always', UserWarning)
    with warnings.catch_warnings(record=True) as w:
        run_start_uid = mdsc.insert_run_start(
            scan_id=30220, beamline_id='testbed',
            owner='Al the Aardvark', group='Orycteropus',
            project='Nikea', time=document_insertion_time,
            uid=run_start_uid, custom={'order': 'Tubulidentata'})
        assert len(w) == 1

    rs = next(mdsc.find_run_starts(order='Tubulidentata'))
    assert rs['uid'] == run_start_uid

    with warnings.catch_warnings(record=True) as w:
        ev_desc_uid = mdsc.insert_descriptor(
            run_start_uid,
            {'a': {'source': 'zoo', 'shape': [], 'dtype': 'number'}},
            ttime.time(), str(uuid.uuid4()), custom={'food': 'ants'})

        assert len(w) == 1
    ed = mdsc.descriptor_given_uid(ev_desc_uid)
    assert ed['food'] == 'ants'

    with warnings.catch_warnings(record=True) as w:
        stop_uid = str(uuid.uuid4())
        mdsc.insert_run_stop(run_start_uid, ttime.time(),
                             stop_uid, custom={'navy': 'VF-114'})

        assert len(w) == 1

    run_stop = mdsc.run_stop_given_uid(stop_uid)
    assert run_stop['navy'] == 'VF-114'
コード例 #2
0
ファイル: test_commands.py プロジェクト: licode/metadatastore
def test_find_run_start():
    run_start_uid, e_desc_uid, data_keys = setup_syn()
    mdsc.insert_run_stop(run_start_uid, ttime.time(), uid=str(uuid.uuid4()))

    run_start = mdsc.run_start_given_uid(run_start_uid)

    run_start2, = list(mdsc.find_run_starts(uid=run_start_uid))

    assert run_start == run_start2
コード例 #3
0
def test_find_run_start():
    run_start_uid, e_desc_uid, data_keys = setup_syn()
    mdsc.insert_run_stop(run_start_uid, ttime.time(), uid=str(uuid.uuid4()))

    run_start = mdsc.run_start_given_uid(run_start_uid)

    run_start2, = list(mdsc.find_run_starts(uid=run_start_uid))

    assert_equal(run_start, run_start2)
コード例 #4
0
ファイル: broker_callbacks.py プロジェクト: klauer/bluesky
 def f(name, stop_doc):
     uid = stop_doc['run_start']
     start, = find_run_starts(uid=uid)
     descriptors = find_event_descriptors(run_start=uid)
     # For convenience, I'll rely on the broker to get Events.
     header = db[uid]
     events = db.fetch_events(header)
     callback.start(start)
     for d in descriptors:
         callback.descriptor(d)
     for e in events:
         callback.event(e)
     callback.stop(stop_doc)
コード例 #5
0
ファイル: test_commands.py プロジェクト: licode/metadatastore
def test_insert_run_start():
    time = ttime.time()
    beamline_id = 'sample_beamline'
    scan_id = 42
    custom = {'foo': 'bar', 'baz': 42,
              'aardvark': ['ants', 3.14]}
    run_start_uid = mdsc.insert_run_start(
        time, beamline_id=beamline_id,
        scan_id=scan_id, uid=str(uuid.uuid4()), **custom)

    run_start_mds, = mdsc.find_run_starts(uid=run_start_uid)

    names = ['time', 'beamline_id', 'scan_id'] + list(custom.keys())
    values = [time, beamline_id, scan_id] + list(custom.values())

    for name, val in zip(names, values):
        assert getattr(run_start_mds, name) == val

    # make sure the metadatstore document raises properly
    check_for_id(run_start_mds)
コード例 #6
0
def test_insert_run_start():
    time = ttime.time()
    beamline_id = 'sample_beamline'
    scan_id = 42
    custom = {'foo': 'bar', 'baz': 42,
              'aardvark': ['ants', 3.14]}
    run_start_uid = mdsc.insert_run_start(
        time, beamline_id=beamline_id,
        scan_id=scan_id, custom=custom, uid=str(uuid.uuid4()))

    run_start_mds, = mdsc.find_run_starts(uid=run_start_uid)

    names = ['time', 'beamline_id', 'scan_id'] + list(custom.keys())
    values = [time, beamline_id, scan_id] + list(custom.values())

    for name, val in zip(names, values):
        assert_equal(getattr(run_start_mds, name), val)

    # make sure the metadatstore document raises properly
    check_for_id(run_start_mds)
コード例 #7
0
ファイル: test_commands.py プロジェクト: shengb/metadatastore
def test_find_funcs_for_smoke():
    """ Exercise documented kwargs in the find_* functions
    """
    rs, = mdsc.find_run_starts(uid=run_start_uid)
    test_dict = {
        mdsc.find_run_starts: [
            {'limit': 5},
            {'start_time': ttime.time()},
            {'start_time': '2015'},
            {'start_time': '2015-03-30'},
            {'start_time': '2015-03-30 03:00:00'},
            {'start_time': datetime.datetime.now()},
            {'stop_time': ttime.time()},
            {'start_time': ttime.time() - 1, 'stop_time': ttime.time()},
            {'beamline_id': 'csx'},
            {'project': 'world-domination'},
            {'owner': 'drdrake'},
            {'scan_id': 1},
            {'uid': run_start_uid}],
        mdsc.find_run_stops: [
            {'start_time': ttime.time()},
            {'stop_time': ttime.time()},
            {'start_time': ttime.time()-1, 'stop_time': ttime.time()},
            {'reason': 'whimsy'},
            {'exit_status': 'success'},
            {'uid': 'foo'}],
        mdsc.find_event_descriptors: [
            {'run_start': rs},
            {'run_start_uid': rs.uid},
            {'start_time': ttime.time()},
            {'stop_time': ttime.time()},
            {'start_time': ttime.time() - 1, 'stop_time': ttime.time()},
            {'uid': 'foo'}],
        mdsc.find_run_stops: [
            {'run_start': rs},
            {'run_start_uid': rs.uid},
        ]
    }
    for func, list_o_dicts in test_dict.items():
        for dct in list_o_dicts:
            yield _find_helper, func, dct
コード例 #8
0
def test_find_funcs_for_smoke():
    """ Exercise documented kwargs in the find_* functions
    """
    rs, = mdsc.find_run_starts(uid=run_start_uid)
    test_dict = {
        mdsc.find_run_starts: [
            {'limit': 5},
            {'start_time': ttime.time()},
            {'start_time': '2015'},
            {'start_time': '2015-03-30'},
            {'start_time': '2015-03-30 03:00:00'},
            {'start_time': datetime.datetime.now()},
            {'stop_time': ttime.time()},
            {'start_time': ttime.time() - 1, 'stop_time': ttime.time()},
            {'beamline_id': 'csx'},
            {'project': 'world-domination'},
            {'owner': 'drdrake'},
            {'scan_id': 1},
            {'uid': run_start_uid}],
        mdsc.find_run_stops: [
            {'start_time': ttime.time()},
            {'stop_time': ttime.time()},
            {'start_time': ttime.time()-1, 'stop_time': ttime.time()},
            {'reason': 'whimsy'},
            {'exit_status': 'success'},
            {'uid': 'foo'}],
        mdsc.find_event_descriptors: [
            {'run_start': rs},
            {'run_start_uid': rs.uid},
            {'start_time': ttime.time()},
            {'stop_time': ttime.time()},
            {'start_time': ttime.time() - 1, 'stop_time': ttime.time()},
            {'uid': 'foo'}],
        mdsc.find_run_stops: [
            {'run_start': rs},
            {'run_start_uid': rs.uid},
        ]
    }
    for func, list_o_dicts in test_dict.items():
        for dct in list_o_dicts:
            yield _find_helper, func, dct
コード例 #9
0
ファイル: databroker.py プロジェクト: danielballan/databroker
    def __getitem__(self, key):
        """DWIM slicing

        Some more docs go here
        """
        if isinstance(key, slice):
            # Interpret key as a slice into previous scans.
            if key.start is not None and key.start > -1:
                raise ValueError("slice.start must be negative. You gave me "
                                 "key=%s The offending part is key.start=%s"
                                 % (key, key.start))
            if key.stop is not None and key.stop > 0:
                raise ValueError("slice.stop must be <= 0. You gave me key=%s. "
                                 "The offending part is key.stop = %s"
                                 % (key, key.stop))
            if key.stop is not None:
                stop = -key.stop
            else:
                stop = None
            if key.start is None:
                raise ValueError("slice.start cannot be None because we do not "
                                 "support slicing infinitely into the past; "
                                 "the size of the result is non-deterministic "
                                 "and could become too large.")
            start = -key.start
            result = list(find_last(start))[stop::key.step]
            header = [Header.from_run_start(h) for h in result]
        elif isinstance(key, int):
            if key > -1:
                # Interpret key as a scan_id.
                gen = find_run_starts(scan_id=key)
                try:
                    result = next(gen)  # most recent match
                except StopIteration:
                    raise ValueError("No such run found for key=%s which is "
                                     "being interpreted as a scan id." % key)
                header = Header.from_run_start(result)
            else:
                # Interpret key as the Nth last scan.
                gen = find_last(-key)
                for i in range(-key):
                    try:
                        result = next(gen)
                    except StopIteration:
                        raise IndexError(
                            "There are only {0} runs.".format(i))
                header = Header.from_run_start(result)
        elif isinstance(key, six.string_types):
            results = None
            if len(key) >= 36:
                # Interpret key as a uid (or the few several characters of one).
                logger.debug('Treating %s as a full uuid' % key)
                results = list(find_run_starts(uid=key))
                logger.debug('%s runs found for key=%s treated as a full uuid'
                             % (len(results), key))
            if not results == 0:
                # No dice? Try searching as if we have a partial uid.
                logger.debug('Treating %s as a partial uuid' % key)
                gen = find_run_starts(uid={'$regex': '{0}.*'.format(key)})
                results = list(gen)
            if not results:
                # Still no dice? Bail out.
                raise ValueError("No such run found for key=%s" % key)
            if len(results) > 1:
                raise ValueError("key=%s  matches %s runs. Provide "
                                 "more characters." % (key, len(results)))
            result, = results
            header = Header.from_run_start(result)
        elif isinstance(key, Iterable):
            # Interpret key as a list of several keys. If it is a string
            # we will never get this far.
            return [self.__getitem__(k) for k in key]
        else:
            raise ValueError("Must give an integer scan ID like [6], a slice "
                             "into past scans like [-5], [-5:], or [-5:-9:2], "
                             "a list like [1, 7, 13], a (partial) uid "
                             "like ['a23jslk'] or a full uid like "
                             "['f26efc1d-8263-46c8-a560-7bf73d2786e1'].")
        return header
コード例 #10
0
ファイル: databroker.py プロジェクト: danielballan/databroker
    def __call__(self, **kwargs):
        """Given search criteria, find Headers describing runs.

        This function returns a list of dictionary-like objects encapsulating
        the metadata for a run -- start time, instruments used, and so on.
        In addition to the Parameters below, advanced users can specifiy
        arbitrary queries that are passed through to mongodb.

        Parameters
        ----------
        start_time : time-like, optional
            Include Headers for runs started after this time. Valid
            "time-like" representations are:
                - float timestamps (seconds since 1970), such as time.time()
                - '2015'
                - '2015-01'
                - '2015-01-30'
                - '2015-03-30 03:00:00'
                - Python datetime objects, such as datetime.datetime.now()
        stop_time: time-like, optional
            Include Headers for runs started before this time. See
            `start_time` above for examples.
        beamline_id : str, optional
            String identifier for a specific beamline
        project : str, optional
            Project name
        owner : str, optional
            The username of the logged-in user when the scan was performed
        scan_id : int, optional
            Integer scan identifier
        uid : str, optional
            Globally unique id string provided to metadatastore
        data_key : str, optional
            The alias (e.g., 'motor1') or PV identifier of data source

        Returns
        -------
        data : list
            Header objects

        Examples
        --------
        >>> DataBroker(start_time='2015-03-05', stop_time='2015-03-10')
        >>> DataBroker(data_key='motor1')
        >>> DataBroker(data_key='motor1', start_time='2015-03-05')
        """
        data_key = kwargs.pop('data_key', None)
        run_start = find_run_starts(**kwargs)
        if data_key is not None:
            node_name = 'data_keys.{0}'.format(data_key)

            query = {node_name: {'$exists': True}}
            descriptors = []
            for rs in run_start:
                descriptor = find_descriptors(run_start=rs, **query)
                for d in descriptor:
                    descriptors.append(d)
            # query = {node_name: {'$exists': True},
            #          'run_start_id': {'$in': [ObjectId(rs.id) for rs in run_start]}}
            # descriptors = find_descriptors(**query)
            result = []
            known_uids = deque()
            for descriptor in descriptors:
                if descriptor['run_start']['uid'] not in known_uids:
                    rs = descriptor['run_start']
                    known_uids.append(rs['uid'])
                    result.append(rs)
            run_start = result
        result = []
        for rs in run_start:
            result.append(Header.from_run_start(rs))
        return result