pdstools.decision_analyzer.utils ================================ .. py:module:: pdstools.decision_analyzer.utils Attributes ---------- .. autoapisummary:: pdstools.decision_analyzer.utils.NBADScope_Mapping Functions --------- .. autoapisummary:: pdstools.decision_analyzer.utils.apply_filter pdstools.decision_analyzer.utils.filtered_action_counts pdstools.decision_analyzer.utils.area_under_curve pdstools.decision_analyzer.utils.gini_coefficient pdstools.decision_analyzer.utils.get_first_level_stats pdstools.decision_analyzer.utils.get_git_version_and_date pdstools.decision_analyzer.utils.determine_extract_type pdstools.decision_analyzer.utils.rename_and_cast_types pdstools.decision_analyzer.utils.get_table_definition pdstools.decision_analyzer.utils.get_schema pdstools.decision_analyzer.utils.create_hierarchical_selectors pdstools.decision_analyzer.utils.get_scope_config Module Contents --------------- .. py:data:: NBADScope_Mapping .. py:function:: apply_filter(df: polars.LazyFrame, filters: Optional[Union[polars.Expr, List[polars.Expr]]] = None) Apply a global set of filters. Kept outside of the DecisionData class as this is really more of a utility function, not bound to that class at all. .. py:function:: filtered_action_counts(df: polars.LazyFrame, groupby_cols: list, propensityTH: float = None, priorityTH: float = None) -> polars.LazyFrame Returns a DataFrame with action counts filtered based on the given propensity and priority thresholds. :param df: The input dataframe. :type df: pl.LazyFrame :param groupby_cols: The list of column names to group by(["pxEngagementStage", "pxInteractionID"]). :type groupby_cols: list :param propensityTH: The propensity threshold. :type propensityTH: float :param priorityTH: The priority threshold. :type priorityTH: float :returns: A DataFrame with action counts filtered based on the given propensity and priority thresholds. :rtype: pl.LazyFrame .. py:function:: area_under_curve(df: polars.DataFrame, col_x: str, col_y: str) .. py:function:: gini_coefficient(df: polars.DataFrame, col_x: str, col_y: str) .. py:function:: get_first_level_stats(interaction_data: polars.LazyFrame, filters: List[polars.Expr] = None) Returns some first level stats of a dataframe. Used to show effects of user data filters. .. py:function:: get_git_version_and_date() .. py:function:: determine_extract_type(raw_data) .. py:function:: rename_and_cast_types(df: polars.LazyFrame, table_definition: Dict, include_cols: Optional[Iterable[str]] = None) -> polars.LazyFrame Rename columns and cast data types based on table definition. :param df: The input dataframe to process :type df: pl.LazyFrame :param table_definition: Dictionary containing column definitions with 'label', 'default', and 'type' keys :type table_definition: Dict :param include_cols: Additional columns to include beyond default columns :type include_cols: Optional[Iterable[str]], optional :returns: Processed dataframe with renamed columns and cast types :rtype: pl.LazyFrame .. py:function:: get_table_definition(table: str) .. py:function:: get_schema(df: polars.LazyFrame, table_definition: Dict, include_cols: Iterable[str]) -> Dict[str, Type[polars.DataType]] Build type mapping for dataframe columns based on table definition. :param df: The input dataframe to analyze :type df: pl.LazyFrame :param table_definition: Dictionary containing column definitions with 'label', 'default', and 'type' keys :type table_definition: Dict :param include_cols: Additional columns to include beyond default columns :type include_cols: Iterable[str] :returns: Mapping of column names to their data types :rtype: Dict[str, Type[pl.DataType]] .. py:function:: create_hierarchical_selectors(data: polars.LazyFrame, selected_issue: Optional[str] = None, selected_group: Optional[str] = None, selected_action: Optional[str] = None) -> Dict[str, Dict[str, Union[List[str], int]]] Create hierarchical filter options and calculate indices for selectbox widgets. Args: data: LazyFrame with hierarchical data (should be pre-filtered to desired stage) selected_issue: Currently selected issue (optional) selected_group: Currently selected group (optional) selected_action: Currently selected action (optional) Returns: Dict with structure: { "issues": {"options": [...], "index": 0}, "groups": {"options": ["All", ...], "index": 0}, "actions": {"options": ["All", ...], "index": 0} } .. py:function:: get_scope_config(selected_issue: str, selected_group: str, selected_action: str) -> Dict[str, Union[str, polars.Expr, List[str]]] Generate scope configuration for lever application and plotting based on user selections. This utility function determines the appropriate scope level (Issue, Group, or Action) based on hierarchical user selections and returns configuration needed for both lever condition generation and plotting. :param selected_issue: Selected issue value from dropdown (can be "All") :type selected_issue: str :param selected_group: Selected group value from dropdown (can be "All") :type selected_group: str :param selected_action: Selected action value from dropdown (can be "All") :type selected_action: str :returns: Configuration dictionary containing: - level: "Action", "Group", or "Issue" indicating scope level - lever_condition: Polars expression for filtering selected actions - group_cols: List of column names for grouping operations - x_col: Column name to use for x-axis in plots - selected_value: The actual selected value for highlighting - plot_title_prefix: Prefix for plot titles :rtype: Dict[str, Union[str, pl.Expr, List[str]]] .. rubric:: Notes The function follows hierarchical logic: - If action != "All": Action-level scope - Elif group != "All": Group-level scope - Else: Issue-level scope .. rubric:: Examples Action-level selection: >>> config = get_scope_config("Service", "Cards", "SpecificAction") >>> config["level"] # "Action" >>> config["lever_condition"] # pl.col("pyName") == "SpecificAction" Group-level selection: >>> config = get_scope_config("Service", "Cards", "All") >>> config["level"] # "Group" >>> config["lever_condition"] # (pl.col("pyIssue") == "Service") & (pl.col("pyGroup") == "Cards")