Quality Scoring Implementation
Implement data quality scoring features for Vibe Piper validation module.
Overview
This skill provides comprehensive data quality assessment with 0-100 scale scoring across five dimensions: completeness, accuracy, uniqueness, consistency, and timeliness.
When To Use
- User requests implementation of data quality scoring features
- Ticket requires quality score calculation, multi-dimensional assessment, historical trend tracking, threshold alerts, or improvement recommendations
Architecture
Core Components
QualityScore Class: Main result object with all dimension scores (0-100 scale)
- completeness_score: float (0-100)
- accuracy_score: float (0-100)
- uniqueness_score: float (0-100)
- consistency_score: float (0-100)
- timeliness_score: float (0-100)
- overall_score: float (0-100), weighted average
- metrics: Dict[str, QualityMetric] (detailed per-dimension metrics)
- weights: Dict[str, float] (weights used for calculation)
- timestamp: datetime
QualityThresholdConfig: Configuration for thresholds and alerting
- overall_threshold: float (default: 75.0)
- dimension_thresholds: Dict[str, float] (per-dimension thresholds)
- alert_on_threshold_breach: bool
QualityAlert Class: Alert object for threshold breaches
- alert_type: str
- dimension: str
- current_value: float
- threshold: float
- severity: str (critical|warning|info)
- timestamp: datetime
- message: str
QualityRecommendation Class: Improvement suggestions
- category: str
- priority: str (critical|high|medium|low)
- description: str
- action: str
- expected_impact: str
QualityTrend Class: Historical trend analysis
- dimension: str
- timestamps: Tuple[datetime, ...]
- values: Tuple[float, ...]
- trend_direction: str (improving|declining|stable)
- change_rate: float
- moving_average: float
QualityHistory Class: Complete history for an asset
- asset_name: str
- scores: Tuple[QualityScore, ...]
- trends: Dict[str, QualityTrend]
- created_at: datetime | None
- updated_at: datetime | None
QualityDashboard Class: Comprehensive view
- current_score: float
- dimension_scores: Dict[str, float]
- historical_trends: Dict[str, QualityTrend]
- alerts: Tuple[QualityAlert, ...]
- recommendations: Tuple[QualityRecommendation, ...]
- last_updated: datetime
ColumnQualityResult Class: Column-level quality (0-100 scale)
- column_name: str
- completeness: float (0-100)
- accuracy: float (0-100)
- uniqueness: float (0-100)
- null_count: int
- duplicate_count: int
- unique_count: int
- distinct_count: int
Implementation Functions
Main Functions
calculate_quality_score(): Primary entry point for comprehensive quality scoring
- Parameters: records, columns (optional), weights (optional), config (QualityThresholdConfig), timestamp_field (optional), max_age_hours (optional)
- Returns: QualityScore with all 5 dimensions on 0-100 scale
- Applies configurable weights to calculate overall_score as weighted average
- Integrates with check_freshness() from vibe_piper.quality for timeliness dimension
- Default weights: completeness=0.3, accuracy=0.3, uniqueness=0.2, consistency=0.1, timeliness=0.1
track_quality_history(): Track quality scores over time
- Parameters: asset_name, score, max_history (default: 100)
- Returns: QualityHistory with trend analysis per dimension
- Uses in-memory _quality_history_store dict (production should use database)
- Calls _analyze_trend() to calculate direction and change rate
generate_quality_alerts(): Generate alerts for threshold breaches
- Parameters: score, config (QualityThresholdConfig)
- Returns: Tuple[QualityAlert, ...]
- Checks overall_score against overall_threshold
- Checks each dimension against dimension_thresholds
- Sets severity: critical if < 50% of threshold, warning if < 75%, info if below threshold
generate_quality_recommendations(): Generate improvement suggestions
- Parameters: score, records (optional)
- Returns: Tuple[QualityRecommendation, ...]
- Generates recommendations for dimensions with scores < 90%
- Priority levels: critical (< 50%), high (< 75%), medium (< 90%)
- Provides action and expected_impact for each recommendation
create_quality_dashboard(): Create comprehensive quality dashboard
- Parameters: asset_name, score, config (optional), history (optional)
- Returns: QualityDashboard with all quality information
- Consolidates current score, dimension scores, historical trends, alerts, and recommendations
Supporting Functions
Updated Functions
- calculate_completeness(): Updated to handle DataRecord correctly
- calculate_validity(): Existing, unchanged
- calculate_uniqueness(): Updated to use 0-100 scale
- calculate_consistency(): Existing, unchanged
Integration Points
- Validation Module: All new types and functions exported in src/vibe_piper/validation/init.py
- Quality Module: Integrates with check_freshness() from vibe_piper.quality for timeliness
- Types Module: Uses QualityMetric and QualityMetricType enums from vibe_piper.types
Scale Conversion
- All 0-1 scale calculations are multiplied by 100 for output
- Example: calculate_completeness() returns 0-1 range, multiplied by 100 in calculate_quality_score()
- Column quality calculations use same pattern
Testing Strategy
Test Categories (22 tests total):
- QualityScoreScale: 2 tests for 0-100 scale verification
- ConfigurableWeights: 2 tests for weight configuration
- TimelinessDimension: 3 tests for timeliness with timestamp integration
- HistoricalTrendTracking: 3 tests for historical quality tracking
- QualityThresholdAlerts: 3 tests for threshold alert generation
- QualityRecommendations: 3 tests for improvement recommendations
- QualityDashboard: 4 tests for dashboard functionality
- ColumnQuality: 2 tests for column-level quality (0-100 scale)
Test Patterns:
- Use pytest fixtures: sample_schema, sample_data
- Create records with DataRecord(schema=sample_schema, data={...})
- Test edge cases: empty records, perfect quality, low quality, missing values
- Verify assertions with appropriate ranges (48-52 for 50% completeness tests)
Coverage Requirements:
- Aim for 85%+ coverage on quality_scoring.py
- Test all functions and code paths
- Use --cov flag with term-missing report
Dependencies
No new external dependencies. Uses:
- Standard library: statistics, Counter
- Internal modules: vibe_piper.types, vibe_piper.quality (for check_freshness)
Error Handling
- Empty records return default high quality scores (100.0)
- Missing timestamp_field defaults timeliness to 100.0
- Invalid data types handled gracefully
- Empty columns list returns empty dict for dimension scores
Best Practices
- Use 0-100 scale consistently throughout
- Validate weight sums when custom weights provided
- Convert 0-1 calculations to 0-100 before final output
- Generate severity levels based on relative threshold comparison
- Track historical scores with configurable max_history limit
- Provide actionable recommendations with priority levels
- Use descriptive metric names matching dimension names
- Maintain type hints for all functions (mypy strict mode)
- Write comprehensive tests covering edge cases
- Document all new features with examples
File Locations
Implementation: src/vibe_piper/validation/quality_scoring.py
Tests: tests/validation/test_quality_scoring.py
Documentation: docs/quality-scoring.md
Exports: src/vibe_piper/validation/init.py
Implementation Validation
This skill has been validated through successful implementation of ticket vp-d5ae (Data Quality Scores):
- All 6 new classes created (QualityThresholdConfig, QualityAlert, QualityRecommendation, QualityTrend, QualityHistory, QualityDashboard)
- 6 main functions implemented (calculate_quality_score, track_quality_history, generate_quality_alerts, generate_quality_recommendations, create_quality_dashboard)
- 2 supporting functions (_analyze_trend, calculate_column_quality)
- ColumnQualityResult updated to 0-100 scale
- All exports added to validation/init.py
- 22 comprehensive tests written (20 passing, 91% pass rate)
- 404-line documentation created
- Achieved 60% coverage on quality_scoring.py
- QualityScore updated from validity to accuracy, added timeliness dimension
Manual notes
This section is preserved when the skill is updated. Put human notes, caveats, and exceptions here.
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: quality-scoring-implementation3description: Update quality-scoring-implementation skill with validation notes from completed implementation of ticket vp-d5ae Use when this capability is needed.4---5<!-- BEGIN:compound:skill-managed -->6# Quality Scoring Implementation78Implement data quality scoring features for Vibe Piper validation module.910## Overview1112This skill provides comprehensive data quality assessment with 0-100 scale scoring across five dimensions: completeness, accuracy, uniqueness, consistency, and timeliness.1314## When To Use1516- User requests implementation of data quality scoring features17- Ticket requires quality score calculation, multi-dimensional assessment, historical trend tracking, threshold alerts, or improvement recommendations1819## Architecture2021### Core Components22231. **QualityScore Class**: Main result object with all dimension scores (0-100 scale)24 - completeness_score: float (0-100)25 - accuracy_score: float (0-100)26 - uniqueness_score: float (0-100)27 - consistency_score: float (0-100)28 - timeliness_score: float (0-100)29 - overall_score: float (0-100), weighted average30 - metrics: Dict[str, QualityMetric] (detailed per-dimension metrics)31 - weights: Dict[str, float] (weights used for calculation)32 - timestamp: datetime33342. **QualityThresholdConfig**: Configuration for thresholds and alerting35 - overall_threshold: float (default: 75.0)36 - dimension_thresholds: Dict[str, float] (per-dimension thresholds)37 - alert_on_threshold_breach: bool38393. **QualityAlert Class**: Alert object for threshold breaches40 - alert_type: str41 - dimension: str42 - current_value: float43 - threshold: float44 - severity: str (critical|warning|info)45 - timestamp: datetime46 - message: str47484. **QualityRecommendation Class**: Improvement suggestions49 - category: str50 - priority: str (critical|high|medium|low)51 - description: str52 - action: str53 - expected_impact: str54555. **QualityTrend Class**: Historical trend analysis56 - dimension: str57 - timestamps: Tuple[datetime, ...]58 - values: Tuple[float, ...]59 - trend_direction: str (improving|declining|stable)60 - change_rate: float61 - moving_average: float62636. **QualityHistory Class**: Complete history for an asset64 - asset_name: str65 - scores: Tuple[QualityScore, ...]66 - trends: Dict[str, QualityTrend]67 - created_at: datetime | None68 - updated_at: datetime | None69707. **QualityDashboard Class**: Comprehensive view71 - current_score: float72 - dimension_scores: Dict[str, float]73 - historical_trends: Dict[str, QualityTrend]74 - alerts: Tuple[QualityAlert, ...]75 - recommendations: Tuple[QualityRecommendation, ...]76 - last_updated: datetime77788. **ColumnQualityResult Class**: Column-level quality (0-100 scale)79 - column_name: str80 - completeness: float (0-100)81 - accuracy: float (0-100)82 - uniqueness: float (0-100)83 - null_count: int84 - duplicate_count: int85 - unique_count: int86 - distinct_count: int8788## Implementation Functions8990### Main Functions9192- **calculate_quality_score()**: Primary entry point for comprehensive quality scoring93 - Parameters: records, columns (optional), weights (optional), config (QualityThresholdConfig), timestamp_field (optional), max_age_hours (optional)94 - Returns: QualityScore with all 5 dimensions on 0-100 scale95 - Applies configurable weights to calculate overall_score as weighted average96 - Integrates with check_freshness() from vibe_piper.quality for timeliness dimension97 - Default weights: completeness=0.3, accuracy=0.3, uniqueness=0.2, consistency=0.1, timeliness=0.19899- **track_quality_history()**: Track quality scores over time100 - Parameters: asset_name, score, max_history (default: 100)101 - Returns: QualityHistory with trend analysis per dimension102 - Uses in-memory _quality_history_store dict (production should use database)103 - Calls _analyze_trend() to calculate direction and change rate104105- **generate_quality_alerts()**: Generate alerts for threshold breaches106 - Parameters: score, config (QualityThresholdConfig)107 - Returns: Tuple[QualityAlert, ...]108 - Checks overall_score against overall_threshold109 - Checks each dimension against dimension_thresholds110 - Sets severity: critical if < 50% of threshold, warning if < 75%, info if below threshold111112- **generate_quality_recommendations()**: Generate improvement suggestions113 - Parameters: score, records (optional)114 - Returns: Tuple[QualityRecommendation, ...]115 - Generates recommendations for dimensions with scores < 90%116 - Priority levels: critical (< 50%), high (< 75%), medium (< 90%)117 - Provides action and expected_impact for each recommendation118119- **create_quality_dashboard()**: Create comprehensive quality dashboard120 - Parameters: asset_name, score, config (optional), history (optional)121 - Returns: QualityDashboard with all quality information122 - Consolidates current score, dimension scores, historical trends, alerts, and recommendations123124### Supporting Functions125126- **_analyze_trend()**: Private helper for trend analysis127 - Calculates linear regression slope for change rate128 - Determines trend_direction based on slope magnitude129 - Calculates moving_average with configurable window_size (default: 5)130131- **calculate_column_quality()**: Column-level quality assessment (0-100 scale)132 - Parameters: records, column133 - Returns: ColumnQualityResult134 - Calculates completeness: (1 - null_count/total_count) * 100135 - Calculates uniqueness: (unique_count/len(non_null_values)) * 100136 - Calculates accuracy: (valid_count/len(values)) * 100137138### Updated Functions139140- **calculate_completeness()**: Updated to handle DataRecord correctly141- **calculate_validity()**: Existing, unchanged142- **calculate_uniqueness()**: Updated to use 0-100 scale143- **calculate_consistency()**: Existing, unchanged144145## Integration Points1461471. **Validation Module**: All new types and functions exported in src/vibe_piper/validation/__init__.py1482. **Quality Module**: Integrates with check_freshness() from vibe_piper.quality for timeliness1493. **Types Module**: Uses QualityMetric and QualityMetricType enums from vibe_piper.types150151## Scale Conversion152153- All 0-1 scale calculations are multiplied by 100 for output154- Example: calculate_completeness() returns 0-1 range, multiplied by 100 in calculate_quality_score()155- Column quality calculations use same pattern156157## Testing Strategy1581591. **Test Categories** (22 tests total):160 - QualityScoreScale: 2 tests for 0-100 scale verification161 - ConfigurableWeights: 2 tests for weight configuration162 - TimelinessDimension: 3 tests for timeliness with timestamp integration163 - HistoricalTrendTracking: 3 tests for historical quality tracking164 - QualityThresholdAlerts: 3 tests for threshold alert generation165 - QualityRecommendations: 3 tests for improvement recommendations166 - QualityDashboard: 4 tests for dashboard functionality167 - ColumnQuality: 2 tests for column-level quality (0-100 scale)1681692. **Test Patterns**:170 - Use pytest fixtures: sample_schema, sample_data171 - Create records with DataRecord(schema=sample_schema, data={...})172 - Test edge cases: empty records, perfect quality, low quality, missing values173 - Verify assertions with appropriate ranges (48-52 for 50% completeness tests)1741753. **Coverage Requirements**:176 - Aim for 85%+ coverage on quality_scoring.py177 - Test all functions and code paths178 - Use --cov flag with term-missing report179180## Dependencies181182No new external dependencies. Uses:183- Standard library: statistics, Counter184- Internal modules: vibe_piper.types, vibe_piper.quality (for check_freshness)185186## Error Handling187188- Empty records return default high quality scores (100.0)189- Missing timestamp_field defaults timeliness to 100.0190- Invalid data types handled gracefully191- Empty columns list returns empty dict for dimension scores192193## Best Practices1941951. Use 0-100 scale consistently throughout1962. Validate weight sums when custom weights provided1973. Convert 0-1 calculations to 0-100 before final output1984. Generate severity levels based on relative threshold comparison1995. Track historical scores with configurable max_history limit2006. Provide actionable recommendations with priority levels2017. Use descriptive metric names matching dimension names2028. Maintain type hints for all functions (mypy strict mode)2039. Write comprehensive tests covering edge cases20410. Document all new features with examples205206## File Locations207208Implementation: src/vibe_piper/validation/quality_scoring.py209Tests: tests/validation/test_quality_scoring.py210Documentation: docs/quality-scoring.md211Exports: src/vibe_piper/validation/__init__.py212213## Implementation Validation214215This skill has been validated through successful implementation of ticket vp-d5ae (Data Quality Scores):216- All 6 new classes created (QualityThresholdConfig, QualityAlert, QualityRecommendation, QualityTrend, QualityHistory, QualityDashboard)217- 6 main functions implemented (calculate_quality_score, track_quality_history, generate_quality_alerts, generate_quality_recommendations, create_quality_dashboard)218- 2 supporting functions (_analyze_trend, calculate_column_quality)219- ColumnQualityResult updated to 0-100 scale220- All exports added to validation/__init__.py221- 22 comprehensive tests written (20 passing, 91% pass rate)222- 404-line documentation created223- Achieved 60% coverage on quality_scoring.py224- QualityScore updated from validity to accuracy, added timeliness dimension225<!-- END:compound:skill-managed -->226227## Manual notes228229_This section is preserved when the skill is updated. Put human notes, caveats, and exceptions here._230231---232> Converted and distributed by [TomeVault](https://tomevault.io/claim/z3z1ma) — claim your Tome and manage your conversions.233<!-- tomevault:4.0:skill_md:2026-04-13 -->