Merge branch 'cost'

master
jbruce 2022-10-13 12:47:09 -04:00
commit 4868cf33c0
5 zmienionych plików z 35 dodań i 4 usunięć

Wyświetl plik

@ -14,10 +14,17 @@ log_format = '%(asctime)s %(levelname)s %(name)s: %(message)s'
### Server
listening_ip = "0.0.0.0"
listening_port = 8081
listening_port = 8082
### Cost Estimate
kwh_rate = 0.1319 # Rate in currency_type to calculate cost to run job
########################################################################
# Cost Information
#
# This is used to calculate a cost estimate before a run. It's also used
# to produce the actual cost during a run. My kiln has three
# elements that when my switches are set to high, consume 9460 watts.
kwh_rate = 0.1319 # cost per kilowatt hour per currency_type to calculate cost to run job
kw_elements = 9.460 # if the kiln elements are on, the wattage in kilowatts
currency_type = "$" # Currency Symbol to show when calculating cost to run job
########################################################################
@ -173,3 +180,11 @@ automatic_restarts = True
automatic_restart_window = 15 # max minutes since power outage
automatic_restart_state_file = os.path.abspath(os.path.join(os.path.dirname( __file__ ),'state.json'))
########################################################################
# load kiln profiles from this directory
# created a repo where anyone can contribute profiles. The objective is
# to load profiles from this repository by default.
# See https://github.com/jbruce12000/kiln-profiles
kiln_profiles_directory = os.path.abspath(os.path.join(os.path.dirname( __file__ ),"storage", "profiles"))
#kiln_profiles_directory = os.path.abspath(os.path.join(os.path.dirname( __file__ ),'..','kiln-profiles','pottery'))

Wyświetl plik

@ -28,7 +28,7 @@ log.info("Starting kiln controller")
script_dir = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, script_dir + '/lib/')
profile_path = os.path.join(script_dir, "storage", "profiles")
profile_path = config.kiln_profiles_directory
from oven import SimulatedOven, RealOven, Profile
from ovenWatcher import OvenWatcher

Wyświetl plik

@ -204,6 +204,7 @@ class Oven(threading.Thread):
self.reset()
def reset(self):
self.cost = 0
self.state = "IDLE"
self.profile = None
self.start_time = 0
@ -294,8 +295,16 @@ class Oven(threading.Thread):
def reset_if_schedule_ended(self):
if self.runtime > self.totaltime:
log.info("schedule ended, shutting down")
log.info("total cost = %s%.2f" % (config.currency_type,self.cost))
self.abort_run()
def update_cost(self):
if self.heat:
cost = (config.kwh_rate * config.kw_elements) * ((self.heat)/3600)
else:
cost = 0
self.cost = self.cost + cost
def get_state(self):
temp = 0
try:
@ -306,6 +315,7 @@ class Oven(threading.Thread):
pass
state = {
'cost': self.cost,
'runtime': self.runtime,
'temperature': temp,
'target': self.target,
@ -368,6 +378,7 @@ class Oven(threading.Thread):
profile_json = json.dumps(json.load(infile))
profile = Profile(profile_json)
self.run_profile(profile,startat=startat)
self.cost = d["cost"]
time.sleep(1)
self.ovenwatcher.record(profile)
@ -383,6 +394,7 @@ class Oven(threading.Thread):
time.sleep(1)
continue
if self.state == "RUNNING":
self.update_cost()
self.save_automatic_restart_state()
self.kiln_must_catch_up()
self.update_runtime()

Wyświetl plik

@ -548,6 +548,8 @@ $(document).ready(function()
updateProgress(parseFloat(x.runtime)/parseFloat(x.totaltime)*100);
$('#state').html('<span class="glyphicon glyphicon-time" style="font-size: 22px; font-weight: normal"></span><span style="font-family: Digi; font-size: 40px;">' + eta + '</span>');
$('#target_temp').html(parseInt(x.target));
$('#cost').html(x.currency_type + parseFloat(x.cost).toFixed(2));
}

Wyświetl plik

@ -29,12 +29,14 @@
<div class="ds-title-panel">
<div class="ds-title">Sensor Temp</div>
<div class="ds-title">Target Temp</div>
<div class="ds-title">Cost</div>
<div class="ds-title ds-state pull-right" style="border-left: 1px solid #ccc;">Status</div>
</div>
<div class="clearfix"></div>
<div class="ds-panel">
<div class="display ds-num"><span id="act_temp">25</span><span class="ds-unit" id="act_temp_scale" >&deg;C</span></div>
<div class="display ds-num ds-target"><span id="target_temp">---</span><span class="ds-unit" id="target_temp_scale">&deg;C</span></div>
<div class="display ds-num ds-cost"><span id="cost">0.00</span><span class="ds-unit" id="cost"></span></div>
<div class="display ds-num ds-text" id="state"></div>
<div class="display pull-right ds-state" style="padding-right:0"><span class="ds-led" id="heat">&#92;</span><span class="ds-led" id="cool">&#108;</span><span class="ds-led" id="air">&#91;</span><span class="ds-led" id="hazard">&#73;</span><span class="ds-led" id="door">&#9832;</span></div>
</div>