DEV Community

Armaan Khan
Armaan Khan

Posted on

Chart config

# SNOWFLAKE ANALYTICS CHART CONFIGURATIONS

## ALL USERS ANALYSIS CONFIGURATIONS

all_users_configs = {
    "user_unoptimized_query": [
        # Keep existing configuration as is - already optimized
        {
            "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",
            ],
        },
        {
            "chart_type": "stacked_bar",
            "x_axis": "USER_NAME",
            "y_axis": [
                "SPILLED_QUERIES",
                "PEAK_HOUR_LONG_RUNNING_QUERIES",
                "SELECT_STAR_QUERIES",
                "UNPARTITIONED_SCAN_QUERIES",
                "COMPLEX_JOIN_QUERIES",
                "HIGH_COMPILE_QUERIES",
            ],
            "stack_field": "Inefficiency Type",
            "title": "Cost-Related Inefficiency Breakdown by User",
            "colors": {
                "SPILLED_QUERIES": "rgba(255, 99, 132, 0.6)",
                "PEAK_HOUR_LONG_RUNNING_QUERIES": "rgba(255, 206, 86, 0.6)",
                "SELECT_STAR_QUERIES": "rgba(75, 192, 192, 0.6)",
                "UNPARTITIONED_SCAN_QUERIES": "rgba(153, 102, 255, 0.6)",
                "COMPLEX_JOIN_QUERIES": "rgba(199, 199, 199, 0.6)",
                "HIGH_COMPILE_QUERIES": "rgba(255, 99, 71, 0.6)",
            },
            "tooltip_fields": ["RECOMMENDATIONS", "TOTAL_CREDITS"],
        },
        {
            "chart_type": "grouped_bar",
            "x_axis": "USER_NAME",
            "y_axis": [
                "SPILLED_QUERIES",
                "PEAK_HOUR_LONG_RUNNING_QUERIES",
                "SELECT_STAR_QUERIES",
                "UNPARTITIONED_SCAN_QUERIES",
                "COMPLEX_JOIN_QUERIES",
                "HIGH_COMPILE_QUERIES",
            ],
            "stack_field": "Inefficiency Type",
            "title": "Cost-Related Inefficiency Comparison by User",
            "colors": {
                "SPILLED_QUERIES": "rgba(255, 99, 132, 0.6)",
                "PEAK_HOUR_LONG_RUNNING_QUERIES": "rgba(255, 206, 86, 0.6)",
                "SELECT_STAR_QUERIES": "rgba(75, 192, 192, 0.6)",
                "UNPARTITIONED_SCAN_QUERIES": "rgba(153, 102, 255, 0.6)",
                "COMPLEX_JOIN_QUERIES": "rgba(199, 199, 199, 0.6)",
                "HIGH_COMPILE_QUERIES": "rgba(255, 99, 71, 0.6)",
            },
            "tooltip_fields": ["RECOMMENDATIONS", "TOTAL_CREDITS"],
        },
        {
            "chart_type": "pie",
            "y_axis": [
                "OVER_PROVISIONED_QUERIES",
                "SELECT_STAR_QUERIES",
                "ZERO_RESULT_QUERIES",
                "UNTAGGED_QUERIES",
            ],
            "stack_field": "Inefficiency Type",
            "title": "Performance-Related Distribution of Inefficiency Types",
            "colors": [
                "rgba(54, 162, 235, 0.6)",
                "rgba(75, 192, 192, 0.6)",
                "rgba(83, 102, 255, 0.6)",
                "rgba(144, 238, 144, 0.6)",
            ],
            "tooltip_fields": ["USER_NAME", "TOTAL_CREDITS", "RECOMMENDATIONS"],
        },
    ],

    # Additional analysis for all users
    "bad_practice_impact_all": [
        {
            "chart_type": "bar",
            "x_axis": "USER_NAME",
            "y_axis": "TOTAL_COST_IMPACT",
            "color_field": "ISSUE_DESCRIPTION",
            "title": "Cost Impact of Bad Practices by User",
            "colors": {
                "Frequent SELECT * usage detected.": "rgba(255, 99, 132, 0.6)",
                "High unpartitioned scan frequency.": "rgba(54, 162, 235, 0.6)",
                "Repeated queries not leveraging caching.": "rgba(255, 206, 86, 0.6)",
                "Excessive complex query patterns.": "rgba(75, 192, 192, 0.6)",
                "Mixed bad practices.": "rgba(153, 102, 255, 0.6)",
            },
            "tooltip_fields": ["RECOMMENDATION", "TOTAL_QUERIES"],
        },
    ],

    "user_efficiency_matrix": [
        {
            "chart_type": "bar",
            "x_axis": "USER_NAME",
            "y_axis": "TOTAL_COST",
            "color_field": "RISK_LEVEL",
            "title": "Total Cost by Risk Level - All Users",
            "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": [
                "RECOMMENDATION",
                "COST_EFFICIENCY_SCORE",
                "PERFORMANCE_EFFICIENCY_SCORE",
            ],
        },
    ],

    "bytes_scanned_vs_rows_returned": [
        {
            "chart_type": "bar",
            "x_axis": "EFFICIENCY_STATUS",
            "y_axis": "MB_SCANNED",
            "color_field": "EFFICIENCY_STATUS",
            "title": "Data Scanning Efficiency - All Queries",
            "colors": {
                "Inefficient": "rgba(255, 99, 132, 0.6)",
                "Efficient": "rgba(54, 162, 235, 0.6)",
            },
            "tooltip_fields": ["ROWS_RETURNED", "QUERY_ID"],
        },
    ],
}

## SINGLE USER ANALYSIS CONFIGURATIONS

single_user_configs = {
    "single_user_analysis": [
        # Show weighted score with details (not as chart but as summary card)
        {
            "chart_type": "metric_card",
            "metrics": ["WEIGHTED_SCORE", "COST_STATUS", "TOTAL_QUERIES", "TOTAL_CREDITS"],
            "title": "User Performance Summary",
            "color_field": "COST_STATUS",
            "colors": {
                "High Cost": "rgba(255, 99, 132, 0.6)",
                "Normal": "rgba(54, 162, 235, 0.6)",
            },
            "tooltip_fields": ["RECOMMENDATIONS"],
        },

        # Cost-Related Inefficiency Breakdown with focus on actionable items
        {
            "chart_type": "grouped_bar",
            "x_axis": "METRIC_TYPE",
            "y_axis": [
                "SPILLED_QUERIES",
                "PEAK_HOUR_LONG_RUNNING_QUERIES", 
                "COMPLEX_JOIN_QUERIES",
                "HIGH_COMPILE_QUERIES",
            ],
            "title": "Cost-Related Inefficiency Breakdown",
            "colors": {
                "SPILLED_QUERIES": "rgba(255, 99, 132, 0.6)",
                "PEAK_HOUR_LONG_RUNNING_QUERIES": "rgba(255, 206, 86, 0.6)",
                "COMPLEX_JOIN_QUERIES": "rgba(199, 199, 199, 0.6)",
                "HIGH_COMPILE_QUERIES": "rgba(255, 99, 71, 0.6)",
            },
            "tooltip_fields": ["RECOMMENDATIONS"],
        },

        # Performance-Related Issues as pie chart
        {
            "chart_type": "pie",
            "y_axis": [
                "OVER_PROVISIONED_QUERIES",
                "SELECT_STAR_QUERIES", 
                "UNPARTITIONED_SCAN_QUERIES",
                "ZERO_RESULT_QUERIES",
                "UNTAGGED_QUERIES",
            ],
            "title": "Performance-Related Issue Distribution",
            "colors": [
                "rgba(54, 162, 235, 0.6)",
                "rgba(75, 192, 192, 0.6)",
                "rgba(153, 102, 255, 0.6)",
                "rgba(83, 102, 255, 0.6)",
                "rgba(144, 238, 144, 0.6)",
            ],
            "tooltip_fields": ["RECOMMENDATIONS"],
        },
    ],

    # Bad practice details with time dimension
    "single_user_bad_practice_details": [
        {
            "chart_type": "donut",
            "x_axis": "ISSUE_TYPE",
            "y_axis": "COST_IMPACT",
            "title": "Cost Impact 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": ["RECOMMENDATION", "QUERY_COUNT", "EXAMPLE_QUERY"],
        },

        # Action items table showing what to fix
        {
            "chart_type": "table",
            "title": "Optimization Action Plan",
            "columns": ["ISSUE_TYPE", "QUERY_COUNT", "COST_IMPACT", "RECOMMENDATION"],
            "sort_by": "COST_IMPACT",
            "sort_order": "desc",
            "color_field": "COST_IMPACT",
            "conditional_formatting": {
                "high": {"threshold": 75, "color": "rgba(255, 99, 132, 0.6)"},
                "medium": {"threshold": 25, "color": "rgba(255, 206, 86, 0.6)"},
                "low": {"threshold": 0, "color": "rgba(54, 162, 235, 0.6)"},
            },
        },
    ],

    # Time-based bad practice trends
    "credits_query_efficiency_trend": [
        {
            "chart_type": "line",
            "x_axis": "USAGE_DATE",
            "y_axis": "DAILY_CREDITS",
            "color_field": "QUERY_EFFICIENCY_STATUS",
            "title": "Daily Credit Usage Trend with Efficiency Status",
            "colors": {
                "Inefficient": "rgba(255, 99, 132, 0.6)",
                "Efficient": "rgba(54, 162, 235, 0.6)",
            },
            "tooltip_fields": ["QUERY_COUNT", "AVG_CREDITS_PER_QUERY", "DAILY_USAGE_STATUS"],
        },

        {
            "chart_type": "bar",
            "x_axis": "USAGE_DATE", 
            "y_axis": "QUERY_COUNT",
            "color_field": "DAILY_USAGE_STATUS",
            "title": "Query Volume by Day with Usage Status",
            "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": ["DAILY_CREDITS", "AVG_CREDITS_PER_QUERY"],
        },
    ],

    # Critical bad practices with detailed recommendations
    "single_user_critical_bad_practices_pie": [
        {
            "chart_type": "donut",
            "x_axis": "ISSUE_TYPE",
            "y_axis": "COST_IMPACT", 
            "title": "Critical Bad Practices - Cost Breakdown",
            "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"],
            "center_text": "Total Cost Impact",
        },

        # Recommendations matrix
        {
            "chart_type": "heatmap",
            "x_axis": "ISSUE_TYPE",
            "y_axis": "PRIORITY_LEVEL", # Based on cost impact
            "value_field": "COST_IMPACT",
            "title": "Optimization Priority Matrix",
            "colors": {
                "low": "rgba(54, 162, 235, 0.3)",
                "medium": "rgba(255, 206, 86, 0.6)", 
                "high": "rgba(255, 99, 132, 0.8)",
            },
            "tooltip_fields": ["ISSUE_TYPE", "COST_IMPACT", "RECOMMENDATION"],
        },
    ],

    # Query efficiency over time with patterns
    "bytes_scanned_vs_rows_returned": [
        {
            "chart_type": "bar",
            "x_axis": "EFFICIENCY_STATUS",
            "y_axis": "MB_SCANNED",
            "color_field": "EFFICIENCY_STATUS", 
            "title": "Data Scanning Efficiency - Single User",
            "colors": {
                "Inefficient": "rgba(255, 99, 132, 0.6)",
                "Efficient": "rgba(54, 162, 235, 0.6)",
            },
            "tooltip_fields": ["ROWS_RETURNED", "MB_PER_ROW"],
        },

        # Efficiency improvement tracking
        {
            "chart_type": "gauge",
            "value_field": "EFFICIENCY_PERCENTAGE",
            "title": "Query Efficiency Score",
            "min_value": 0,
            "max_value": 100,
            "thresholds": {
                "poor": {"min": 0, "max": 30, "color": "rgba(255, 99, 132, 0.6)"},
                "average": {"min": 30, "max": 70, "color": "rgba(255, 206, 86, 0.6)"},
                "good": {"min": 70, "max": 100, "color": "rgba(54, 162, 235, 0.6)"},
            },
        },
    ],
}

## ADDITIONAL INSIGHTS FOR SINGLE USER

single_user_additional = {
    # Time-based bad practice analysis
    "bad_practice_timeline": [
        {
            "chart_type": "stacked_area",
            "x_axis": "DATE",
            "y_axis": [
                "SPILLED_QUERIES_COUNT",
                "SELECT_STAR_COUNT", 
                "UNPARTITIONED_SCAN_COUNT",
                "COMPLEX_JOIN_COUNT",
            ],
            "title": "Bad Practice Trends Over Time",
            "colors": {
                "SPILLED_QUERIES_COUNT": "rgba(255, 99, 132, 0.6)",
                "SELECT_STAR_COUNT": "rgba(75, 192, 192, 0.6)",
                "UNPARTITIONED_SCAN_COUNT": "rgba(153, 102, 255, 0.6)", 
                "COMPLEX_JOIN_COUNT": "rgba(199, 199, 199, 0.6)",
            },
            "tooltip_fields": ["TOTAL_COST_IMPACT", "RECOMMENDATIONS"],
        },
    ],

    # Actionable recommendations with priority
    "optimization_roadmap": [
        {
            "chart_type": "horizontal_bar",
            "x_axis": "COST_SAVINGS_POTENTIAL",
            "y_axis": "RECOMMENDATION_CATEGORY",
            "color_field": "IMPLEMENTATION_DIFFICULTY",
            "title": "Optimization Roadmap - Cost Savings vs Effort",
            "colors": {
                "Easy": "rgba(54, 162, 235, 0.6)",
                "Medium": "rgba(255, 206, 86, 0.6)",
                "Hard": "rgba(255, 99, 132, 0.6)",
            },
            "tooltip_fields": ["SPECIFIC_ACTION", "ESTIMATED_TIMEFRAME"],
        },
    ],
}

# CHART CONFIGURATION RULES:
# 1. Each chart shows unique insights - no duplication
# 2. All Users: Focus on comparative analysis and ranking
# 3. Single User: Focus on detailed diagnosis and actionable recommendations  
# 4. Time dimension included where relevant for trend analysis
# 5. Clear action items and recommendations highlighted
# 6. Cost impact always considered for prioritization
# 7. Performance and cost metrics balanced
# 8. Visual hierarchy: Critical issues → Cost impact → Recommendations
Enter fullscreen mode Exit fullscreen mode

Top comments (0)