bluesky / databroker-pack

Pack and unpack Bluesky Runs to/from a portable storage format.
http://blueskyproject.io/databroker-pack
BSD 3-Clause "New" or "Revised" License
3 stars 9 forks source link

Add support for --filter via Python lambda #20

Open danielballan opened 4 years ago

danielballan commented 4 years ago

It would be useful to be able to filter Runs at the Python layer. The --query argument already allows them to be filter at the MongoDB layer, but Python gives us access to more things and is of course more expressive (though more expensive). I have in mind things like

databroker-pack ... --filter "lambda run: run.metadata['stop'] == 'success'"
databroker-pack ... --filter "lambda run: run.primary.read()['motor'].max() < 5"

Multiple --filter parameters should be allowed, using argparse's action='append', and they should be logically AND-ed just as --query is. (Why not OR? Because OR will will be less common, and if needed it can be implemented inside one lambda.)