#101 fixed averages and display them

This commit is contained in:
Mikayla Fischler 2023-02-03 21:05:21 -05:00
parent a117d5ee97
commit ba8bfb6e14
6 changed files with 39 additions and 30 deletions

View File

@ -307,9 +307,9 @@ function iocontrol.update_facility_status(status)
if type(rtu_statuses) == "table" then
-- power statistics
if type(rtu_statuses.power) == "table" then
fac.ps.publish("avg_charge", rtu_statuses.power[1])
fac.ps.publish("avg_inflow", rtu_statuses.power[2])
fac.ps.publish("avg_outflow", rtu_statuses.power[3])
fac.induction_ps_tbl[1].publish("avg_charge", rtu_statuses.power[1])
fac.induction_ps_tbl[1].publish("avg_inflow", rtu_statuses.power[2])
fac.induction_ps_tbl[1].publish("avg_outflow", rtu_statuses.power[3])
else
log.debug(log_header .. "power statistics list not a table")
end

View File

@ -19,7 +19,7 @@ local iocontrol = require("coordinator.iocontrol")
local renderer = require("coordinator.renderer")
local sounder = require("coordinator.sounder")
local COORDINATOR_VERSION = "beta-v0.8.15"
local COORDINATOR_VERSION = "beta-v0.8.16"
local print = util.print
local println = util.println

View File

@ -24,16 +24,17 @@ local TEXT_ALIGN = core.graphics.TEXT_ALIGN
---@param y integer top left y
---@param data imatrix_session_db matrix data
---@param ps psil ps interface
---@param id number? matrix ID
local function new_view(root, x, y, data, ps, id)
local title = "INDUCTION MATRIX"
if type(id) == "number" then title = title .. id end
local matrix = Div{parent=root,fg_bg=style.root,width=33,height=21,x=x,y=y}
local matrix = Div{parent=root,fg_bg=style.root,width=33,height=25,x=x,y=y}
TextBox{parent=matrix,text=" ",width=33,height=1,x=1,y=1,fg_bg=cpair(colors.lightGray,colors.gray)}
TextBox{parent=matrix,text=title,alignment=TEXT_ALIGN.CENTER,width=33,height=1,x=1,y=2,fg_bg=cpair(colors.lightGray,colors.gray)}
local rect = Rectangle{parent=matrix,border=border(1, colors.gray, true),width=33,height=18,x=1,y=3}
local rect = Rectangle{parent=matrix,border=border(1,colors.gray,true),width=33,height=22,x=1,y=3}
local text_fg_bg = cpair(colors.black, colors.lightGray)
local label_fg_bg = cpair(colors.gray, colors.lightGray)
@ -45,31 +46,39 @@ local function new_view(root, x, y, data, ps, id)
local input = PowerIndicator{parent=rect,x=7,y=5,lu_colors=lu_col,label="Input: ",format="%8.2f",rate=true,value=0,width=26,fg_bg=text_fg_bg}
local output = PowerIndicator{parent=rect,x=7,y=6,lu_colors=lu_col,label="Output: ",format="%8.2f",rate=true,value=0,width=26,fg_bg=text_fg_bg}
local avg_chg = PowerIndicator{parent=rect,x=7,y=8,lu_colors=lu_col,label="Avg. Chg:",format="%8.2f",value=0,width=26,fg_bg=text_fg_bg}
local avg_in = PowerIndicator{parent=rect,x=7,y=9,lu_colors=lu_col,label="Avg. In: ",format="%8.2f",rate=true,value=0,width=26,fg_bg=text_fg_bg}
local avg_out = PowerIndicator{parent=rect,x=7,y=10,lu_colors=lu_col,label="Avg. Out:",format="%8.2f",rate=true,value=0,width=26,fg_bg=text_fg_bg}
ps.subscribe("computed_status", status.update)
ps.subscribe("energy", function (val) energy.update(util.joules_to_fe(val)) end)
ps.subscribe("max_energy", function (val) capacity.update(util.joules_to_fe(val)) end)
ps.subscribe("last_input", function (val) input.update(util.joules_to_fe(val)) end)
ps.subscribe("last_output", function (val) output.update(util.joules_to_fe(val)) end)
local fill = DataIndicator{parent=rect,x=11,y=8,lu_colors=lu_col,label="Fill:",unit="%",format="%8.2f",value=0,width=18,fg_bg=text_fg_bg}
ps.subscribe("avg_charge", avg_chg.update)
ps.subscribe("avg_inflow", avg_in.update)
ps.subscribe("avg_outflow", avg_out.update)
local cells = DataIndicator{parent=rect,x=11,y=10,lu_colors=lu_col,label="Cells: ",format="%7d",value=0,width=18,fg_bg=text_fg_bg}
local providers = DataIndicator{parent=rect,x=11,y=11,lu_colors=lu_col,label="Providers:",format="%7d",value=0,width=18,fg_bg=text_fg_bg}
local fill = DataIndicator{parent=rect,x=11,y=12,lu_colors=lu_col,label="Fill:",unit="%",format="%8.2f",value=0,width=18,fg_bg=text_fg_bg}
TextBox{parent=rect,text="Transfer Capacity",x=11,y=13,height=1,width=17,fg_bg=label_fg_bg}
local trans_cap = PowerIndicator{parent=rect,x=19,y=14,lu_colors=lu_col,label="",format="%5.2f",rate=true,value=0,width=12,fg_bg=text_fg_bg}
local cells = DataIndicator{parent=rect,x=11,y=14,lu_colors=lu_col,label="Cells: ",format="%7d",value=0,width=18,fg_bg=text_fg_bg}
local providers = DataIndicator{parent=rect,x=11,y=15,lu_colors=lu_col,label="Providers:",format="%7d",value=0,width=18,fg_bg=text_fg_bg}
TextBox{parent=rect,text="Transfer Capacity",x=11,y=17,height=1,width=17,fg_bg=label_fg_bg}
local trans_cap = PowerIndicator{parent=rect,x=19,y=18,lu_colors=lu_col,label="",format="%5.2f",rate=true,value=0,width=12,fg_bg=text_fg_bg}
ps.subscribe("cells", cells.update)
ps.subscribe("providers", providers.update)
ps.subscribe("energy_fill", function (val) fill.update(val * 100) end)
ps.subscribe("transfer_cap", function (val) trans_cap.update(util.joules_to_fe(val)) end)
local charge = VerticalBar{parent=rect,x=2,y=2,fg_bg=cpair(colors.green,colors.gray),height=13,width=4}
local in_cap = VerticalBar{parent=rect,x=7,y=8,fg_bg=cpair(colors.red,colors.gray),height=7,width=1}
local out_cap = VerticalBar{parent=rect,x=9,y=8,fg_bg=cpair(colors.blue,colors.gray),height=7,width=1}
local charge = VerticalBar{parent=rect,x=2,y=2,fg_bg=cpair(colors.green,colors.gray),height=17,width=4}
local in_cap = VerticalBar{parent=rect,x=7,y=12,fg_bg=cpair(colors.red,colors.gray),height=7,width=1}
local out_cap = VerticalBar{parent=rect,x=9,y=12,fg_bg=cpair(colors.blue,colors.gray),height=7,width=1}
TextBox{parent=rect,text="FILL",x=2,y=16,height=1,width=4,fg_bg=text_fg_bg}
TextBox{parent=rect,text="I/O",x=7,y=16,height=1,width=3,fg_bg=text_fg_bg}
TextBox{parent=rect,text="FILL",x=2,y=20,height=1,width=4,fg_bg=text_fg_bg}
TextBox{parent=rect,text="I/O",x=7,y=20,height=1,width=3,fg_bg=text_fg_bg}
local function calc_saturation(val)
if (type(data.build) == "table") and (type(data.build.transfer_cap) == "number") and (data.build.transfer_cap > 0) then

View File

@ -253,7 +253,7 @@ function util.mov_avg(length, default)
function public.compute()
local sum = 0
for i = 1, length do sum = sum + data[i] end
return sum
return sum / length
end
public.reset(default)

View File

@ -65,9 +65,9 @@ function facility.new(num_reactors, cooling_conf)
last_time = 0.0,
-- statistics
im_stat_init = false,
avg_charge = util.mov_avg(10, 0.0),
avg_inflow = util.mov_avg(10, 0.0),
avg_outflow = util.mov_avg(10, 0.0)
avg_charge = util.mov_avg(20, 0.0),
avg_inflow = util.mov_avg(20, 0.0),
avg_outflow = util.mov_avg(20, 0.0)
}
-- create units
@ -185,14 +185,14 @@ function facility.new(num_reactors, cooling_conf)
if (db.state.last_update > 0) and (db.tanks.last_update > 0) then
if self.im_stat_init then
self.avg_charge.record(db.tanks.energy, db.tanks.last_update)
self.avg_inflow.record(db.state.last_input, db.state.last_update)
self.avg_outflow.record(db.state.last_output, db.state.last_update)
self.avg_charge.record(util.joules_to_fe(db.tanks.energy), db.tanks.last_update)
self.avg_inflow.record(util.joules_to_fe(db.state.last_input), db.state.last_update)
self.avg_outflow.record(util.joules_to_fe(db.state.last_output), db.state.last_update)
else
self.im_stat_init = true
self.avg_charge.reset(db.tanks.energy)
self.avg_inflow.reset(db.state.last_input)
self.avg_outflow.reset(db.state.last_output)
self.avg_charge.reset(util.joules_to_fe(db.tanks.energy))
self.avg_inflow.reset(util.joules_to_fe(db.state.last_input))
self.avg_outflow.reset(util.joules_to_fe(db.state.last_output))
end
end
else
@ -586,9 +586,9 @@ function facility.new(num_reactors, cooling_conf)
-- power averages from induction matricies
status.power = {
self.avg_charge,
self.avg_inflow,
self.avg_outflow
self.avg_charge.compute(),
self.avg_inflow.compute(),
self.avg_outflow.compute()
}
-- status of induction matricies (including tanks)

View File

@ -14,7 +14,7 @@ local svsessions = require("supervisor.session.svsessions")
local config = require("supervisor.config")
local supervisor = require("supervisor.supervisor")
local SUPERVISOR_VERSION = "beta-v0.9.10"
local SUPERVISOR_VERSION = "beta-v0.9.11"
local print = util.print
local println = util.println