Adding the energy cost from 2 to 3 decimal precision (#416)

* Adding the energy cost from 2 to 3 decimal precision

* Complying with pr

* Complying with PR

* Complying with PR

* Fix energy cost display precision in ProjectDetailPage

* Change energy cost formatting to two decimal places

* Change decimal precision for energy cost display

---------

Co-authored-by: MartinNYHC <mz@v8w.de>
This commit is contained in:
Wesley Reuel Marques Silva
2026-02-20 16:23:00 +01:00
committed by GitHub
co-authored by MartinNYHC
parent 57920d116a
commit ceb2de7164
7 changed files with 10 additions and 10 deletions
+2 -2
View File
@@ -570,7 +570,7 @@ async def get_archive_stats(
total_energy_kwh += mqtt_data.energy
total_energy_kwh = round(total_energy_kwh, 3)
total_energy_cost = round(total_energy_kwh * energy_cost_per_kwh, 2)
total_energy_cost = round(total_energy_kwh * energy_cost_per_kwh, 3)
else:
# Print mode: sum up per-print energy from archives
energy_kwh_result = await db.execute(select(func.sum(PrintArchive.energy_kwh)))
@@ -591,7 +591,7 @@ async def get_archive_stats(
average_time_accuracy=average_accuracy,
time_accuracy_by_printer=accuracy_by_printer if accuracy_by_printer else None,
total_energy_kwh=round(total_energy_kwh, 3),
total_energy_cost=round(total_energy_cost, 2),
total_energy_cost=round(total_energy_cost, 3),
)
+1 -1
View File
@@ -144,7 +144,7 @@ async def compute_project_stats(
parts_progress_percent=parts_progress_percent,
estimated_cost=round((sums.total_filament_cost or 0), 2),
total_energy_kwh=round((sums.total_energy or 0), 3),
total_energy_cost=round((sums.total_energy_cost or 0), 2),
total_energy_cost=round((sums.total_energy_cost or 0), 3),
remaining_prints=remaining_prints,
remaining_parts=remaining_parts,
bom_total_items=bom_stats.total or 0,
+1 -1
View File
@@ -2447,7 +2447,7 @@ async def on_print_complete(printer_id: int, data: dict):
energy_cost_per_kwh = await get_setting(db, "energy_cost_per_kwh")
cost_per_kwh = float(energy_cost_per_kwh) if energy_cost_per_kwh else 0.15
energy_cost = round(energy_used * cost_per_kwh, 2)
energy_cost = round(energy_used * cost_per_kwh, 3)
from backend.app.models.archive import PrintArchive
+1 -1
View File
@@ -265,7 +265,7 @@ export function SmartPlugCard({ plug, onEdit }: SmartPlugCardProps) {
)}
{status.energy.today !== null && status.energy.today !== undefined && (
<div className="flex-1 text-center border-l border-bambu-dark-tertiary">
<p className="text-lg font-semibold text-white">{status.energy.today.toFixed(2)}</p>
<p className="text-lg font-semibold text-white">{status.energy.today.toFixed(3)}</p>
<p className="text-xs text-bambu-gray">kWh Today</p>
</div>
)}
+1 -1
View File
@@ -640,7 +640,7 @@ export function ProjectDetailPage() {
<div>
<p className="text-xs text-bambu-gray uppercase">{t('projectDetail.cost.energy')}</p>
<p className="text-lg font-semibold text-white">
{stats.total_energy_kwh.toFixed(2)} kWh
{stats.total_energy_kwh.toFixed(3)} kWh
{stats.total_energy_cost > 0 && (
<span className="text-sm text-bambu-gray ml-1">
({currency}{stats.total_energy_cost.toFixed(2)})
+3 -3
View File
@@ -1527,7 +1527,7 @@ export function SettingsPage() {
</span>
<input
type="number"
step="0.01"
step="0.001"
min="0"
value={localSettings.energy_cost_per_kwh}
onChange={(e) =>
@@ -2580,7 +2580,7 @@ export function SettingsPage() {
Today
</div>
<div className="text-xl font-bold text-white">
{plugEnergySummary.totalToday.toFixed(2)}
{plugEnergySummary.totalToday.toFixed(3)}
<span className="text-sm font-normal text-bambu-gray ml-1">kWh</span>
</div>
{(localSettings?.energy_cost_per_kwh ?? 0) > 0 && (
@@ -2597,7 +2597,7 @@ export function SettingsPage() {
Yesterday
</div>
<div className="text-xl font-bold text-white">
{plugEnergySummary.totalYesterday.toFixed(2)}
{plugEnergySummary.totalYesterday.toFixed(3)}
<span className="text-sm font-normal text-bambu-gray ml-1">kWh</span>
</div>
{(localSettings?.energy_cost_per_kwh ?? 0) > 0 && (
+1 -1
View File
@@ -91,7 +91,7 @@ function QuickStatsWidget({
</div>
<div>
<p className="text-xs text-bambu-gray">{t('stats.energyUsed')}</p>
<p className="text-xl font-bold text-white">{stats?.total_energy_kwh.toFixed(2) || '0.00'} kWh</p>
<p className="text-xl font-bold text-white">{stats?.total_energy_kwh.toFixed(3) || '0.000'} kWh</p>
</div>
</div>
<div className="flex items-start gap-3">