在 TypeScript 中计算费用和节省金额

您可以使用 TypeScript 创建自己的计算公式。代码位于 从长远来看,这个网页可以帮助您确定安装费用是否更低 或继续按原样支付电费。

下面简要说明了该代码如何确定太阳能电池板的成本。

第 1 部分:系统需求和设置

首先,定义您当前的用电情况和账单:

  • 您每月用多少电?(monthlyKwhEnergyConsumption
  • 这笔电费多少钱?(energyCostPerKwh

接下来,输入你的太阳系计划:

  • 需要多少面板?(panelsCount
  • 这些面板的效果如何?(panelCapacityWatts
  • 安装费用是多少?(installationCostPerWatt
  • 系统是否有任何折扣?(solarIncentives

第 2 部分:计算

代码会根据输入的值计算:

  • yearlyProductionAcKwh:您的太阳能电池板的年发电量 生成。
  • totalCostWithSolar:使用太阳能多年的电力成本 面板
  • totalCostWithoutSolar:多年来的电力成本 太阳能电池板

第 3 部分:结果

该代码还会告诉您以下信息:

  • savings:安装太阳能板与未安装太阳能板的费用差异。
  • breakEvenYear:还需要几年才能让太阳能电池板的成本等于 的电力节省。

示例代码

// Solar configuration, from buildingInsights.solarPotential.solarPanelConfigs
let panelsCount = 20;
let yearlyEnergyDcKwh = 12000;

// Basic settings
let monthlyAverageEnergyBill: number = 300;
let energyCostPerKwh = 0.31;
let panelCapacityWatts = 400;
let solarIncentives: number = 7000;
let installationCostPerWatt: number = 4.0;
let installationLifeSpan: number = 20;

// Advanced settings
let dcToAcDerate = 0.85;
let efficiencyDepreciationFactor = 0.995;
let costIncreaseFactor = 1.022;
let discountRate = 1.04;

// Solar installation
let installationSizeKw: number = (panelsCount * panelCapacityWatts) / 1000;
let installationCostTotal: number = installationCostPerWatt * installationSizeKw * 1000;

// Energy consumption
let monthlyKwhEnergyConsumption: number = monthlyAverageEnergyBill / energyCostPerKwh;
let yearlyKwhEnergyConsumption: number = monthlyKwhEnergyConsumption * 12;

// Energy produced for installation life span
let initialAcKwhPerYear: number = yearlyEnergyDcKwh * dcToAcDerate;
let yearlyProductionAcKwh: number[] = [...Array(installationLifeSpan).keys()].map(
  (year) => initialAcKwhPerYear * efficiencyDepreciationFactor ** year,
);

// Cost with solar for installation life span
let yearlyUtilityBillEstimates: number[] = yearlyProductionAcKwh.map(
  (yearlyKwhEnergyProduced, year) => {
    const billEnergyKwh = yearlyKwhEnergyConsumption - yearlyKwhEnergyProduced;
    const billEstimate =
      (billEnergyKwh * energyCostPerKwh * costIncreaseFactor ** year) / discountRate ** year;
    return Math.max(billEstimate, 0); // bill cannot be negative
  },
);
let remainingLifetimeUtilityBill: number = yearlyUtilityBillEstimates.reduce((x, y) => x + y, 0);
let totalCostWithSolar: number =
  installationCostTotal + remainingLifetimeUtilityBill - solarIncentives;
console.log(`Cost with solar: $${totalCostWithSolar.toFixed(2)}`);

// Cost without solar for installation life span
let yearlyCostWithoutSolar: number[] = [...Array(installationLifeSpan).keys()].map(
  (year) => (monthlyAverageEnergyBill * 12 * costIncreaseFactor ** year) / discountRate ** year,
);
let totalCostWithoutSolar: number = yearlyCostWithoutSolar.reduce((x, y) => x + y, 0);
console.log(`Cost without solar: $${totalCostWithoutSolar.toFixed(2)}`);

// Savings with solar for installation life span
let savings: number = totalCostWithoutSolar - totalCostWithSolar;
console.log(`Savings: $${savings.toFixed(2)} in ${installationLifeSpan} years`);