webpage_quality_analyzer 1.0.2

High-performance webpage quality analyzer with 115 comprehensive metrics - Rust library with WASM, C++, and Python bindings
Documentation
/// Profile-aware scoring validation example
/// This demonstrates that different scoring profiles produce different scores
use webpage_quality_analyzer::metrics::*;

fn main() {
    println!("🔬 Profile-Aware Scoring Validation");
    println!("=====================================");

    // Load metrics registry
    let all_metrics = get_all_metrics();
    println!("📊 Loaded {} metrics from registry", all_metrics.len());

    // Test with word count metric
    let word_count_scorer = WordCountScorer;
    let test_word_count = MetricValue::Usize(1000);

    // Content Article Profile (favors longer content)
    let content_article_config = ProfileMetricConfig {
        weight: 0.3,
        enabled: true,
        thresholds: ThresholdSet {
            excellent: 2000.0, // Long articles are excellent
            good: 1000.0,
            fair: 500.0,
            poor: 200.0,
        },
        penalty_multiplier: 1.0,
        bonus_conditions: Vec::new(),
        scoring_function_override: None,
    };

    // Product Page Profile (prefers concise content)
    let product_config = ProfileMetricConfig {
        weight: 0.15,
        enabled: true,
        thresholds: ThresholdSet {
            excellent: 500.0, // Concise product descriptions are excellent
            good: 300.0,
            fair: 150.0,
            poor: 50.0,
        },
        penalty_multiplier: 1.0,
        bonus_conditions: Vec::new(),
        scoring_function_override: None,
    };

    // News Page Profile (balanced approach)
    let news_config = ProfileMetricConfig {
        weight: 0.25,
        enabled: true,
        thresholds: ThresholdSet {
            excellent: 800.0,
            good: 500.0,
            fair: 300.0,
            poor: 100.0,
        },
        penalty_multiplier: 1.0,
        bonus_conditions: Vec::new(),
        scoring_function_override: None,
    };

    // Calculate scores for same content (1000 words) across different profiles
    let content_score =
        word_count_scorer.score_metric(test_word_count.clone(), &content_article_config);
    let product_score = word_count_scorer.score_metric(test_word_count.clone(), &product_config);
    let news_score = word_count_scorer.score_metric(test_word_count, &news_config);

    println!("\n📝 Word Count Scoring (1000 words):");
    println!("Content Article Profile: {:.1} points", content_score);
    println!("Product Page Profile:    {:.1} points", product_score);
    println!("News Page Profile:       {:.1} points", news_score);

    // Validate that scores are different
    let scores_are_different = content_score != product_score || product_score != news_score;

    if scores_are_different {
        println!("\n✅ SUCCESS: Profile-aware scoring is working!");
        println!("Different profiles produce different scores for the same content.");

        // Show the scoring rationale
        println!("\n🎯 Scoring Logic:");
        println!("- Content articles favor longer content (excellent ≥ 2000 words)");
        println!("- Product pages favor concise content (excellent ≥ 500 words)");
        println!("- News articles use balanced thresholds (excellent ≥ 800 words)");
        println!("\nWith 1000 words:");
        println!("- Content: Below excellent threshold → moderate score");
        println!("- Product: Well above excellent threshold → high score");
        println!("- News: Above excellent threshold → high score");
    } else {
        println!("\n❌ ISSUE: All profiles produced the same score!");
        println!("This suggests profile-aware scoring may not be fully implemented.");
    }

    // Show additional metrics information
    println!("\n📈 Registry Statistics:");
    let categories: std::collections::HashSet<_> =
        all_metrics.iter().map(|m| &m.category).collect();
    println!("- Total metrics: {}", all_metrics.len());
    println!("- Categories: {}", categories.len());
    println!(
        "- Enabled by default: {}",
        all_metrics.iter().filter(|m| m.default_enabled).count()
    );

    println!("\n🏁 Phase 1 Enhanced Metric Registry validation complete!");
}