use std::collections::HashMap;
use webpage_quality_analyzer::config::profile_builder::{ContentType, ProfileBuilder};
use webpage_quality_analyzer::config::ProfileTemplates;
use webpage_quality_analyzer::metrics::ThresholdSet;
fn main() {
println!("🎨 Custom Profile Creation Examples\n");
println!("{}", "=".repeat(80));
example_1_basic_profile();
example_2_content_type_presets();
example_3_custom_weights();
example_4_custom_thresholds();
example_5_profile_templates();
example_6_advanced_custom();
println!("\n✅ All examples completed successfully!");
}
fn example_1_basic_profile() {
println!("\n📊 Example 1: Basic Profile Creation");
println!("{}", "-".repeat(80));
let profile = ProfileBuilder::new("my_custom_profile")
.with_description("A simple custom profile for testing")
.build()
.expect("Failed to build profile");
println!("✓ Profile Name: {}", profile.metadata.name);
println!("✓ Description: {}", profile.metadata.description);
println!("✓ Category Weights:");
for (category, weight) in &profile.category_weights {
println!(" - {}: {:.2}", category, weight);
}
}
fn example_2_content_type_presets() {
println!("\n📊 Example 2: Content Type Presets");
println!("{}", "-".repeat(80));
let article_profile = ProfileBuilder::new("tech_blog")
.for_content_type(ContentType::LongFormArticle)
.with_description("Profile for technical blog posts")
.build()
.expect("Failed to build article profile");
println!("✓ Long-Form Article Profile:");
println!(
" - Content weight: {:.2}",
article_profile
.category_weights
.get("content")
.unwrap_or(&0.0)
);
let news_profile = ProfileBuilder::new("news_site")
.for_content_type(ContentType::NewsArticle)
.with_description("Profile for news articles")
.build()
.expect("Failed to build news profile");
println!("✓ News Article Profile:");
println!(
" - Content weight: {:.2}",
news_profile.category_weights.get("content").unwrap_or(&0.0)
);
println!(
" - SEO weight: {:.2}",
news_profile.category_weights.get("seo").unwrap_or(&0.0)
);
}
fn example_3_custom_weights() {
println!("\n📊 Example 3: Custom Metric Weights");
println!("{}", "-".repeat(80));
let profile = ProfileBuilder::new("content_first")
.for_content_type(ContentType::LongFormArticle)
.with_description("Extremely content-focused profile")
.with_metric_weight("word_count", 0.60)
.expect("Failed to set word_count weight")
.with_metric_weight("paragraph_count", 0.30)
.expect("Failed to set paragraph_count weight")
.with_metric_weight("title_len", 0.10)
.expect("Failed to set title_len weight")
.build()
.expect("Failed to build profile");
println!("✓ Custom Metric Weights:");
for (metric, override_cfg) in &profile.metric_overrides {
println!(" - {}: {:.2}", metric, override_cfg.weight);
}
}
fn example_4_custom_thresholds() {
println!("\n📊 Example 4: Custom Thresholds");
println!("{}", "-".repeat(80));
let word_count_thresholds = ThresholdSet {
excellent: 3000.0, good: 2000.0,
fair: 1000.0,
poor: 500.0,
};
let profile = ProfileBuilder::new("long_form_strict")
.for_content_type(ContentType::LongFormArticle)
.with_description("Strict long-form article requirements")
.with_custom_threshold("word_count", word_count_thresholds)
.expect("Failed to set custom thresholds")
.build()
.expect("Failed to build profile");
if let Some(override_cfg) = profile.metric_overrides.get("word_count") {
if let Some(thresholds) = &override_cfg.thresholds {
println!("✓ Custom Word Count Thresholds:");
println!(" - Excellent: {} words", thresholds.excellent);
println!(" - Good: {} words", thresholds.good);
println!(" - Fair: {} words", thresholds.fair);
println!(" - Poor: {} words", thresholds.poor);
}
}
}
fn example_5_profile_templates() {
println!("\n📊 Example 5: Using ProfileTemplates");
println!("{}", "-".repeat(80));
let templates = ProfileTemplates::list_templates();
println!("✓ Available Templates:");
for template in &templates {
println!(" - {}", template);
}
println!();
let template = ProfileTemplates::get_template("content_article")
.expect("Failed to get content_article template");
println!("✓ Content Article Template:");
println!(" - Name: {}", template.metadata.name);
println!(" - Description: {}", template.metadata.description);
println!(
" - Content weight: {:.2}",
template.category_weights.get("content").unwrap_or(&0.0)
);
}
fn example_6_advanced_custom() {
println!("\n📊 Example 6: Advanced Customization");
println!("{}", "-".repeat(80));
let profile = ProfileBuilder::new("advanced_custom")
.with_description("Fully customized profile with multiple features")
.for_content_type(ContentType::LongFormArticle)
.with_metric_weight("word_count", 0.40)
.expect("Failed to set weight")
.with_metric_weight("readability_fk", 0.30)
.expect("Failed to set weight")
.with_metric_weight("title_len", 0.30)
.expect("Failed to set weight")
.with_metric_enabled("meta_desc_len", false)
.build()
.expect("Failed to build profile");
println!("✓ Advanced profile created:");
println!(" - Name: {}", profile.metadata.name);
println!(" - Content Type: Long Form Article");
println!(
" - Total metric overrides: {}",
profile.metric_overrides.len()
);
println!(
" - Enabled metrics: {}",
profile
.metric_overrides
.values()
.filter(|m| m.enabled)
.count()
);
println!(
" - Disabled metrics: {}",
profile
.metric_overrides
.values()
.filter(|m| !m.enabled)
.count()
);
}