mendevi.database.meta

Help to get the good extractor.

Classes

ExtractContext(label, func, is_log)

Create new instance of ExtractContext(label, func, is_log)

Functions

extract_names(expr)

Return all the symbols in the python expression.

get_extractor(name[, safe])

Get the way to deserialize a raw value.

merge_extractors(labels[, select])

Return the source code of the function that extracts all variables.

Details

class mendevi.database.meta.ExtractContext(label, func, is_log)

Create new instance of ExtractContext(label, func, is_log)

mendevi.database.meta.extract_names(expr: str) set[str][source]

Return all the symbols in the python expression.

Examples

>>> from mendevi.database.meta import extract_names
>>> extract_names("foo")
{'foo'}
>>> extract_names("[i**2 for i in foo]"")
{'foo'}
>>> extract_names("foo.bar")
{'foo'}
>>> extract_names("bar(foo)")
{'foo'}
>>> extract_names("foo.bar()")
{'foo'}
>>>
mendevi.database.meta.get_extractor(name: str, safe: bool = False) ExtractContext[source]

Get the way to deserialize a raw value.

Parameters

namestr

The label name.

safeboolean, default=False

If True, retrun a stupid value instead of raising KeyError.

Returns

labelstr

The description of the physical quantity. This description can be used to label the axes of a graph.

funccallable | str

The function that performs the verification and deserialisation task, or the formula that allows you to find this quantity.

is_logboolean or None

True to display in log space, False for linear. The value None means the axis is not continuous.

mendevi.database.meta.merge_extractors(labels: set[str], select: str | None = None) Module[source]

Return the source code of the function that extracts all variables.

Examples

>>> from mendevi.database.meta import merge_extractors
>>> print("\n".join(merge_extractors({"rate", "profile"})[1]))
def line_extractor(raw: dict[str]) -> dict[str]:
"""Get the labels: profile, rate."""
    # deserialisation of basic values
    profile = extract.extract_profile(raw)
    size = extract.extract_video_size(raw)
    video_duration = extract.extract_video_duration(raw)

    # association of basic values
    rate = 8.0 * size / video_duration

    # packaging
    return {
        'profile': profile
        'rate': rate
    }
>>>