{
  "schemaVersion": 1,
  "slug": "pet-food-calculator",
  "category": "everyday",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "edfcaeb414111321bb0f6ead13260146b0077092bf47edafcaefd21666e17b8c",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/pet-food-calculator.json",
    "src/engine.js"
  ],
  "runtimeSource": "/sources/engine.txt",
  "runtimeHash": "5c888d8898afbdee36267bb9977829e1e2ac568f6677c8ee87469c139864645c",
  "scope": "The compute function records implemented equations, constants, lookup tables and custom rules. Inputs record defaults and allowed values; outputs record precision and units. Defaults are examples, not recommendations. General background references are not evidence for this specific algorithm.",
  "publishedFormula": {
    "formula": "C_kg = P ÷ (w × 0.45359237); C_day = g ÷ 1000 × C_kg × n",
    "vars": [
      [
        "C_kg",
        "Price per kg"
      ],
      [
        "P",
        "Bag price"
      ],
      [
        "w",
        "Bag weight (lb)"
      ],
      [
        "g",
        "Daily grams"
      ],
      [
        "n",
        "Number of pets"
      ],
      [
        "C_day",
        "Daily feeding cost"
      ]
    ],
    "note": "Cost per kg = bag price / bag mass in kg; cost per 1,000 kcal = cost per kg / kcal per kg × 1,000. Daily and yearly comparisons use the same entered grams per day and pet count for both foods; this does not determine a suitable feeding amount."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const costPerKg = bagWeight > 0 ? bagPrice/(bagWeight*0.45359237) : 0; const costPer1000Kcal = kcalPerKg > 0 ? costPerKg/kcalPerKg*1000 : 0; const dailyCost = dailyGrams/1000*costPerKg*pets; const compareCostPerKg = compareWeight > 0 ? comparePrice/(compareWeight*0.45359237) : 0; const comparePer1000 = compareKcal > 0 ? compareCostPerKg/compareKcal*1000 : 0; const compareDailyCost = dailyGrams/1000*compareCostPerKg*pets; const saving = (compareDailyCost-dailyCost)*365; return { costPerKg, costPer1000Kcal, dailyCost, monthlyCost: dailyCost*30.44, compareDailyCost, betterValue: costPer1000Kcal < comparePer1000 ? 'Your current food' : costPer1000Kcal > comparePer1000 ? 'The comparison food' : 'Same cost per 1,000 kcal', yearlySaving: Math.abs(saving) };",
    "inputs": [
      {
        "name": "bagPrice",
        "type": "number",
        "default": 45,
        "min": 0,
        "max": 10000,
        "step": 0.5
      },
      {
        "name": "bagWeight",
        "type": "number",
        "default": 24,
        "min": 0.1,
        "max": 500,
        "step": 0.5,
        "slider": true
      },
      {
        "name": "kcalPerKg",
        "type": "number",
        "default": 3600,
        "min": 500,
        "max": 6000,
        "step": 50,
        "slider": true
      },
      {
        "name": "dailyGrams",
        "type": "number",
        "default": 250,
        "min": 1,
        "max": 5000,
        "step": 5,
        "slider": true
      },
      {
        "name": "pets",
        "type": "number",
        "default": 1,
        "min": 1,
        "max": 50,
        "step": 1,
        "slider": true
      },
      {
        "name": "comparePrice",
        "type": "number",
        "default": 70,
        "min": 0,
        "max": 10000,
        "step": 0.5
      },
      {
        "name": "compareWeight",
        "type": "number",
        "default": 24,
        "min": 0.1,
        "max": 500,
        "step": 0.5,
        "slider": true
      },
      {
        "name": "compareKcal",
        "type": "number",
        "default": 4200,
        "min": 500,
        "max": 6000,
        "step": 50,
        "slider": true
      }
    ],
    "outputs": [
      {
        "name": "costPerKg",
        "precision": 2,
        "unit": "$/kg"
      },
      {
        "name": "costPer1000Kcal",
        "precision": 3,
        "unit": "$"
      },
      {
        "name": "dailyCost",
        "precision": 3,
        "unit": "$"
      },
      {
        "name": "monthlyCost",
        "precision": 2,
        "unit": "$"
      },
      {
        "name": "compareDailyCost",
        "precision": 3,
        "unit": "$"
      },
      {
        "name": "betterValue",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "yearlySaving",
        "precision": 2,
        "unit": "$"
      }
    ],
    "interpret": null
  }
}
