Module: Synthra::QualityMetrics

Defined in:
lib/synthra/quality_metrics.rb

Overview

Data Quality Metrics

Analyze generated data for quality, realism, and distribution. Useful for validating test data quality and debugging generation issues.

Examples:

Analyze generated data

records = Synthra.generate_many("User", 1000)
report = Synthra::QualityMetrics.analyze(records, schema: "User")

report.uniqueness[:email]  # => 100.0
report.distribution[:role] # => { "admin" => 5, "user" => 95 }
report.realism_score       # => 94.5

Defined Under Namespace

Classes: Analyzer, GenerationResult, QualityReport

Class Method Summary collapse

Class Method Details

.analyze(records, schema: nil) ⇒ QualityReport

Analyze a collection of records

Parameters:

  • records (Array<Hash>)

    generated records

  • schema (String, Schema) (defaults to: nil)

    schema for context

Returns:



25
26
27
28
29
30
# File 'lib/synthra/quality_metrics.rb', line 25

def analyze(records, schema: nil)
  schema = Synthra.registry.schema(schema.to_s) if schema.is_a?(String)

  analyzer = Analyzer.new(records, schema)
  analyzer.analyze
end

.generate_with_quality(schema_name, count: 100, **options) ⇒ GenerationResult

Generate data with quality report

Parameters:

  • schema_name (String)

    schema name

  • count (Integer) (defaults to: 100)

    number of records

  • options (Hash)

    generation options

Returns:



39
40
41
42
43
44
45
# File 'lib/synthra/quality_metrics.rb', line 39

def generate_with_quality(schema_name, count: 100, **options)
  schema = Synthra.registry.schema(schema_name)
  records = schema.generate_many(count, **options)
  report = analyze(records, schema: schema)

  GenerationResult.new(records, report)
end