All files / src/utils businessValueUtils.ts

37.5% Statements 3/8
50% Branches 1/2
50% Functions 1/2
37.5% Lines 3/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94                                                                          102x             102x         102x                                                                                        
import roiEstimatesData from "../data/security/roiEstimatesData";
import { SecurityLevel } from "../types/cia";
import { ROIEstimate } from "../types/cia-services";
import {
  calculateImplementationCost as calculateImplCost,
  Industry,
  OrganizationSize,
} from "./costCalculationUtils";
import {
  calculateOverallSecurityLevel,
  getSecurityLevelValue,
} from "./securityLevelUtils";
 
/**
 * Interface for representing implementation timeline
 */
export interface ImplementationTimeline {
  total: string;
  phases?: Array<{
    name: string;
    duration: string;
  }>;
}
 
/**
 * Calculates ROI estimate based on security levels
 * @param availabilityLevel - Availability security level
 * @param integrityLevel - Integrity security level
 * @param confidentialityLevel - Confidentiality security level
 * @returns ROI estimate object with value and description
 */
export function calculateROIEstimate(
  availabilityLevel: SecurityLevel,
  integrityLevel: SecurityLevel,
  confidentialityLevel: SecurityLevel
): ROIEstimate {
  // Calculate overall security level for consistent ROI estimation
  const securityLevel = calculateOverallSecurityLevel(
    availabilityLevel,
    integrityLevel,
    confidentialityLevel
  );
 
  // Convert security level to ROI key format (e.g., "Very High" -> "VERY_HIGH")
  const roiKey = securityLevel
    .toUpperCase()
    .replace(" ", "_") as keyof typeof roiEstimatesData;
 
  // Return the ROI estimate from the existing data
  return roiEstimatesData[roiKey] || roiEstimatesData.MODERATE;
}
 
/**
 * Calculates implementation timeline based on security levels
 * @param availabilityLevel - Availability security level
 * @param integrityLevel - Integrity security level
 * @param confidentialityLevel - Confidentiality security level
 * @returns Implementation timeline object
 */
export function calculateImplementationTimeline(
  availabilityLevel: SecurityLevel,
  integrityLevel: SecurityLevel,
  confidentialityLevel: SecurityLevel
): ImplementationTimeline {
  // Get security level values
  const availabilityValue = getSecurityLevelValue(availabilityLevel);
  const integrityValue = getSecurityLevelValue(integrityLevel);
  const confidentialityValue = getSecurityLevelValue(confidentialityLevel);
 
  // Calculate total weeks based on security levels
  const totalWeeks = Math.round(
    (availabilityValue + integrityValue + confidentialityValue) * 1.5
  );
 
  // Calculate phases based on total time
  return {
    total: `${totalWeeks} weeks`,
    phases: [
      {
        name: "Planning",
        duration: `${Math.round(totalWeeks * 0.3)} weeks`,
      },
      {
        name: "Implementation",
        duration: `${Math.round(totalWeeks * 0.5)} weeks`,
      },
      {
        name: "Testing & Adoption",
        duration: `${Math.round(totalWeeks * 0.2)} weeks`,
      },
    ],
  };
}