-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
listruns(): use databroker v2 API #332
Comments
This means we need to learn how to manage multiple catalog names. |
This short program demonstrates the lookup process: program source#!/usr/bin/env python
from apstools.utils import listruns
from databroker import catalog
from databroker.queries import TimeRange
import datetime
import pyRestTable
import time
def ts2dt(timestamp):
return datetime.datetime.fromtimestamp(timestamp)
def lookup_catalog(*args,
cat=None,
since=None,
until=None,
**query):
"""
look for runs in the given catalog, limited by search terms
The basic search::
results.search({'num_points': {'$gt': 50}})
results.search(plan_name={"$in": ["scan", "count"]})
For more complex queries, see
https://blueskyproject.io/databroker/v2/user/index.html#search-for-runs
and additional mongo query terms at
https://docs.mongodb.com/v3.2/reference/operator/query/#query-selectors
"""
if cat is None:
raise ValueError("must provide a catalog to search")
elif len(cat) == 0:
raise ValueError("empty catalog")
since = since or "1980" # before the APS
until = until or "2200" # after a long time from now
cat = cat.search(TimeRange(since=since, until=until))
if len(cat) == 0:
raise ValueError(
f"no runs start between dates {since} <= run < {until}")
cat = cat.search(query)
if len(cat) == 0:
raise ValueError(f"no runs matching search terms {query}")
return cat
def main():
for cat_name in list(catalog):
print(f"catalog '{cat_name}' : {len(catalog[cat_name])} run(s)")
findings = lookup_catalog(
cat=catalog["mongodb_config"],
# scan_id=1,
plan_name={"$in": ["scan", "count"]},
until="2020-05",
)
print(f"found {len(findings)} run(s)")
quantity = 20
table = pyRestTable.Table()
table.labels = "# run_id plan start_time end_time".split()
for i, item in enumerate(findings.items()):
if i >= quantity:
break
uid, run = item
plan = run.metadata["start"]["plan_name"]
t_start = ts2dt(run.metadata["start"]["time"])
t_stop = ts2dt(run.metadata["stop"]["time"])
table.addRow((i+1, uid[:7], plan, t_start, t_stop))
print(table)
if __name__ == "__main__":
t0 = time.time()
main()
print(f"completed in {time.time()-t0:.03f}s") program output
|
The current |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
listruns()
utility function uses the databroker v0 and v1 API. Time to upgrade that to the v2 API AND upgrade the search capabilities.This continues the maintenance of #330.
The text was updated successfully, but these errors were encountered: