derived_data_variable
DerivedDataVariable
from dara.core.interactivity.derived_data_variable import DerivedDataVariable
class DerivedDataVariable(AnyDataVariable, DerivedVariable)
DerivedDataVariable represents a variable designed to hold datasets computed by a resolver function like a normal DerivedVariable.
Note: the resolver function must return a DataFrame.
Attributes
- uid: str
- filters: Optional[FilterQuery]
- variables: List[AnyVariable]
- polling_interval: Optional[int]
- deps: Optional[List[AnyVariable]]
Methods
__init__
def __init__(func: Union[
Callable[..., Union[DataFrame, None]],
Callable[..., Coroutine[Any, Any, Union[DataFrame, None]]],
],
variables: List[AnyVariable],
cache: CacheArgType = Cache.Type.GLOBAL,
run_as_task: bool = False,
polling_interval: Optional[int] = None,
deps: Optional[List[AnyVariable]] = None,
uid: Optional[str] = None) -> None
DerivedDataVariable represents a variable designed to hold datasets computed
by a resolver function like a normal DerivedVariable.
Note: the resolver function must return a DataFrame.
Arguments:
func
: the function to derive a new value from the input variables. Must return a DataFramevariables
: a set of input variables that will be passed to the deriving functiondefault
: the initial value for the variable, defaults to Nonecache
: whether to cache the result, defaults to global caching. Other options are to cache per user session, or per userrun_as_task
: whether to run the calculation in a separate process, recommended for any CPU intensive tasks, defaults to Falsepolling_interval
: an optional polling interval for the DerivedVariable. Setting this will cause the component to poll the backend and refresh itself every n seconds.deps
: an optional array of variables, specifying which dependant variables changing should trigger a recalculation of the derived variabledeps = None
-func
is ran everytime (default behaviour),deps = []
-func
is ran once on initial startup,deps = [var1, var2]
-func
is ran whenever one of these vars changesuid
: the unique identifier for this variable; if not provided a random one is generated
get_value
@classmethod
async def get_value(cls,
var_entry: DerivedVariableRegistryEntry,
store: CacheStore,
task_mgr: TaskManager,
args: List[Any],
force: bool = False) -> DerivedVariableResult
Update the underlying derived variable.
Wrapper around DerivedVariable.get_value which does not return the value (returns True
instead).
Arguments:
var
: the registry entry for the underlying derived variablestore
: the store instance to check for cached valuestask_mgr
: task manager instanceargs
: the arguments to call the underlying function withforce
: whether to ignore cache
get_data
@classmethod
async def get_data(
cls,
dv_entry: DerivedVariableRegistryEntry,
data_entry: DataVariableRegistryEntry,
cache_key: str,
store: CacheStore,
filters: Optional[Union[FilterQuery, dict]] = None,
pagination: Optional[Pagination] = None,
format_for_display: bool = False) -> Union[BaseTask, DataFrame, None]
Get the filtered data from the underlying derived variable stored under the specified cache_key.
Arguments:
var_entry
: the registry entry for the data variablecache_key
: cache_key of the underlying DerivedVariablestore
: the store instance to check for cached valuesfilters
: the filters to apply to the datapagination
: the pagination to apply to the data
get_total_count
@classmethod
async def get_total_count(cls, data_entry: DataVariableRegistryEntry,
store: CacheStore, cache_key: str,
filters: Optional[FilterQuery])
Get total count of the derived data variable.
get_schema
@classmethod
async def get_schema(cls, derived_entry: DerivedVariableRegistryEntry,
store: CacheStore, cache_key: str)
Get the schema of the derived data variable.
resolve_value
@classmethod
async def resolve_value(cls,
data_entry: DataVariableRegistryEntry,
dv_entry: DerivedVariableRegistryEntry,
store: CacheStore,
task_mgr: TaskManager,
args: List[Any],
force: bool,
filters: Optional[Union[FilterQuery, dict]] = None)
Helper method to resolve the filtered value of a derived data variable.
Under the hood runs the underlying DerivedVariable, starts its task if required, and then filters the result.
Arguments:
data_entry
: the registry entry for the data variabledv_entry
: the registry entry for the underlying derived variablestore
: the store instance to check for cached valuestask_mgr
: task manager instanceargs
: the arguments to call the underlying function withforce
: whether to ignore cachefilters
: the filters to apply to the datapagination
: the pagination to apply to the data