def render_variables_section(dataframe_summary: dict) -> list: """Render the HTML for each of the variables in the DataFrame. Args: dataframe_summary: The statistics for each variable. Returns: The rendered HTML, where each row represents a variable. """ templs = [] descriptions = config["variables"]["descriptions"].get(dict) show_description = config["show_variable_description"].get(bool) reject_variables = config["reject_variables"].get(bool) render_map = get_render_map() for idx, summary in dataframe_summary["variables"].items(): # Common template variables warnings = [ warning.fmt() for warning in dataframe_summary["messages"] if warning.column_name == idx ] warning_fields = { field for warning in dataframe_summary["messages"] if warning.column_name == idx for field in warning.fields } warning_types = { warning.message_type for warning in dataframe_summary["messages"] if warning.column_name == idx } template_variables = { "varname": idx, "varid": hash(idx), "warnings": warnings, "description": descriptions.get(idx, "") if show_description else "", "warn_fields": warning_fields, } template_variables.update(summary) # Per type template variables template_variables.update( render_map[summary["type"]](template_variables)) # Ignore these if reject_variables: ignore = MessageType.REJECTED in warning_types else: ignore = False bottom = None if "bottom" in template_variables and template_variables[ "bottom"] is not None: btn = ToggleButton("Toggle details", anchor_id=template_variables["varid"]) bottom = Collapse(btn, template_variables["bottom"]) var = Variable( template_variables["top"], bottom=bottom, anchor_id=template_variables["varid"], name=idx, ignore=ignore, ) templs.append(var) return templs
def render_variables_section(dataframe_summary: dict) -> list: """Render the HTML for each of the variables in the DataFrame. Args: dataframe_summary: The statistics for each variable. Returns: The rendered HTML, where each row represents a variable. """ type_to_func = { Boolean: render_boolean, Real: render_real, Count: render_real, Complex: render_complex, Date: render_date, Categorical: render_categorical, Url: render_url, AbsolutePath: render_path, ExistingPath: render_path, # ImagePath: render_path_image, Generic: render_generic, } templs = [] for idx, summary in dataframe_summary["variables"].items(): # Common template variables warnings = [ warning.fmt() for warning in dataframe_summary["messages"] if warning.column_name == idx ] warning_fields = { field for warning in dataframe_summary["messages"] if warning.column_name == idx for field in warning.fields } warning_types = { warning.message_type for warning in dataframe_summary["messages"] if warning.column_name == idx } template_variables = { "varname": idx, "varid": hash(idx), "warnings": warnings, "warn_fields": warning_fields, } template_variables.update(summary) # Per type template variables template_variables.update(type_to_func[summary["type"]](template_variables)) # Ignore these if config["reject_variables"].get(bool): ignore = MessageType.REJECTED in warning_types else: ignore = False bottom = None if "bottom" in template_variables and template_variables["bottom"] is not None: btn = ToggleButton("Toggle details", anchor_id=template_variables["varid"]) bottom = Collapse(btn, template_variables["bottom"]) var = Variable( template_variables["top"], bottom=bottom, anchor_id=template_variables["varid"], name=idx, ignore=ignore, ) templs.append(var) return templs
def render_variables_section(config: Settings, dataframe_summary: dict) -> list: """Render the HTML for each of the variables in the DataFrame. Args: config: report Settings object dataframe_summary: The statistics for each variable. Returns: The rendered HTML, where each row represents a variable. """ templs = [] descriptions = config.variables.descriptions show_description = config.show_variable_description reject_variables = config.reject_variables render_map = get_render_map() for idx, summary in dataframe_summary["variables"].items(): # Common template variables alerts = [ alert.fmt() for alert in dataframe_summary["alerts"] if alert.column_name == idx ] alert_fields = { field for alert in dataframe_summary["alerts"] if alert.column_name == idx for field in alert.fields } alert_types = { alert.alert_type for alert in dataframe_summary["alerts"] if alert.column_name == idx } template_variables = { "varname": idx, "varid": hash(idx), "alerts": alerts, "description": descriptions.get(idx, "") if show_description else "", "alert_fields": alert_fields, } template_variables.update(summary) # Per type template variables template_variables.update( render_map[summary["type"]](config, template_variables) ) # Ignore these if reject_variables: ignore = AlertType.REJECTED in alert_types else: ignore = False bottom = None if "bottom" in template_variables and template_variables["bottom"] is not None: btn = ToggleButton("Toggle details", anchor_id=template_variables["varid"]) bottom = Collapse(btn, template_variables["bottom"]) var = Variable( template_variables["top"], bottom=bottom, anchor_id=template_variables["varid"], name=idx, ignore=ignore, ) templs.append(var) return templs