DEV Community

Armaan Khan
Armaan Khan

Posted on

Nkw

USER360_CHART_CONFIGS = {
    "user_unoptimized_query": [
        # Bar chart: Top inefficient users by weighted score
        {
            "chart_type": "bar",
            "x_axis": "USER_NAME",
            "y_axis": "WEIGHTED_SCORE",
            "title": "Top 20 Inefficient Users by Weighted Score",
            "color_field": "COST_STATUS",
            "colors": {
                "High Cost": "rgba(255, 99, 132, 0.6)",
                "Normal": "rgba(54, 162, 235, 0.6)"
            },
            "tooltip_fields": [
                "TOTAL_QUERIES",
                "TOTAL_CREDITS",
                "FAILURE_CANCELLATION_RATE_PCT",
                "RECOMMENDATIONS"
            ],
            # Insight: Identifies the top 20 users causing inefficiencies, with cost status highlighting high-cost users. Tooltips suggest actions like "Optimize joins to reduce failures."
        },
        # Heatmap: Correlation between inefficiency types and cost impact
        {
            "chart_type": "heatmap",
            "x_axis": "INEFFICIENCY_TYPE",
            "y_axis": "COST_IMPACT",
            "title": "Correlation of Inefficiency Types and Cost Impact",
            "color_scale": "RdBu_r",
            "tooltip_fields": ["TOTAL_CREDITS", "RECOMMENDATIONS"],
            # Insight: Shows which inefficiency types (e.g., spills, unpartitioned scans) correlate most with cost, guiding targeted fixes like "Use partitioning for scans."
        },
        # Treemap: Cost impact by inefficiency type
        {
            "chart_type": "treemap",
            "path": ["INEFFICIENCY_TYPE"],
            "values": "COST_IMPACT",
            "title": "Cost Impact by Inefficiency Type",
            "color_field": "INEFFICIENCY_TYPE",
            "colors": [
                "rgba(255, 99, 132, 0.6)",
                "rgba(54, 162, 235, 0.6)",
                "rgba(255, 206, 86, 0.6)",
                "rgba(75, 192, 192, 0.6)",
                "rgba(153, 102, 255, 0.6)",
                "rgba(255, 159, 64, 0.6)",
                "rgba(199, 199, 199, 0.6)",
                "rgba(83, 102, 255, 0.6)",
                "rgba(255, 99, 71, 0.6)",
                "rgba(144, 238, 144, 0.6)"
            ],
            "tooltip_fields": ["COST_IMPACT", "RECOMMENDATIONS"],
            # Insight: Visualizes the relative cost of each inefficiency type (e.g., SELECT * queries), with larger areas indicating higher impact. Tooltips suggest "Reduce SELECT * usage."
        },
        # Table: Detailed summary
        {
            "chart_type": "table",
            "title": "Unoptimized Query Summary for All Users",
        },
    ],
    "single_user_analysis": [
        # Radar chart: Multi-metric user performance
        {
            "chart_type": "radar",
            "categories": ["QUERY_EFFICIENCY", "COST_EFFICIENCY", "FAILURE_RATE", "SPILLAGE_RATE"],
            "values": ["QUERY_EFFICIENCY_SCORE", "COST_EFFICIENCY_SCORE", "FAILURE_RATE_PCT", "SPILLAGE_RATE_PCT"],
            "title": "User Performance Across Key Metrics",
            "tooltip_fields": ["RECOMMENDATIONS"],
            # Insight: Offers a holistic view of a user's efficiency, highlighting weak areas (e.g., high spillage rate) with suggestions like "Increase memory allocation."
        },
        # Waterfall chart: Incremental cost of bad practices
        {
            "chart_type": "waterfall",
            "x_axis": "INEFFICIENCY_TYPE",
            "y_axis": "COST_IMPACT",
            "title": "Cost Impact Breakdown by Inefficiency",
            "colors": ["rgba(255, 99, 132, 0.6)", "rgba(54, 162, 235, 0.6)", "rgba(255, 206, 86, 0.6)"],
            "tooltip_fields": ["COST_IMPACT", "RECOMMENDATIONS"],
            # Insight: Shows how each inefficiency adds to the total cost, pinpointing the biggest contributors (e.g., complex joins) with actions like "Simplify JOINs."
        },
        # Table: Detailed summary
        {
            "chart_type": "table",
            "title": "Single User Analysis Summary",
        },
    ],
    "bad_practice_impact_all": [
        # Treemap: Cost impact of bad practices across users
        {
            "chart_type": "treemap",
            "path": ["ISSUE_DESCRIPTION"],
            "values": "TOTAL_COST_IMPACT",
            "title": "Cost Impact of Bad Practices Across All Users",
            "color_field": "ISSUE_DESCRIPTION",
            "colors": [
                "rgba(255, 99, 132, 0.6)",
                "rgba(54, 162, 235, 0.6)",
                "rgba(255, 206, 86, 0.6)",
                "rgba(75, 192, 192, 0.6)",
                "rgba(153, 102, 255, 0.6)"
            ],
            "tooltip_fields": ["TOTAL_QUERIES", "RECOMMENDATIONS"],
            # Insight: Highlights the most costly bad practices (e.g., unpartitioned scans) across all users, suggesting fixes like "Implement partitioning."
        },
    ],
    "single_user_bad_practice_details": [
        # Donut chart: Cost distribution with total cost context
        {
            "chart_type": "donut",
            "names": "ISSUE_TYPE",
            "values": "COST_IMPACT",
            "title": "Cost Distribution by Bad Practice Type",
            "colors": [
                "rgba(255, 99, 132, 0.6)",
                "rgba(54, 162, 235, 0.6)",
                "rgba(255, 206, 86, 0.6)",
                "rgba(75, 192, 192, 0.6)"
            ],
            "tooltip_fields": ["RECOMMENDATIONS", "EXAMPLE_QUERY"],
            "center_text": "Total Cost: ${total_cost_impact:,.2f}",
            # Insight: Shows the proportion of cost per bad practice, with total cost in the center. Tooltips provide examples and fixes like "Cache repeated queries."
        },
    ],
    "user_value_vs_cost_quadrant": [
        # Scatter with quadrants: Efficiency vs. cost segmentation
        {
            "chart_type": "scatter",
            "x_axis": "EFFICIENCY_SCORE",
            "y_axis": "COST_IMPACT",
            "size_field": "QUERY_COUNT",
            "color_field": "USER_SEGMENT",
            "title": "User Value vs. Cost Quadrant",
            "colors": {
                "High Efficiency - High Cost": "rgba(75, 192, 192, 0.6)",
                "Low Efficiency - High Cost (OPTIMIZE)": "rgba(255, 99, 132, 0.6)",
                "High Efficiency - Low Cost (IDEAL)": "rgba(54, 162, 235, 0.6)",
                "Low Efficiency - Low Cost (MONITOR)": "rgba(255, 206, 86, 0.6)"
            },
            "tooltip_fields": ["USER_NAME", "EFFICIENCY_SCORE", "COST_IMPACT", "QUERY_COUNT"],
            "quadrants": {
                "lines": [50, 50],  # Thresholds for efficiency and cost
                "labels": ["Monitor", "Ideal", "Optimize", "High Value"]
            },
            # Insight: Segments users into actionable categories (e.g., "Optimize" for low efficiency, high cost), guiding prioritization.
        },
    ],
    "user_efficiency_matrix": [
        # Scatter with reference lines: Cost vs. performance efficiency
        {
            "chart_type": "scatter",
            "x_axis": "COST_EFFICIENCY_SCORE",
            "y_axis": "PERFORMANCE_EFFICIENCY_SCORE",
            "size_field": "TOTAL_COST",
            "color_field": "RISK_LEVEL",
            "title": "User Efficiency Matrix",
            "colors": {
                "HIGH_RISK": "rgba(255, 99, 132, 0.6)",
                "MEDIUM_RISK": "rgba(255, 206, 86, 0.6)",
                "OPTIMIZED": "rgba(54, 162, 235, 0.6)"
            },
            "tooltip_fields": ["USER_NAME", "RECOMMENDATIONS", "TOTAL_COST"],
            "reference_lines": {
                "x": 50,  # Cost efficiency threshold
                "y": 50   # Performance efficiency threshold
            },
            # Insight: Maps users by cost and performance efficiency, with risk levels and suggestions like "Adjust warehouse size" for high-risk users.
        },
    ],
    "single_user_critical_bad_practices_pie": [
        # Donut chart: Critical bad practices with total cost
        {
            "chart_type": "donut",
            "names": "ISSUE_TYPE",
            "values": "COST_IMPACT",
            "title": "Cost of Critical Bad Practices",
            "colors": [
                "rgba(255, 99, 132, 0.6)",
                "rgba(54, 162, 235, 0.6)",
                "rgba(255, 206, 86, 0.6)",
                "rgba(75, 192, 192, 0.6)"
            ],
            "tooltip_fields": ["COST_IMPACT", "RECOMMENDATIONS"],
            "center_text": "Total Cost: ${total_cost_impact:,.2f}",
            # Insight: Highlights critical bad practices by cost, with total impact in the center and fixes like "Debug failing queries."
        },
    ],
    "bytes_scanned_vs_rows_returned": [
        # Scatter with regression: Data efficiency analysis
        {
            "chart_type": "scatter",
            "x_axis": "MB_SCANNED",
            "y_axis": "ROWS_RETURNED",
            "color_field": "EFFICIENCY_STATUS",
            "title": "Bytes Scanned vs. Rows Returned",
            "colors": {
                "Inefficient": "rgba(255, 99, 132, 0.6)",
                "Efficient": "rgba(54, 162, 235, 0.6)"
            },
            "tooltip_fields": ["QUERY_ID", "MB_PER_ROW", "RECOMMENDATIONS"],
            "regression_line": True,
            # Insight: Identifies inefficient queries (outliers above the line), suggesting "Use clustering to reduce scans."
        },
    ],
    "credits_query_efficiency_trend": [
        # Dual-axis line: Daily credits vs. query efficiency
        {
            "chart_type Prune": "dual_axis",
            "x_axis": "USAGE_DATE",
            "y_axis": ["DAILY_CREDITS", "AVG_CREDITS_PER_QUERY"],
            "color_field": "DAILY_USAGE_STATUS",
            "title": "Daily Credits and Query Efficiency Trend",
            "colors": {
                "Very High": "rgba(255, 99, 132, 0.6)",
                "High": "rgba(255, 206, 86, 0.6)",
                "Normal": "rgba(54, 162, 235, 0.6)"
            },
            "tooltip_fields": ["QUERY_COUNT", "AVG_CREDITS_PER_QUERY", "RECOMMENDATIONS"],
            # Insight: Tracks daily credit usage alongside query cost, pinpointing inefficient days with suggestions like "Review peak usage queries."
        },
    ],
    "query_inefficiency_bar_all": [
        # Grouped bar: Inefficiency vs. query volume
        {
            "chart_type": "grouped_bar",
            "x_axis": "USER_NAME",
            "y_axis": ["AVG_MB_SCANNED_PER_ROW", "TOTAL_QUERIES"],
            "title": "Query Inefficiency and Volume by User",
            "colors": ["rgba(255, 99, 132, 0.6)", "rgba(54, 162, 235, 0.6)"],
            "tooltip_fields": ["EFFICIENCY_STATUS", "TOTAL_CREDITS_USED", "RECOMMENDATIONS"],
            # Insight: Compares inefficiency (MB/row) with query volume, identifying users needing optimization (e.g., "Reduce scan-heavy queries").
        },
    ],
    "failure_spillage_summary": [
        # Bubble chart: Failure vs. spillage risk
        {
            "chart_type": "bubble",
            "x_axis": "FAILURE_CANCELLATION_RATE_PCT",
            "y_axis": "SPILLAGE_RATE_PCT",
            "size_field": "TOTAL_CREDITS",
            "color_field": "RISK_LEVEL",
            "title": "Failure & Spillage Risk by User",
            "colors": {
                "High Risk": "rgba(255, 99, 132, 0.6)",
                "Moderate Risk": "rgba(255, 206, 86, 0.6)",
                "Low Risk": "rgba(54, 162, 235, 0.6)"
            },
            "tooltip_fields": ["USER_NAME", "TOTAL_CREDITS", "RECOMMENDATIONS"],
            # Insight: Highlights users with high failure/spillage rates and costs, suggesting "Stabilize queries" or "Optimize memory."
        },
    ],
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)