From ba8bfb6e14561b4b675296c9a7b37946ad92aeda Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Fri, 3 Feb 2023 21:05:21 -0500 Subject: [PATCH] #101 fixed averages and display them --- coordinator/iocontrol.lua | 6 ++--- coordinator/startup.lua | 2 +- coordinator/ui/components/imatrix.lua | 33 +++++++++++++++++---------- scada-common/util.lua | 2 +- supervisor/session/facility.lua | 24 +++++++++---------- supervisor/startup.lua | 2 +- 6 files changed, 39 insertions(+), 30 deletions(-) diff --git a/coordinator/iocontrol.lua b/coordinator/iocontrol.lua index 2502027..d5b0a54 100644 --- a/coordinator/iocontrol.lua +++ b/coordinator/iocontrol.lua @@ -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 diff --git a/coordinator/startup.lua b/coordinator/startup.lua index 3052ed0..f8d3406 100644 --- a/coordinator/startup.lua +++ b/coordinator/startup.lua @@ -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 diff --git a/coordinator/ui/components/imatrix.lua b/coordinator/ui/components/imatrix.lua index 62d7dbf..c14e910 100644 --- a/coordinator/ui/components/imatrix.lua +++ b/coordinator/ui/components/imatrix.lua @@ -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 diff --git a/scada-common/util.lua b/scada-common/util.lua index 8b88758..56cacd7 100644 --- a/scada-common/util.lua +++ b/scada-common/util.lua @@ -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) diff --git a/supervisor/session/facility.lua b/supervisor/session/facility.lua index ebd417a..a63dfd2 100644 --- a/supervisor/session/facility.lua +++ b/supervisor/session/facility.lua @@ -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) diff --git a/supervisor/startup.lua b/supervisor/startup.lua index 3832894..ae879f4 100644 --- a/supervisor/startup.lua +++ b/supervisor/startup.lua @@ -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