2023-08-10 03:26:06 +00:00
--
-- Basic Unit Flow Overview
--
2023-08-11 03:31:38 +00:00
local util = require ( " scada-common.util " )
2023-08-10 03:26:06 +00:00
2023-08-13 04:51:37 +00:00
local style = require ( " coordinator.ui.style " )
2023-08-11 03:31:38 +00:00
local core = require ( " graphics.core " )
2023-08-10 03:26:06 +00:00
2023-08-11 03:31:38 +00:00
local Div = require ( " graphics.elements.div " )
local PipeNetwork = require ( " graphics.elements.pipenet " )
local TextBox = require ( " graphics.elements.textbox " )
2023-08-10 03:26:06 +00:00
2023-08-11 03:31:38 +00:00
local Rectangle = require ( " graphics.elements.rectangle " )
2023-08-10 03:26:06 +00:00
2023-08-11 03:31:38 +00:00
local DataIndicator = require ( " graphics.elements.indicators.data " )
2023-08-10 03:26:06 +00:00
local IndicatorLight = require ( " graphics.elements.indicators.light " )
local TriIndicatorLight = require ( " graphics.elements.indicators.trilight " )
local TEXT_ALIGN = core.TEXT_ALIGN
2023-08-13 04:11:58 +00:00
local sprintf = util.sprintf
2023-08-11 03:31:38 +00:00
local cpair = core.cpair
local border = core.border
2023-08-10 03:26:06 +00:00
local pipe = core.pipe
2023-08-20 20:52:12 +00:00
local wh_gray = style.wh_gray
2023-08-13 04:51:37 +00:00
local bw_fg_bg = style.bw_fg_bg
local text_c = style.text_colors
local lu_c = style.lu_colors
local ind_grn = style.ind_grn
local ind_wht = style.ind_wht
2023-08-13 04:11:58 +00:00
-- make a new unit flow window
2023-08-10 03:26:06 +00:00
---@param parent graphics_element parent
---@param x integer top left x
---@param y integer top left y
2023-08-19 17:38:05 +00:00
---@param wide boolean whether to render wide version
2023-08-10 03:26:06 +00:00
---@param unit ioctl_unit unit database entry
2023-08-19 17:38:05 +00:00
local function make ( parent , x , y , wide , unit )
2023-08-10 03:26:06 +00:00
local height = 16
2023-08-20 03:28:03 +00:00
local v_start = 1 + ( ( unit.unit_id - 1 ) * 5 )
2023-08-11 03:31:38 +00:00
local prv_start = 1 + ( ( unit.unit_id - 1 ) * 3 )
2023-08-20 03:24:20 +00:00
local v_fields = { " pu " , " po " , " pl " , " am " }
2023-08-10 03:26:06 +00:00
local v_names = {
2023-08-13 04:11:58 +00:00
sprintf ( " PV%02d-PU " , v_start ) ,
sprintf ( " PV%02d-PO " , v_start + 1 ) ,
sprintf ( " PV%02d-PL " , v_start + 2 ) ,
sprintf ( " PV%02d-AM " , v_start + 3 ) ,
sprintf ( " PRV%02d " , prv_start ) ,
sprintf ( " PRV%02d " , prv_start + 1 ) ,
sprintf ( " PRV%02d " , prv_start + 2 )
2023-08-10 03:26:06 +00:00
}
assert ( parent.get_height ( ) >= ( y + height ) , " flow display not of sufficient vertical resolution (add an additional row of monitors) " .. y .. " , " .. parent.get_height ( ) )
2023-08-19 17:38:05 +00:00
local function _wide ( a , b ) return util.trinary ( wide , a , b ) end
2023-08-10 03:26:06 +00:00
-- bounding box div
2023-08-19 17:38:05 +00:00
local root = Div { parent = parent , x = x , y = y , width = _wide ( 136 , 114 ) , height = height }
2023-08-10 03:26:06 +00:00
2023-08-13 04:51:37 +00:00
local lg_gray = cpair ( colors.lightGray , colors.gray )
2023-08-10 03:26:06 +00:00
2023-08-11 03:31:38 +00:00
------------------
-- COOLING LOOP --
------------------
2023-08-10 03:26:06 +00:00
2023-08-20 21:30:34 +00:00
local reactor = Rectangle { parent = root , x = 1 , y = 1 , border = border ( 1 , colors.gray , true ) , width = 19 , height = 5 , fg_bg = wh_gray }
2023-08-10 03:26:06 +00:00
TextBox { parent = reactor , y = 1 , text = " FISSION REACTOR " , alignment = TEXT_ALIGN.CENTER , height = 1 }
TextBox { parent = reactor , y = 3 , text = " UNIT # " .. unit.unit_id , alignment = TEXT_ALIGN.CENTER , height = 1 }
2023-08-13 04:51:37 +00:00
TextBox { parent = root , x = 19 , y = 2 , text = " \x1b \x80 \x1a " , width = 1 , height = 3 , fg_bg = lg_gray }
2023-08-19 17:38:05 +00:00
TextBox { parent = root , x = 3 , y = 5 , text = " \x19 " , width = 1 , height = 1 , fg_bg = lg_gray }
2023-08-10 03:26:06 +00:00
local rc_pipes = { }
2023-08-19 17:38:05 +00:00
local emc_x = 42 -- emergency coolant connection x point
if unit.num_boilers > 0 then
table.insert ( rc_pipes , pipe ( 0 , 1 , _wide ( 28 , 19 ) , 1 , colors.lightBlue , true ) )
table.insert ( rc_pipes , pipe ( 0 , 3 , _wide ( 28 , 19 ) , 3 , colors.orange , true ) )
table.insert ( rc_pipes , pipe ( _wide ( 46 , 39 ) , 1 , _wide ( 72 , 58 ) , 1 , colors.blue , true ) )
table.insert ( rc_pipes , pipe ( _wide ( 46 , 39 ) , 3 , _wide ( 72 , 58 ) , 3 , colors.white , true ) )
else
emc_x = 3
table.insert ( rc_pipes , pipe ( 0 , 1 , _wide ( 72 , 58 ) , 1 , colors.blue , true ) )
table.insert ( rc_pipes , pipe ( 0 , 3 , _wide ( 72 , 58 ) , 3 , colors.white , true ) )
end
2023-08-10 03:26:06 +00:00
2023-08-19 17:38:05 +00:00
if unit.has_tank then
table.insert ( rc_pipes , pipe ( emc_x , 1 , emc_x , 0 , colors.blue , true , true ) )
end
2023-08-10 03:26:06 +00:00
2023-08-19 17:38:05 +00:00
local prv_yo = math.max ( 3 - unit.num_turbines , 0 )
for i = 1 , unit.num_turbines do
local py = 2 * ( i - 1 ) + prv_yo
table.insert ( rc_pipes , pipe ( _wide ( 92 , 78 ) , py , _wide ( 104 , 83 ) , py , colors.white , true ) )
end
2023-08-10 03:26:06 +00:00
2023-08-19 17:38:05 +00:00
PipeNetwork { parent = root , x = 20 , y = 1 , pipes = rc_pipes , bg = colors.lightGray }
2023-08-10 03:26:06 +00:00
2023-08-19 17:38:05 +00:00
if unit.num_boilers > 0 then
2023-08-20 00:06:37 +00:00
local cc_rate = DataIndicator { parent = root , x = _wide ( 25 , 22 ) , y = 5 , lu_colors = lu_c , label = " " , unit = " mB/t " , format = " %11.0f " , value = 0 , commas = true , width = 16 , fg_bg = bw_fg_bg }
local hc_rate = DataIndicator { parent = root , x = _wide ( 25 , 22 ) , y = 3 , lu_colors = lu_c , label = " " , unit = " mB/t " , format = " %11.0f " , value = 0 , commas = true , width = 16 , fg_bg = bw_fg_bg }
cc_rate.register ( unit.unit_ps , " boil_sum " , cc_rate.update )
hc_rate.register ( unit.unit_ps , " heating_rate " , hc_rate.update )
2023-08-19 17:38:05 +00:00
local boiler = Rectangle { parent = root , x = _wide ( 47 , 40 ) , y = 1 , border = border ( 1 , colors.gray , true ) , width = 19 , height = 5 , fg_bg = wh_gray }
TextBox { parent = boiler , y = 1 , text = " THERMO-ELECTRIC " , alignment = TEXT_ALIGN.CENTER , height = 1 }
TextBox { parent = boiler , y = 3 , text = " BOILERS " , alignment = TEXT_ALIGN.CENTER , height = 1 }
TextBox { parent = root , x = _wide ( 47 , 40 ) , y = 2 , text = " \x1b \x80 \x1a " , width = 1 , height = 3 , fg_bg = lg_gray }
TextBox { parent = root , x = _wide ( 65 , 58 ) , y = 2 , text = " \x1b \x80 \x1a " , width = 1 , height = 3 , fg_bg = lg_gray }
2023-08-20 00:06:37 +00:00
local wt_rate = DataIndicator { parent = root , x = _wide ( 71 , 61 ) , y = 3 , lu_colors = lu_c , label = " " , unit = " mB/t " , format = " %11.0f " , value = 0 , commas = true , width = 16 , fg_bg = bw_fg_bg }
local st_rate = DataIndicator { parent = root , x = _wide ( 71 , 61 ) , y = 5 , lu_colors = lu_c , label = " " , unit = " mB/t " , format = " %11.0f " , value = 0 , commas = true , width = 16 , fg_bg = bw_fg_bg }
wt_rate.register ( unit.unit_ps , " turbine_flow_sum " , wt_rate.update )
st_rate.register ( unit.unit_ps , " boil_sum " , st_rate.update )
2023-08-19 17:38:05 +00:00
else
2023-08-20 00:06:37 +00:00
local wt_rate = DataIndicator { parent = root , x = 28 , y = 3 , lu_colors = lu_c , label = " " , unit = " mB/t " , format = " %11.0f " , value = 0 , commas = true , width = 16 , fg_bg = bw_fg_bg }
local st_rate = DataIndicator { parent = root , x = 28 , y = 5 , lu_colors = lu_c , label = " " , unit = " mB/t " , format = " %11.0f " , value = 0 , commas = true , width = 16 , fg_bg = bw_fg_bg }
wt_rate.register ( unit.unit_ps , " turbine_flow_sum " , wt_rate.update )
st_rate.register ( unit.unit_ps , " heating_rate " , st_rate.update )
2023-08-19 17:38:05 +00:00
end
2023-08-10 03:26:06 +00:00
2023-08-19 17:38:05 +00:00
local turbine = Rectangle { parent = root , x = _wide ( 93 , 79 ) , y = 1 , border = border ( 1 , colors.gray , true ) , width = 19 , height = 5 , fg_bg = wh_gray }
2023-08-10 03:26:06 +00:00
TextBox { parent = turbine , y = 1 , text = " STEAM TURBINE " , alignment = TEXT_ALIGN.CENTER , height = 1 }
2023-08-20 00:06:37 +00:00
TextBox { parent = turbine , y = 3 , text = util.trinary ( unit.num_turbines > 1 , " GENERATORS " , " GENERATOR " ) , alignment = TEXT_ALIGN.CENTER , height = 1 }
2023-08-21 02:53:14 +00:00
TextBox { parent = root , x = _wide ( 93 , 79 ) , y = 2 , text = " \x1b \x80 \x1a " , width = 1 , height = 3 , fg_bg = lg_gray }
2023-08-10 03:26:06 +00:00
2023-08-19 17:38:05 +00:00
for i = 1 , unit.num_turbines do
local ry = 1 + ( 2 * ( i - 1 ) ) + prv_yo
TextBox { parent = root , x = _wide ( 125 , 103 ) , y = ry , text = " \x10 \x11 \x7f " , fg_bg = text_c , width = 3 , height = 1 }
local state = TriIndicatorLight { parent = root , x = _wide ( 129 , 107 ) , y = ry , label = v_names [ i + 4 ] , c1 = colors.gray , c2 = colors.yellow , c3 = colors.red }
2023-08-20 00:06:37 +00:00
state.register ( unit.turbine_ps_tbl [ i ] , " SteamDumpOpen " , state.update )
2023-08-11 03:31:38 +00:00
end
----------------------
-- WASTE PROCESSING --
----------------------
2023-08-10 03:26:06 +00:00
local waste = Div { parent = root , x = 3 , y = 6 }
local waste_pipes = {
2023-08-19 17:38:05 +00:00
pipe ( 0 , 0 , _wide ( 19 , 16 ) , 1 , colors.brown , true ) ,
pipe ( _wide ( 14 , 13 ) , 1 , _wide ( 19 , 17 ) , 5 , colors.brown , true ) ,
pipe ( _wide ( 22 , 19 ) , 1 , _wide ( 49 , 45 ) , 1 , colors.brown , true ) ,
pipe ( _wide ( 22 , 19 ) , 5 , _wide ( 28 , 24 ) , 5 , colors.brown , true ) ,
pipe ( _wide ( 64 , 53 ) , 1 , _wide ( 95 , 81 ) , 1 , colors.green , true ) ,
pipe ( _wide ( 48 , 43 ) , 4 , _wide ( 71 , 61 ) , 4 , colors.cyan , true ) ,
pipe ( _wide ( 66 , 57 ) , 4 , _wide ( 71 , 61 ) , 8 , colors.cyan , true ) ,
pipe ( _wide ( 74 , 63 ) , 4 , _wide ( 95 , 81 ) , 4 , colors.cyan , true ) ,
pipe ( _wide ( 74 , 63 ) , 8 , _wide ( 133 , 111 ) , 8 , colors.cyan , true ) ,
pipe ( _wide ( 108 , 94 ) , 1 , _wide ( 132 , 110 ) , 6 , colors.black , true , true ) ,
pipe ( _wide ( 108 , 94 ) , 4 , _wide ( 111 , 95 ) , 1 , colors.black , true , true ) ,
pipe ( _wide ( 132 , 110 ) , 6 , _wide ( 130 , 108 ) , 6 , colors.black , true , true )
2023-08-10 03:26:06 +00:00
}
2023-08-19 17:38:05 +00:00
PipeNetwork { parent = waste , x = 1 , y = 1 , pipes = waste_pipes , bg = colors.lightGray }
2023-08-10 03:26:06 +00:00
local function _valve ( vx , vy , n )
2023-08-13 04:51:37 +00:00
TextBox { parent = waste , x = vx , y = vy , text = " \x10 \x11 " , fg_bg = text_c , width = 2 , height = 1 }
local conn = IndicatorLight { parent = waste , x = vx - 3 , y = vy + 1 , label = v_names [ n ] , colors = ind_grn }
2023-08-20 03:24:20 +00:00
local open = IndicatorLight { parent = waste , x = vx - 3 , y = vy + 2 , label = " OPEN " , colors = ind_wht }
conn.register ( unit.unit_ps , util.c ( " V_ " , v_fields [ n ] , " _conn " ) , conn.update )
open.register ( unit.unit_ps , util.c ( " V_ " , v_fields [ n ] , " _state " ) , open.update )
2023-08-10 03:26:06 +00:00
end
local function _machine ( mx , my , name )
local l = string.len ( name ) + 2
2023-08-19 17:38:05 +00:00
TextBox { parent = waste , x = mx , y = my , text = string.rep ( " \x8f " , l ) , alignment = TEXT_ALIGN.CENTER , fg_bg = lg_gray , width = l , height = 1 }
2023-08-13 04:51:37 +00:00
TextBox { parent = waste , x = mx , y = my + 1 , text = name , alignment = TEXT_ALIGN.CENTER , fg_bg = wh_gray , width = l , height = 1 }
2023-08-10 03:26:06 +00:00
end
2023-08-20 00:06:37 +00:00
local waste_rate = DataIndicator { parent = waste , x = 1 , y = 3 , lu_colors = lu_c , label = " " , unit = " mB/t " , format = " %7.2f " , value = 0 , width = 12 , fg_bg = bw_fg_bg }
local pu_rate = DataIndicator { parent = waste , x = _wide ( 82 , 70 ) , y = 3 , lu_colors = lu_c , label = " " , unit = " mB/t " , format = " %7.3f " , value = 0 , width = 12 , fg_bg = bw_fg_bg }
local po_rate = DataIndicator { parent = waste , x = _wide ( 52 , 45 ) , y = 6 , lu_colors = lu_c , label = " " , unit = " mB/t " , format = " %7.3f " , value = 0 , width = 12 , fg_bg = bw_fg_bg }
local popl_rate = DataIndicator { parent = waste , x = _wide ( 82 , 70 ) , y = 6 , lu_colors = lu_c , label = " " , unit = " mB/t " , format = " %7.3f " , value = 0 , width = 12 , fg_bg = bw_fg_bg }
local poam_rate = DataIndicator { parent = waste , x = _wide ( 82 , 70 ) , y = 10 , lu_colors = lu_c , label = " " , unit = " mB/t " , format = " %7.3f " , value = 0 , width = 12 , fg_bg = bw_fg_bg }
local spent_rate = DataIndicator { parent = waste , x = _wide ( 117 , 99 ) , y = 3 , lu_colors = lu_c , label = " " , unit = " mB/t " , format = " %7.3f " , value = 0 , width = 12 , fg_bg = bw_fg_bg }
waste_rate.register ( unit.unit_ps , " act_burn_rate " , waste_rate.update )
pu_rate.register ( unit.unit_ps , " pu_rate " , pu_rate.update )
po_rate.register ( unit.unit_ps , " po_rate " , po_rate.update )
popl_rate.register ( unit.unit_ps , " po_pl_rate " , popl_rate.update )
poam_rate.register ( unit.unit_ps , " po_am_rate " , poam_rate.update )
spent_rate.register ( unit.unit_ps , " ws_rate " , spent_rate.update )
2023-08-19 17:38:05 +00:00
_valve ( _wide ( 21 , 18 ) , 2 , 1 )
_valve ( _wide ( 21 , 18 ) , 6 , 2 )
_valve ( _wide ( 73 , 62 ) , 5 , 3 )
_valve ( _wide ( 73 , 62 ) , 9 , 4 )
_machine ( _wide ( 51 , 45 ) , 1 , " CENTRIFUGE \x1a " ) ;
_machine ( _wide ( 97 , 83 ) , 1 , " PRC [Pu] \x1a " ) ;
_machine ( _wide ( 97 , 83 ) , 4 , " PRC [Po] \x1a " ) ;
_machine ( _wide ( 116 , 94 ) , 6 , " SPENT WASTE \x1b " )
TextBox { parent = waste , x = _wide ( 30 , 25 ) , y = 3 , text = " SNAs [Po] " , alignment = TEXT_ALIGN.CENTER , width = 19 , height = 1 , fg_bg = wh_gray }
2023-08-20 21:30:34 +00:00
local sna_po = Rectangle { parent = waste , x = _wide ( 30 , 25 ) , y = 4 , border = border ( 1 , colors.gray , true ) , width = 19 , height = 7 , thin = true , fg_bg = bw_fg_bg }
2023-08-13 04:51:37 +00:00
local sna_act = IndicatorLight { parent = sna_po , label = " ACTIVE " , colors = ind_grn }
2023-08-20 00:06:37 +00:00
local sna_cnt = DataIndicator { parent = sna_po , x = 12 , y = 1 , lu_colors = lu_c , label = " CNT " , unit = " " , format = " %2d " , value = 0 , width = 7 }
local sna_pk = DataIndicator { parent = sna_po , y = 3 , lu_colors = lu_c , label = " PEAK " , unit = " mB/t " , format = " %7.2f " , value = 0 , width = 17 }
2023-08-20 21:30:34 +00:00
local sna_max = DataIndicator { parent = sna_po , lu_colors = lu_c , label = " MAX " , unit = " mB/t " , format = " %8.2f " , value = 0 , width = 17 }
local sna_in = DataIndicator { parent = sna_po , lu_colors = lu_c , label = " IN " , unit = " mB/t " , format = " %9.2f " , value = 0 , width = 17 }
2023-08-20 00:06:37 +00:00
sna_act.register ( unit.unit_ps , " po_rate " , function ( r ) sna_act.update ( r > 0 ) end )
sna_cnt.register ( unit.unit_ps , " sna_count " , sna_cnt.update )
sna_pk.register ( unit.unit_ps , " sna_peak_rate " , sna_pk.update )
sna_max.register ( unit.unit_ps , " sna_prod_rate " , sna_max.update )
sna_in.register ( unit.unit_ps , " sna_in " , sna_in.update )
2023-08-10 03:26:06 +00:00
return root
end
return make