#72, #78 updated main view to adapt to facility configuration, initial use of pub/sub for main view

This commit is contained in:
Mikayla Fischler
2022-07-10 16:15:30 -04:00
parent 5a96818c97
commit 6f61203db3
6 changed files with 145 additions and 50 deletions

View File

@ -51,4 +51,7 @@ function database.init(conf)
end end
end end
-- get the database
function database.get() return db end
return database return database

View File

@ -14,7 +14,12 @@ local TEXT_ALIGN = core.graphics.TEXT_ALIGN
local cpair = core.graphics.cpair local cpair = core.graphics.cpair
local border = core.graphics.border local border = core.graphics.border
local function new_view(root, x, y) -- new boiler view
---@param root graphics_element
---@param x integer
---@param y integer
---@param ps psil
local function new_view(root, x, y, ps)
local boiler = Rectangle{parent=root,border=border(1, colors.gray, true),width=31,height=7,x=x,y=y} local boiler = Rectangle{parent=root,border=border(1, colors.gray, true),width=31,height=7,x=x,y=y}
local text_fg_bg = cpair(colors.black, colors.lightGray) local text_fg_bg = cpair(colors.black, colors.lightGray)
@ -24,6 +29,10 @@ local function new_view(root, x, y)
local temp = DataIndicator{parent=boiler,x=5,y=3,lu_colors=lu_col,label="Temp:",unit="K",format="%10.2f",value=1900,width=22,fg_bg=text_fg_bg} local temp = DataIndicator{parent=boiler,x=5,y=3,lu_colors=lu_col,label="Temp:",unit="K",format="%10.2f",value=1900,width=22,fg_bg=text_fg_bg}
local boil_r = DataIndicator{parent=boiler,x=5,y=4,lu_colors=lu_col,label="Boil:",unit="mB/t",format="%10.0f",value=801523,commas=true,width=22,fg_bg=text_fg_bg} local boil_r = DataIndicator{parent=boiler,x=5,y=4,lu_colors=lu_col,label="Boil:",unit="mB/t",format="%10.0f",value=801523,commas=true,width=22,fg_bg=text_fg_bg}
ps.subscribe("status", status.update)
ps.subscribe("temp", temp.update)
ps.subscribe("boil_rate", boil_r.update)
TextBox{parent=boiler,text="H",x=2,y=5,height=1,width=1,fg_bg=text_fg_bg} TextBox{parent=boiler,text="H",x=2,y=5,height=1,width=1,fg_bg=text_fg_bg}
TextBox{parent=boiler,text="W",x=3,y=5,height=1,width=1,fg_bg=text_fg_bg} TextBox{parent=boiler,text="W",x=3,y=5,height=1,width=1,fg_bg=text_fg_bg}
TextBox{parent=boiler,text="S",x=27,y=5,height=1,width=1,fg_bg=text_fg_bg} TextBox{parent=boiler,text="S",x=27,y=5,height=1,width=1,fg_bg=text_fg_bg}
@ -32,12 +41,17 @@ local function new_view(root, x, y)
local hcool = VerticalBar{parent=boiler,x=2,y=1,fg_bg=cpair(colors.orange,colors.gray),height=4,width=1} local hcool = VerticalBar{parent=boiler,x=2,y=1,fg_bg=cpair(colors.orange,colors.gray),height=4,width=1}
local water = VerticalBar{parent=boiler,x=3,y=1,fg_bg=cpair(colors.blue,colors.gray),height=4,width=1} local water = VerticalBar{parent=boiler,x=3,y=1,fg_bg=cpair(colors.blue,colors.gray),height=4,width=1}
local steam = VerticalBar{parent=boiler,x=27,y=1,fg_bg=cpair(colors.white,colors.gray),height=4,width=1} local steam = VerticalBar{parent=boiler,x=27,y=1,fg_bg=cpair(colors.white,colors.gray),height=4,width=1}
local cool = VerticalBar{parent=boiler,x=28,y=1,fg_bg=cpair(colors.lightBlue,colors.gray),height=4,width=1} local ccool = VerticalBar{parent=boiler,x=28,y=1,fg_bg=cpair(colors.lightBlue,colors.gray),height=4,width=1}
ps.subscribe("hcool", hcool.update)
ps.subscribe("water", water.update)
ps.subscribe("steam", steam.update)
ps.subscribe("ccool", ccool.update)
hcool.update(0.22) hcool.update(0.22)
water.update(1) water.update(1)
steam.update(0.05) steam.update(0.05)
cool.update(0.13) ccool.update(0.13)
end end
return new_view return new_view

View File

@ -14,7 +14,11 @@ local TEXT_ALIGN = core.graphics.TEXT_ALIGN
local cpair = core.graphics.cpair local cpair = core.graphics.cpair
local border = core.graphics.border local border = core.graphics.border
local function new_view(root, x, y) ---@param root graphics_element
---@param x integer
---@param y integer
---@param ps psil
local function new_view(root, x, y, ps)
local reactor = Rectangle{parent=root,border=border(1, colors.gray, true),width=30,height=7,x=x,y=y} local reactor = Rectangle{parent=root,border=border(1, colors.gray, true),width=30,height=7,x=x,y=y}
local text_fg_bg = cpair(colors.black, colors.lightGray) local text_fg_bg = cpair(colors.black, colors.lightGray)
@ -25,6 +29,11 @@ local function new_view(root, x, y)
local burn_r = DataIndicator{parent=reactor,x=2,y=4,lu_colors=lu_col,label="Burn Rate:",unit="mB/t",format="%10.1f",value=40.1,width=26,fg_bg=text_fg_bg} local burn_r = DataIndicator{parent=reactor,x=2,y=4,lu_colors=lu_col,label="Burn Rate:",unit="mB/t",format="%10.1f",value=40.1,width=26,fg_bg=text_fg_bg}
local heating_r = DataIndicator{parent=reactor,x=2,y=5,lu_colors=lu_col,label="Heating:",unit="mB/t",format="%12.0f",value=8015342,commas=true,width=26,fg_bg=text_fg_bg} local heating_r = DataIndicator{parent=reactor,x=2,y=5,lu_colors=lu_col,label="Heating:",unit="mB/t",format="%12.0f",value=8015342,commas=true,width=26,fg_bg=text_fg_bg}
ps.subscribe("status", status.update)
ps.subscribe("temp", core_temp.update)
ps.subscribe("burn_rate", burn_r.update)
ps.subscribe("heating_rate", heating_r.update)
local reactor_fills = Rectangle{parent=root,border=border(1, colors.gray, true),width=24,height=7,x=(x + 29),y=y} local reactor_fills = Rectangle{parent=root,border=border(1, colors.gray, true),width=24,height=7,x=(x + 29),y=y}
TextBox{parent=reactor_fills,text="FUEL",x=2,y=1,height=1,fg_bg=text_fg_bg} TextBox{parent=reactor_fills,text="FUEL",x=2,y=1,height=1,fg_bg=text_fg_bg}
@ -33,12 +42,17 @@ local function new_view(root, x, y)
TextBox{parent=reactor_fills,text="WASTE",x=2,y=5,height=1,fg_bg=text_fg_bg} TextBox{parent=reactor_fills,text="WASTE",x=2,y=5,height=1,fg_bg=text_fg_bg}
local fuel = HorizontalBar{parent=reactor_fills,x=8,y=1,show_percent=true,bar_fg_bg=cpair(colors.black,colors.gray),height=1,width=14} local fuel = HorizontalBar{parent=reactor_fills,x=8,y=1,show_percent=true,bar_fg_bg=cpair(colors.black,colors.gray),height=1,width=14}
local cool = HorizontalBar{parent=reactor_fills,x=8,y=2,show_percent=true,bar_fg_bg=cpair(colors.lightBlue,colors.gray),height=1,width=14} local ccool = HorizontalBar{parent=reactor_fills,x=8,y=2,show_percent=true,bar_fg_bg=cpair(colors.lightBlue,colors.gray),height=1,width=14}
local hcool = HorizontalBar{parent=reactor_fills,x=8,y=4,show_percent=true,bar_fg_bg=cpair(colors.orange,colors.gray),height=1,width=14} local hcool = HorizontalBar{parent=reactor_fills,x=8,y=4,show_percent=true,bar_fg_bg=cpair(colors.orange,colors.gray),height=1,width=14}
local waste = HorizontalBar{parent=reactor_fills,x=8,y=5,show_percent=true,bar_fg_bg=cpair(colors.brown,colors.gray),height=1,width=14} local waste = HorizontalBar{parent=reactor_fills,x=8,y=5,show_percent=true,bar_fg_bg=cpair(colors.brown,colors.gray),height=1,width=14}
ps.subscribe("fuel", fuel.update)
ps.subscribe("ccool", ccool.update)
ps.subscribe("hcool", hcool.update)
ps.subscribe("waste", waste.update)
fuel.update(1) fuel.update(1)
cool.update(0.85) ccool.update(0.85)
hcool.update(0.08) hcool.update(0.08)
waste.update(0.32) waste.update(0.32)
end end

View File

@ -14,18 +14,29 @@ local TEXT_ALIGN = core.graphics.TEXT_ALIGN
local cpair = core.graphics.cpair local cpair = core.graphics.cpair
local border = core.graphics.border local border = core.graphics.border
local function new_view(root, x, y) -- new turbine view
---@param root graphics_element
---@param x integer
---@param y integer
---@param ps psil
local function new_view(root, x, y, ps)
local turbine = Rectangle{parent=root,border=border(1, colors.gray, true),width=23,height=7,x=x,y=y} local turbine = Rectangle{parent=root,border=border(1, colors.gray, true),width=23,height=7,x=x,y=y}
local text_fg_bg = cpair(colors.black, colors.lightGray) local text_fg_bg = cpair(colors.black, colors.lightGray)
local lu_col = cpair(colors.gray, colors.gray) local lu_col = cpair(colors.gray, colors.gray)
local status = StateIndicator{parent=turbine,x=8,y=1,states=style.turbine.states,value=3,min_width=10} local status = StateIndicator{parent=turbine,x=8,y=1,states=style.turbine.states,value=3,min_width=10}
local production = DataIndicator{parent=turbine,x=5,y=3,lu_colors=lu_col,label="",unit="MFE",format="%10.2f",value=3.2,width=16,fg_bg=text_fg_bg} local prod_rate = DataIndicator{parent=turbine,x=5,y=3,lu_colors=lu_col,label="",unit="MFE",format="%10.2f",value=3.2,width=16,fg_bg=text_fg_bg}
local flow_rate = DataIndicator{parent=turbine,x=5,y=4,lu_colors=lu_col,label="",unit="mB/t",format="%10.0f",value=801523,commas=true,width=16,fg_bg=text_fg_bg} local flow_rate = DataIndicator{parent=turbine,x=5,y=4,lu_colors=lu_col,label="",unit="mB/t",format="%10.0f",value=801523,commas=true,width=16,fg_bg=text_fg_bg}
ps.subscribe("status", status.update)
ps.subscribe("prod_rate", prod_rate.update)
ps.subscribe("flow_rate", flow_rate.update)
local steam = VerticalBar{parent=turbine,x=2,y=1,fg_bg=cpair(colors.white,colors.gray),height=5,width=2} local steam = VerticalBar{parent=turbine,x=2,y=1,fg_bg=cpair(colors.white,colors.gray),height=5,width=2}
ps.subscribe("steam", steam.update)
steam.update(0.12) steam.update(0.12)
end end

View File

@ -17,25 +17,37 @@ local border = core.graphics.border
local pipe = core.graphics.pipe local pipe = core.graphics.pipe
---@param parent graphics_element ---@param parent graphics_element
local function make(parent, x, y, unit_id) ---@param x integer
---@param y integer
---@param unit coord_db_entry
local function make(parent, x, y, unit)
-- bounding box div -- bounding box div
local root = Div{parent=parent,x=x,y=y,width=80,height=25} local root = Div{parent=parent,x=x,y=y,width=80,height=25}
-- unit header message -- unit header message
TextBox{parent=root,text="Unit #" .. unit_id,alignment=TEXT_ALIGN.CENTER,height=1,fg_bg=style.header} TextBox{parent=root,text="Unit #" .. unit.unit_id,alignment=TEXT_ALIGN.CENTER,height=1,fg_bg=style.header}
local num_boilers = #unit.boiler_data_tbl
local num_turbines = #unit.turbine_data_tbl
------------- -------------
-- REACTOR -- -- REACTOR --
------------- -------------
reactor_view(root, 1, 3) reactor_view(root, 1, 3, unit.reactor_ps)
local coolant_pipes = { local coolant_pipes = {}
pipe(0, 0, 11, 12, colors.lightBlue),
pipe(0, 0, 11, 3, colors.lightBlue), if num_boilers == 2 then
pipe(2, 0, 11, 2, colors.orange), table.insert(coolant_pipes, pipe(0, 0, 11, 12, colors.lightBlue))
pipe(2, 0, 11, 11, colors.orange) end
}
table.insert(coolant_pipes, pipe(0, 0, 11, 3, colors.lightBlue))
table.insert(coolant_pipes, pipe(2, 0, 11, 2, colors.orange))
if num_boilers == 2 then
table.insert(coolant_pipes, pipe(2, 0, 11, 11, colors.orange))
end
PipeNetwork{parent=root,x=4,y=10,pipes=coolant_pipes,bg=colors.lightGray} PipeNetwork{parent=root,x=4,y=10,pipes=coolant_pipes,bg=colors.lightGray}
@ -43,41 +55,78 @@ local function make(parent, x, y, unit_id)
-- BOILERS -- -- BOILERS --
------------- -------------
boiler_view(root, 16, 11) boiler_view(root, 16, 11, unit.boiler_ps_tbl[1])
boiler_view(root, 16, 19) if num_boilers == 2 then boiler_view(root, 16, 19, unit.boiler_ps_tbl[2]) end
-------------- --------------
-- TURBINES -- -- TURBINES --
-------------- --------------
turbine_view(root, 58, 3) local t_idx = 1
turbine_view(root, 58, 11)
turbine_view(root, 58, 19) if num_turbines == 3 then
turbine_view(root, 58, 3, unit.turbine_ps_tbl[t_idx])
t_idx = t_idx + 1
end
if num_turbines >= 1 then
turbine_view(root, 58, 11, unit.turbine_ps_tbl[t_idx])
t_idx = t_idx + 1
end
if num_turbines >= 2 then turbine_view(root, 58, 19, unit.turbine_ps_tbl[t_idx]) end
local steam_pipes_a = { local steam_pipes_a = {
-- boiler 1 -- boiler 1 steam/water pipes
pipe(0, 1, 6, 1, colors.white, false, true), pipe(0, 1, 6, 1, colors.white, false, true), -- steam boiler 1 to turbine junction
pipe(0, 2, 6, 2, colors.blue, false, true), pipe(0, 2, 6, 2, colors.blue, false, true) -- water boiler 1 to turbine junction
-- boiler 2
pipe(0, 9, 6, 9, colors.white, false, true),
pipe(0, 10, 6, 10, colors.blue, false, true)
} }
local steam_pipes_b = { if num_boilers == 2 then
-- turbines 1 & 2, pipes from boiler 1 -- boiler 2 steam/water pipes
pipe(0, 9, 1, 2, colors.white, false, true), table.insert(steam_pipes_a, pipe(0, 9, 6, 9, colors.white, false, true)) -- steam boiler 2 to turbine junction
pipe(1, 1, 3, 1, colors.white, false, false), table.insert(steam_pipes_a, pipe(0, 10, 6, 10, colors.blue, false, true)) -- water boiler 2 to turbine junction
pipe(0, 9, 3, 9, colors.white, false, true), end
pipe(0, 10, 2, 3, colors.blue, false, true),
pipe(2, 2, 3, 2, colors.blue, false, false), local steam_pipes_b = {}
pipe(0, 10, 3, 10, colors.blue, false, true),
-- turbine 3, pipes from boiler 2 if num_turbines == 3 then
pipe(0, 18, 1, 9, colors.white, false, true), table.insert(steam_pipes_b, pipe(0, 9, 1, 2, colors.white, false, true)) -- steam boiler 1 to turbine 1 junction start
pipe(1, 1, 3, 1, colors.white, false, false), table.insert(steam_pipes_b, pipe(1, 1, 3, 1, colors.white, false, false)) -- steam boiler 1 to turbine 1 junction end
pipe(0, 17, 3, 17, colors.white, false, true), end
pipe(0, 18, 2, 10, colors.blue, false, true),
pipe(0, 18, 3, 18, colors.blue, false, true), table.insert(steam_pipes_b, pipe(0, 9, 3, 9, colors.white, false, true)) -- steam boiler 1 to turbine 2
}
if num_turbines == 3 then
table.insert(steam_pipes_b, pipe(0, 10, 2, 3, colors.blue, false, true)) -- water boiler 1 to turbine 1 junction start
table.insert(steam_pipes_b, pipe(2, 2, 3, 2, colors.blue, false, false)) -- water boiler 1 to turbine 1 junction end
end
table.insert(steam_pipes_b, pipe(0, 10, 3, 10, colors.blue, false, true)) -- water boiler 1 to turbine 2
if num_turbines >= 2 then
if num_boilers == 2 then
table.insert(steam_pipes_b, pipe(0, 17, 1, 9, colors.white, false, true)) -- steam boiler 2 to turbine 2 junction
table.insert(steam_pipes_b, pipe(0, 17, 3, 17, colors.white, false, true)) -- steam boiler 2 to turbine 3
else
table.insert(steam_pipes_b, pipe(1, 17, 1, 9, colors.white, false, true)) -- steam boiler 2 to turbine 2 junction
table.insert(steam_pipes_b, pipe(1, 17, 3, 17, colors.white, false, true)) -- steam boiler 2 to turbine 3
end
if num_boilers == 2 then
table.insert(steam_pipes_b, pipe(0, 18, 2, 10, colors.blue, false, true)) -- water boiler 2 to turbine 3
table.insert(steam_pipes_b, pipe(0, 18, 3, 18, colors.blue, false, true)) -- water boiler 2 to turbine 2 junction
else
table.insert(steam_pipes_b, pipe(2, 18, 2, 10, colors.blue, false, true)) -- water boiler 2 to turbine 3
table.insert(steam_pipes_b, pipe(2, 18, 3, 18, colors.blue, false, true)) -- water boiler 2 to turbine 2 junction
end
elseif num_turbines == 1 and num_boilers == 2 then
table.insert(steam_pipes_b, pipe(0, 17, 1, 9, colors.white, false, true)) -- steam boiler 2 to turbine 2 junction
table.insert(steam_pipes_b, pipe(0, 17, 1, 17, colors.white, false, true)) -- steam boiler 2 to turbine 3
table.insert(steam_pipes_b, pipe(0, 18, 2, 10, colors.blue, false, true)) -- water boiler 2 to turbine 3
table.insert(steam_pipes_b, pipe(0, 18, 2, 18, colors.blue, false, true)) -- water boiler 2 to turbine 2 junction
end
PipeNetwork{parent=root,x=47,y=11,pipes=steam_pipes_a,bg=colors.lightGray} PipeNetwork{parent=root,x=47,y=11,pipes=steam_pipes_a,bg=colors.lightGray}
PipeNetwork{parent=root,x=54,y=3,pipes=steam_pipes_b,bg=colors.lightGray} PipeNetwork{parent=root,x=54,y=3,pipes=steam_pipes_b,bg=colors.lightGray}

View File

@ -2,10 +2,12 @@
-- Main SCADA Coordinator GUI -- Main SCADA Coordinator GUI
-- --
local core = require("graphics.core") local log = require("scada-common.log")
local log = require("scada-common.log")
local style = require("coordinator.ui.style") local database = require("coordinator.database")
local style = require("coordinator.ui.style")
local core = require("graphics.core")
local DisplayBox = require("graphics.elements.displaybox") local DisplayBox = require("graphics.elements.displaybox")
local TextBox = require("graphics.elements.textbox") local TextBox = require("graphics.elements.textbox")
@ -20,11 +22,13 @@ local function init(monitor)
-- window header message -- window header message
TextBox{parent=main,text="Nuclear Generation Facility SCADA Coordinator",alignment=TEXT_ALIGN.CENTER,height=1,fg_bg=style.header} TextBox{parent=main,text="Nuclear Generation Facility SCADA Coordinator",alignment=TEXT_ALIGN.CENTER,height=1,fg_bg=style.header}
local db = database.get()
-- unit overviews -- unit overviews
unit_overview(main, 2, 3, 1) if db.facility.num_units >= 1 then unit_overview(main, 2, 3, db.units[1]) end
unit_overview(main, 84, 3, 2) if db.facility.num_units >= 2 then unit_overview(main, 84, 3, db.units[2]) end
unit_overview(main, 2, 29, 3) if db.facility.num_units >= 3 then unit_overview(main, 2, 29, db.units[3]) end
unit_overview(main, 84, 29, 4) if db.facility.num_units == 4 then unit_overview(main, 84, 29, db.units[4]) end
return main return main
end end