// Label mappings for product categories const CATEGORY_LABELS = { deli_salad: "Deli Salad", dairy_dip: "Dairy Dip", acidified_sauce: "Acidified Sauce", rte_meat: "RTE Meat", plant_based_spread: "Plant-Based Spread", smoked_seafood: "Smoked Seafood", cooked_poultry: "Cooked Poultry", mayo_dressing: "Mayo Dressing", hummus_dip: "Hummus Dip", soft_cheese: "Soft Cheese", }; // Label mappings for packaging types const PACKAGING_LABELS = { tub: "Tub", vacuum: "Vacuum Sealed", jar: "Jar", MAP: "Modified Atmosphere (MAP)", tray: "Tray", bottle: "Bottle", foil: "Foil Pack", sachet: "Sachet", }; // Label mappings for oxygen conditions const OXYGEN_LABELS = { aerobic: "Aerobic", anaerobic: "Anaerobic", reduced_oxygen: "Reduced Oxygen", }; // Label mappings for inoculation types const INOCULATION_LABELS = { low_inoculum: "Low Inoculum", medium_inoculum: "Medium Inoculum", high_inoculum: "High Inoculum", }; // Label mappings for preservative types const PRESERVATIVE_LABELS = { none: "None", sodium_benzoate: "Sodium Benzoate", nisin: "Nisin", potassium_sorbate: "Potassium Sorbate", cultured_dextrose: "Cultured Dextrose", }; // Label mappings for acidulant types const ACIDULANT_LABELS = { none: "None", vinegar: "Vinegar", lactic_acid: "Lactic Acid", acetic_acid: "Acetic Acid", citric_acid: "Citric Acid", }; // Label mappings for curve modes const CURVE_MODE_LABELS = { both: "Both (ML + Kinetic)", ml: "Machine Learning", kinetic: "Kinetic Model", }; // Label mappings for risk classes const RISK_CLASS_LABELS = { low: "Low Risk", moderate: "Moderate Risk", high: "High Risk", critical: "Critical Risk", }; // Label mappings for confidence labels const CONFIDENCE_LABELS = { low: "Low Confidence", moderate: "Moderate Confidence", high: "High Confidence", }; // Label mappings for feature names (used in sensitivity analysis) const FEATURE_LABELS = { storage_temperature_c: "Storage Temperature (°C)", initial_inoculum_log_cfu_g: "Initial Inoculum (log CFU/g)", ph: "pH", aw: "Water Activity (aw)", salt_percent: "Salt (%)", sugar_percent: "Sugar (%)", fat_percent: "Fat (%)", target_shelf_life_days: "Target Shelf Life (days)", product_category: "Product Category", packaging_type: "Packaging Type", oxygen_condition: "Oxygen Condition", preservative_type: "Preservative Type", preservative_flag: "Preservative Enabled", acidulant_type: "Acidulant Type", inoculation_type: "Inoculation Level", time_days: "Time (days)", }; // Label mappings for direction values const DIRECTION_LABELS = { increases: "Increases Risk", decreases: "Decreases Risk", increase: "Increases Risk", decrease: "Decreases Risk", }; // Generic fallback formatter: "snake_case" -> "Title Case" export function toTitleCase(value) { if (!value || typeof value !== "string") return value; return value .split("_") .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()) .join(" "); } // Main formatter function export function formatLabel(value, type = "generic") { if (value === null || value === undefined) return ""; const stringValue = String(value); const labelMaps = { category: CATEGORY_LABELS, packaging: PACKAGING_LABELS, oxygen: OXYGEN_LABELS, inoculation: INOCULATION_LABELS, preservative: PRESERVATIVE_LABELS, acidulant: ACIDULANT_LABELS, curveMode: CURVE_MODE_LABELS, riskClass: RISK_CLASS_LABELS, confidence: CONFIDENCE_LABELS, feature: FEATURE_LABELS, direction: DIRECTION_LABELS, }; const map = labelMaps[type]; if (map && map[stringValue]) { return map[stringValue]; } // Fallback to title case conversion return toTitleCase(stringValue); } // Convenience functions for common use cases export const formatCategory = (v) => formatLabel(v, "category"); export const formatPackaging = (v) => formatLabel(v, "packaging"); export const formatOxygen = (v) => formatLabel(v, "oxygen"); export const formatInoculation = (v) => formatLabel(v, "inoculation"); export const formatPreservative = (v) => formatLabel(v, "preservative"); export const formatAcidulant = (v) => formatLabel(v, "acidulant"); export const formatCurveMode = (v) => formatLabel(v, "curveMode"); export const formatRiskClass = (v) => formatLabel(v, "riskClass"); export const formatConfidence = (v) => formatLabel(v, "confidence"); export const formatFeature = (v) => formatLabel(v, "feature"); export const formatDirection = (v) => formatLabel(v, "direction"); // Export option arrays with labels for dropdowns export const OPTIONS = { category: Object.entries(CATEGORY_LABELS).map(([value, label]) => ({ value, label })), packaging: Object.entries(PACKAGING_LABELS).map(([value, label]) => ({ value, label })), oxygen: Object.entries(OXYGEN_LABELS).map(([value, label]) => ({ value, label })), inoculation: Object.entries(INOCULATION_LABELS).map(([value, label]) => ({ value, label })), preservative: Object.entries(PRESERVATIVE_LABELS).map(([value, label]) => ({ value, label })), acidulant: Object.entries(ACIDULANT_LABELS).map(([value, label]) => ({ value, label })), curveMode: Object.entries(CURVE_MODE_LABELS).map(([value, label]) => ({ value, label })), };