:py:mod:`obr.core.queries` ========================== .. py:module:: obr.core.queries Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: obr.core.queries.query_result obr.core.queries.Predicates obr.core.queries.Query Functions ~~~~~~~~~ .. autoapisummary:: obr.core.queries.input_to_query obr.core.queries.input_to_queries obr.core.queries.execute_query obr.core.queries.flatten_jobs obr.core.queries.query_flat_jobs obr.core.queries.query_to_dict obr.core.queries.query_impl obr.core.queries.query_to_records obr.core.queries.query_to_dataframe obr.core.queries.build_filter_query obr.core.queries.statepoint_get obr.core.queries.statepoint_query obr.core.queries.filter_jobs Attributes ~~~~~~~~~~ .. autoapisummary:: obr.core.queries.logger .. py:data:: logger .. py:class:: query_result .. py:attribute:: id :type: str .. py:attribute:: result :type: list[dict] .. py:attribute:: sub_keys :type: list[list[str]] .. py:method:: __repr__() -> str Return repr(self). .. py:class:: Predicates Bases: :py:obj:`enum.Enum` Generic enumeration. Derive from this class to define new enumerations. .. py:attribute:: eq :value: '==' .. py:attribute:: neq :value: '!=' .. py:attribute:: geq :value: '>=' .. py:attribute:: gt :value: '>' .. py:attribute:: leq :value: '<=' .. py:attribute:: lt :value: '<' .. py:class:: Query .. py:attribute:: key :type: str .. py:attribute:: value :type: Any .. py:attribute:: state :type: dict .. py:attribute:: predicate :type: str :value: 'eq' .. py:attribute:: sub_keys :type: list .. py:attribute:: negate :type: bool :value: False .. py:method:: execute(key, value) .. py:method:: match() .. py:method:: __repr__() -> str Return repr(self). .. py:function:: input_to_query(inp: str) -> Query converts cli input str to a Query object .. py:function:: input_to_queries(inp: str) -> list[Query] Convert a json string to list of queries .. py:function:: execute_query(query: Query, key, value, latest_only=True, track_keys=list) -> Query .. py:function:: flatten_jobs(jobs: Union[OpenFOAMProject, list[Job]]) -> dict convert a list of jobs to a dictionary .. py:function:: query_flat_jobs(jobs: dict[str, dict], queries: list[Query], output, latest_only, strict) -> list[query_result] Execute queries over a dictionary where the job.id is the key and merged job.docs are the values Parameters: jobs -- a job dictionary ordered by job ids queries -- list of queries to run output -- Whether to print result to screen latest_only -- Take only latest value if resulting value is a list strict -- needs all queries to be successful to return a result .. py:function:: query_to_dict(jobs: Union[OpenFOAMProject, list[Job]], queries: list[Query], output=False, latest_only=True, strict=False) -> list[query_result] Given a list jobs find all jobs for which a query matches Flattens list of jobs to a dictionary with merged statepoints and job document first .. py:function:: query_impl(jobs: Union[OpenFOAMProject, list[Job]], queries: list[Query], output=False, latest_only=True) -> list[dict] Performs a query and returns a list of records ie for each job the query result .. py:function:: query_to_records(jobs: obr.signac_wrapper.operations.OpenFOAMProject, queries: list[Query], latest_only=True, strict=False) -> list[dict] Given a list jobs find all jobs for which a query matches Flattens list of jobs to a dictionary with merged statepoints and job document first .. py:function:: query_to_dataframe(jobs: obr.signac_wrapper.operations.OpenFOAMProject, queries: list[Query], latest_only=True, strict: bool = False, index: list[str] = [], post_pro: Union[Callable, None] = None) -> pandas.DataFrame Given a list jobs find all jobs for which a query matches Flattens list of jobs to a dictionary with merged statepoints and job document first Args: index: A list of strings defining which columns should be used as index post_pro: Function to apply to the DataFrame before creating the index .. py:function:: build_filter_query(filters: Iterable[str]) -> list[Query] This function builds a list of filter queries, where filter queries are queries that request a specific value and has to conform a predicate .. py:function:: statepoint_get(statepoint: dict, key: str) This function performs a basic recursive query of the statepoint dictionary if the key: value pair is not found in statepoint it recurses into statepoint["parent"] if present .. py:function:: statepoint_query(statepoint: dict, key: str, value, predicate='==') This function performs a basic recursive query of the statepoint dictionary if the key: value pair is not found in statepoint it recurses into statepoint["parent"] if present .. py:function:: filter_jobs(project, filter: Iterable[str], output: bool = False) -> list[signac.job.Job] `filter` is expected to be a list, string or other iterable of strings in the form of