calculateMetrics method

Map<String, dynamic> calculateMetrics({
  1. required List<ProviderNode> nodes,
  2. required int filesProcessed,
  3. List<ArchitectureSmell> smells = const [],
  4. List<GovernanceViolation> violations = const [],
})

Calculates migration and health metrics from nodes, smells, and violations.

Returns a map with keys: logic_units_migrated, methods_transformed, files_processed, estimated_hours_saved, boilerplate_reduction_percent, architecture_health_score, smells_count, violations_count, and migration_success_ratio.

Implementation

Map<String, dynamic> calculateMetrics({
  required List<ProviderNode> nodes,
  required int filesProcessed,
  List<ArchitectureSmell> smells = const [],
  List<GovernanceViolation> violations = const [],
}) {
  final logicUnits = nodes.whereType<LogicUnitNode>().length;
  final totalMethods = nodes.whereType<LogicUnitNode>().fold(
    0,
    (sum, node) => sum + node.methods.length,
  );

  // Estimation: 2h per logic unit, 30m per method.
  final estimatedHoursSaved = (logicUnits * 2) + (totalMethods * 0.5);
  final boilerplateReduction = 0.15;

  // Architecture Health Score calculation (starts at 100)
  double healthScore = 100.0;
  healthScore -= (smells.length * 2.5); // Deduct for smells
  healthScore -=
      (violations.length * 5.0); // Heavier deduction for violations
  if (healthScore < 0) healthScore = 0.0;

  return {
    'logic_units_migrated': logicUnits,
    'methods_transformed': totalMethods,
    'files_processed': filesProcessed,
    'estimated_hours_saved': estimatedHoursSaved,
    'boilerplate_reduction_percent': (boilerplateReduction * 100)
        .toStringAsFixed(1),
    'architecture_health_score': healthScore.toStringAsFixed(1),
    'smells_count': smells.length,
    'violations_count': violations.length,
    'migration_success_ratio': 1.0,
  };
}