Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
Calculate predicted energy cost
Browse files Browse the repository at this point in the history
  • Loading branch information
floriandejonckheere committed Dec 9, 2023
1 parent 695d735 commit cfc496a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
19 changes: 13 additions & 6 deletions src/api/queries/realtime_summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,18 @@ export const useRealtimeSummary = () => {
}
}

const totalPower =
data.pload_L1.value[data.pload_L1.value.length - 1] +
data.pload_L2.value[data.pload_L2.value.length - 1] +
data.pload_L3.value[data.pload_L3.value.length - 1]

const energyPrice = Math.avg(data.Spot_price.value)

// Calculate energy cost over 24 hours
const energyCost = (totalPower / 1000) * energyPrice

const summary: RealtimeSummary = {
totalPower:
data.pload_L1.value[data.pload_L1.value.length - 1] +
data.pload_L2.value[data.pload_L2.value.length - 1] +
data.pload_L3.value[data.pload_L3.value.length - 1],
totalPower,
voltage: Math.avg([
data.ul_L1.value[data.ul_L1.value.length - 1],
data.ul_L2.value[data.ul_L2.value.length - 1],
Expand All @@ -75,8 +82,8 @@ export const useRealtimeSummary = () => {
data.il_L1.value[data.il_L1.value.length - 1] +
data.il_L2.value[data.il_L2.value.length - 1] +
data.il_L3.value[data.il_L3.value.length - 1],
energyPrice: Math.avg(data.Spot_price.value),
energyCost: 0
energyPrice,
energyCost
}

return {
Expand Down
12 changes: 4 additions & 8 deletions src/components/cards/realtime_summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,20 @@ export default function RealtimeSummary(): ReactElement {
▲ 8%
</span>
</p>
<p className="text-xs text-gray-400 dark:text-slate-400">
Since yesterday
</p>
<p className="text-xs text-gray-400 dark:text-slate-400">Today</p>
</div>
<div className="text-right">
<h5 className="text-sm text-gray-500 font-semibold dark:text-slate-400">
Predicted energy cost
</h5>
<p className="mt-1 text-3xl font-bold flex justify-end items-center dark:text-slate-300">
0.31&nbsp;
<span className="text-xl">&euro;/h</span>
{isSuccess && (summary.energyCost / 100).toFixed(2)}&nbsp;
<span className="text-xl">c&euro;/h</span>
<span className="mx-2 px-1.5 py-1 rounded-sm text-xs font-medium bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-300">
&#9660; 75%
</span>
</p>
<p className="text-xs text-gray-400 dark:text-slate-400">
Since yesterday
</p>
<p className="text-xs text-gray-400 dark:text-slate-400">Today</p>
</div>
</div>
</div>
Expand Down

0 comments on commit cfc496a

Please sign in to comment.