Skip to content

Commit

Permalink
Add solar_potential_calculations region tag
Browse files Browse the repository at this point in the history
  • Loading branch information
TechandEco authored Dec 26, 2023
1 parent 7337ec0 commit 847319f
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 68 deletions.
24 changes: 12 additions & 12 deletions src/routes/sections/Sections.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,24 @@
let showPanels = true;
// User settings
let monthlyAverageEnergyBill = 300;
let panelCapacityWatts = 250;
let energyCostPerKwh = 0.31;
let dcToAcDerate = 0.85;
let monthlyAverageEnergyBillInput = 300;
let panelCapacityWattsInput = 250;
let energyCostPerKwhInput = 0.31;
let dcToAcDerateInput = 0.85;
// Find the config that covers the yearly energy consumption.
let yearlyKwhEnergyConsumption: number;
$: yearlyKwhEnergyConsumption = (monthlyAverageEnergyBill / energyCostPerKwh) * 12;
$: yearlyKwhEnergyConsumption = (monthlyAverageEnergyBillInput / energyCostPerKwhInput) * 12;
let configId: number | undefined;
$: if (configId === undefined && buildingInsights) {
const defaultPanelCapacity = buildingInsights.solarPotential.panelCapacityWatts;
const panelCapacityRatio = panelCapacityWatts / defaultPanelCapacity;
const panelCapacityRatio = panelCapacityWattsInput / defaultPanelCapacity;
configId = findSolarConfig(
buildingInsights.solarPotential.solarPanelConfigs,
yearlyKwhEnergyConsumption,
panelCapacityRatio,
dcToAcDerate,
dcToAcDerateInput,
);
}
</script>
Expand All @@ -63,7 +63,7 @@
bind:expandedSection
bind:buildingInsights
bind:configId
bind:panelCapacityWatts
bind:panelCapacityWattsInput
bind:showPanels
{googleMapsApiKey}
{geometryLibrary}
Expand All @@ -87,10 +87,10 @@
<SolarPotentialSection
bind:expandedSection
bind:configId
bind:monthlyAverageEnergyBill
bind:energyCostPerKwh
bind:panelCapacityWatts
bind:dcToAcDerate
bind:monthlyAverageEnergyBillInput
bind:energyCostPerKwhInput
bind:panelCapacityWattsInput
bind:dcToAcDerateInput
solarPanelConfigs={buildingInsights.solarPotential.solarPanelConfigs}
defaultPanelCapacityWatts={buildingInsights.solarPotential.panelCapacityWatts}
/>
Expand Down
131 changes: 75 additions & 56 deletions src/routes/sections/SolarPotentialSection.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -36,83 +36,102 @@
export let expandedSection: string;
export let configId: number;
export let monthlyAverageEnergyBill: number;
export let energyCostPerKwh: number;
export let panelCapacityWatts: number;
export let dcToAcDerate: number;
export let monthlyAverageEnergyBillInput: number;
export let energyCostPerKwhInput: number;
export let panelCapacityWattsInput: number;
export let dcToAcDerateInput: number;
export let solarPanelConfigs: SolarPanelConfig[];
export let defaultPanelCapacityWatts: number;
const icon = 'payments';
const title = 'Solar Potential analysis';
let costChart: HTMLElement;
let showAdvancedSettings = false;
// [START solar_potential_calculations]
// Solar configuration, from buildingInsights.solarPotential.solarPanelConfigs
let panelsCount = 20;
let yearlyEnergyDcKwh = 12000;
// Basic settings
let panelCapacityRatio = 1.0;
$: panelCapacityRatio = panelCapacityWatts / defaultPanelCapacityWatts;
let monthlyAverageEnergyBill: number = 300;
let energyCostPerKwh = 0.31;
let panelCapacityWatts = 400;
let solarIncentives: number = 7000;
let installationCostPerWatt: number = 4.0;
let installationLifeSpan = 20;
let installationLifeSpan: number = 20;
// Advanced settings
let dcToAcDerate = 0.85;
let efficiencyDepreciationFactor = 0.995;
let costIncreaseFactor = 1.022;
let discountRate = 1.04;
// Calculations
let installationCostTotal: number;
$: installationCostTotal = installationCostPerWatt * installationSizeKw * 1000;
// Solar installation
let installationSizeKw: number = panelsCount * panelCapacityWatts / 1000;
let installationCostTotal: number = installationCostPerWatt * installationSizeKw * 1000;
let costChart: HTMLElement;
let showAdvancedSettings = false;
// Energy consumption
let monthlyKwhEnergyConsumption: number = monthlyAverageEnergyBill / energyCostPerKwh;
let yearlyKwhEnergyConsumption: number = monthlyKwhEnergyConsumption * 12;
let installationSizeKw: number;
$: if (solarPanelConfigs[configId]) {
installationSizeKw = (solarPanelConfigs[configId].panelsCount * panelCapacityWatts) / 1000;
}
// Energy produced for installation life span
let initialAcKwhPerYear: number = yearlyEnergyDcKwh * dcToAcDerate;
let yearlyProductionAcKwh: number[] = [...Array(installationLifeSpan).keys()].map(
(year) => initialAcKwhPerYear * efficiencyDepreciationFactor ** year,
);
let monthlyKwhEnergyConsumption: number;
$: monthlyKwhEnergyConsumption = monthlyAverageEnergyBill / energyCostPerKwh;
// 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)}`)
let yearlyKwhEnergyConsumption: number;
$: yearlyKwhEnergyConsumption = monthlyKwhEnergyConsumption * 12;
// Savings with solar for installation life span
let savings: number = totalCostWithoutSolar - totalCostWithSolar;
console.log(`Savings: \$${savings.toFixed(2)} in ${installationLifeSpan} years`)
// [END solar_potential_calculations]
let initialAcKwhPerYear: number;
// Reactive calculations
let panelCapacityRatio: number = 1.0;
$: panelCapacityRatio = panelCapacityWattsInput / defaultPanelCapacityWatts;
$: installationCostTotal = installationCostPerWatt * installationSizeKw * 1000;
$: if (solarPanelConfigs[configId]) {
installationSizeKw = solarPanelConfigs[configId].panelsCount * panelCapacityWattsInput / 1000;
}
$: monthlyKwhEnergyConsumption = monthlyAverageEnergyBillInput / energyCostPerKwhInput;
$: yearlyKwhEnergyConsumption = monthlyKwhEnergyConsumption * 12;
$: if (solarPanelConfigs[configId]) {
initialAcKwhPerYear =
solarPanelConfigs[configId].yearlyEnergyDcKwh * panelCapacityRatio * dcToAcDerate;
solarPanelConfigs[configId].yearlyEnergyDcKwh * panelCapacityRatio * dcToAcDerateInput;
}
let yearlyProductionAcKwh: number[];
$: yearlyProductionAcKwh = [...Array(installationLifeSpan).keys()].map(
(year) => initialAcKwhPerYear * efficiencyDepreciationFactor ** year,
);
let yearlyUtilityBillEstimates: number[];
$: yearlyUtilityBillEstimates = yearlyProductionAcKwh.map((yearlyKwhEnergyProduced, year) =>
Math.max(
((yearlyKwhEnergyConsumption - yearlyKwhEnergyProduced) *
energyCostPerKwh *
costIncreaseFactor ** year) /
discountRate ** year,
0,
),
);
let remainingLifetimeUtilityBill: number;
$: yearlyUtilityBillEstimates = yearlyProductionAcKwh.map((yearlyKwhEnergyProduced, year) => {
const billEnergyKwh = yearlyKwhEnergyConsumption - yearlyKwhEnergyProduced;
const billEstimate = (billEnergyKwh * energyCostPerKwhInput * costIncreaseFactor ** year) / discountRate ** year;
return Math.max(billEstimate, 0); // bill cannot be negative
});
$: remainingLifetimeUtilityBill = yearlyUtilityBillEstimates.reduce((x, y) => x + y, 0);
let costOfElectricityWithoutSolar: number;
let yearlyCostWithoutSolar: number[];
$: totalCostWithSolar = installationCostTotal + remainingLifetimeUtilityBill - solarIncentives;
$: yearlyCostWithoutSolar = [...Array(installationLifeSpan).keys()].map(
(year) => (monthlyAverageEnergyBill * 12 * costIncreaseFactor ** year) / discountRate ** year,
(year) => (monthlyAverageEnergyBillInput * 12 * costIncreaseFactor ** year) / discountRate ** year,
);
$: costOfElectricityWithoutSolar = yearlyCostWithoutSolar.reduce((x, y) => x + y, 0);
let totalCostWithSolar: number;
$: totalCostWithSolar = installationCostTotal + remainingLifetimeUtilityBill - solarIncentives;
let savings: number;
$: savings = costOfElectricityWithoutSolar - totalCostWithSolar;
$: totalCostWithoutSolar = yearlyCostWithoutSolar.reduce((x, y) => x + y, 0);
$: savings = totalCostWithoutSolar - totalCostWithSolar;
let energyCovered: number;
$: energyCovered = yearlyProductionAcKwh[0] / yearlyKwhEnergyConsumption;
Expand Down Expand Up @@ -163,14 +182,14 @@
);
function updateConfig() {
monthlyKwhEnergyConsumption = monthlyAverageEnergyBill / energyCostPerKwh;
monthlyKwhEnergyConsumption = monthlyAverageEnergyBillInput / energyCostPerKwhInput;
yearlyKwhEnergyConsumption = monthlyKwhEnergyConsumption * 12;
panelCapacityRatio = panelCapacityWatts / defaultPanelCapacityWatts;
panelCapacityRatio = panelCapacityWattsInput / defaultPanelCapacityWatts;
configId = findSolarConfig(
solarPanelConfigs,
yearlyKwhEnergyConsumption,
panelCapacityRatio,
dcToAcDerate,
dcToAcDerateInput,
);
}
</script>
Expand Down Expand Up @@ -202,7 +221,7 @@
</div>

<InputMoney
bind:value={monthlyAverageEnergyBill}
bind:value={monthlyAverageEnergyBillInput}
icon="credit_card"
label="Monthly average energy bill"
onChange={updateConfig}
Expand All @@ -218,7 +237,7 @@
</div>

<InputMoney
bind:value={energyCostPerKwh}
bind:value={energyCostPerKwhInput}
icon="paid"
label="Energy cost per kWh"
onChange={updateConfig}
Expand All @@ -239,7 +258,7 @@
/>

<InputNumber
bind:value={panelCapacityWatts}
bind:value={panelCapacityWattsInput}
icon="bolt"
label="Panel capacity"
suffix="Watts"
Expand Down Expand Up @@ -270,7 +289,7 @@
/>

<InputPercent
bind:value={dcToAcDerate}
bind:value={dcToAcDerateInput}
icon="dynamic_form"
label="DC to AC conversion "
onChange={updateConfig}
Expand Down Expand Up @@ -366,7 +385,7 @@
{
icon: 'wallet',
name: 'Cost without solar',
value: showMoney(costOfElectricityWithoutSolar),
value: showMoney(totalCostWithoutSolar),
},
{
icon: 'wb_sunny',
Expand Down

0 comments on commit 847319f

Please sign in to comment.