Slice-Watch mit Ordnern/Filtern, Orca-Nachbearbeitung, Cockpit-Verlauf mit ED, Zeitzone im Browser. Tasten-Grenze und README-API angeglichen, toter Code entfernt, Requirements gepinnt.
52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
"""ED-Stromschätzung."""
|
|
|
|
import unittest
|
|
from datetime import datetime, timezone
|
|
|
|
from grotti.cost import energy_estimate
|
|
|
|
|
|
def sample_at(offset_s, np=None, bp=None):
|
|
base = datetime(2026, 10, 17, 15, 0, tzinfo=timezone.utc).timestamp()
|
|
at = datetime.fromtimestamp(base + offset_s, tz=timezone.utc).isoformat()
|
|
return {"sampled_at": at, "nozzle_power": np, "bed_power": bp}
|
|
|
|
|
|
class EnergyEdTests(unittest.TestCase):
|
|
def test_flat_without_heater_watts(self):
|
|
est = energy_estimate(3600, {"watts": 100, "euro_per_kwh": 0.5}, [
|
|
sample_at(0, np=1.0, bp=1.0),
|
|
sample_at(1800, np=1.0, bp=1.0),
|
|
])
|
|
self.assertEqual(est["source"], "flat")
|
|
self.assertAlmostEqual(est["kwh"], 0.1)
|
|
self.assertAlmostEqual(est["cost"], 0.05)
|
|
|
|
def test_ed_caps_long_gaps(self):
|
|
# 60 min Lücke → nur 90 s werden gezählt
|
|
samples = [sample_at(0, np=0.5, bp=0.0), sample_at(3600, np=0.5, bp=0.0)]
|
|
est = energy_estimate(3600, {
|
|
"watts": 0,
|
|
"nozzle_watts": 100,
|
|
"bed_watts": 0,
|
|
"euro_per_kwh": 1,
|
|
}, samples)
|
|
self.assertEqual(est["source"], "ed")
|
|
self.assertAlmostEqual(est["print_kwh"], (100 * 0.5 / 1000) * (90 / 3600), places=6)
|
|
|
|
def test_ed_dense_samples_full_hour(self):
|
|
samples = [sample_at(i * 30, np=1.0, bp=0.0) for i in range(0, 121)]
|
|
est = energy_estimate(3600, {
|
|
"watts": 0,
|
|
"nozzle_watts": 200,
|
|
"bed_watts": 0,
|
|
"euro_per_kwh": 2,
|
|
}, samples)
|
|
self.assertEqual(est["source"], "ed")
|
|
self.assertAlmostEqual(est["print_kwh"], 0.2, places=3)
|
|
self.assertAlmostEqual(est["cost"], 0.4, places=3)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|