ENH use func lib

This commit is contained in:
Nathan Dwarshuis 2021-07-23 01:41:06 -04:00
parent 1fb0ebe60b
commit 709845dd8d
5 changed files with 30 additions and 28 deletions

2
core

@ -1 +1 @@
Subproject commit d10599afc4b851673cdb788a7184361816822656 Subproject commit 532a808bd316237644e763c7af80487fa6a36d8f

View File

@ -3,6 +3,7 @@ local Table = require 'Table'
local Util = require 'Util' local Util = require 'Util'
local Common = require 'Common' local Common = require 'Common'
local Geometry = require 'Geometry' local Geometry = require 'Geometry'
local func = require 'func'
return function(update_freq) return function(update_freq)
local MODULE_Y = 712 local MODULE_Y = 712
@ -111,14 +112,15 @@ return function(update_freq)
-- memory top table -- memory top table
local NUM_ROWS = 5 local NUM_ROWS = 5
local TABLE_CONKY = {} local TABLE_CONKY = func.map(
for r = 1, NUM_ROWS do function(i)
TABLE_CONKY[r] = { return {
comm = '${top_mem name '..r..'}', comm = '${top_mem name '..i..'}',
pid = '${top_mem pid '..r..'}', pid = '${top_mem pid '..i..'}',
mem = '${top_mem mem '..r..'}', mem = '${top_mem mem '..i..'}',
} }
end end,
func.seq(NUM_ROWS))
local tbl = Common.initTable( local tbl = Common.initTable(
Geometry.RIGHT_X, Geometry.RIGHT_X,

View File

@ -1,6 +1,7 @@
local Util = require 'Util' local Util = require 'Util'
local Common = require 'Common' local Common = require 'Common'
local Geometry = require 'Geometry' local Geometry = require 'Geometry'
local func = require 'func'
return function(update_freq) return function(update_freq)
local PLOT_SEC_BREAK = 20 local PLOT_SEC_BREAK = 20
@ -17,14 +18,13 @@ return function(update_freq)
local INTERFACES = get_interfaces() local INTERFACES = get_interfaces()
local INTERFACE_PATHS = {} local INTERFACE_PATHS = func.map(
for i = 1, #INTERFACES do function(s)
local dir = string.format('/sys/class/net/%s/statistics/', INTERFACES[i]) local dir = string.format('/sys/class/net/%s/statistics/', s)
INTERFACE_PATHS[i] = { return {rx = dir..'rx_bytes', tx = dir..'tx_bytes'}
rx = dir..'rx_bytes', end,
tx = dir..'tx_bytes', INTERFACES
} )
end
local get_bits = function(path) local get_bits = function(path)
return Util.read_file(path, nil, '*n') * 8 return Util.read_file(path, nil, '*n') * 8

View File

@ -5,6 +5,7 @@ local Util = require 'Util'
local Common = require 'Common' local Common = require 'Common'
local Geometry = require 'Geometry' local Geometry = require 'Geometry'
local CPU = require 'CPU' local CPU = require 'CPU'
local func = require 'func'
local __math_floor = math.floor local __math_floor = math.floor
@ -116,13 +117,10 @@ return function(update_freq)
-- cpu top table -- cpu top table
local NUM_ROWS = 5 local NUM_ROWS = 5
local TABLE_CONKY = {} local TABLE_CONKY = func.map(
for r = 1, NUM_ROWS do function(i) return {pid = '${top pid '..i..'}', cpu = '${top cpu '..i..'}'} end,
TABLE_CONKY[r] = { func.seq(NUM_ROWS)
pid = '${top pid '..r..'}', )
cpu = '${top cpu '..r..'}'
}
end
local tbl = Common.initTable( local tbl = Common.initTable(
Geometry.LEFT_X, Geometry.LEFT_X,

View File

@ -1,6 +1,7 @@
local Util = require 'Util' local Util = require 'Util'
local Common = require 'Common' local Common = require 'Common'
local Geometry = require 'Geometry' local Geometry = require 'Geometry'
local func = require 'func'
return function(update_freq) return function(update_freq)
local PLOT_SEC_BREAK = 20 local PLOT_SEC_BREAK = 20
@ -17,10 +18,11 @@ return function(update_freq)
local __tonumber = tonumber local __tonumber = tonumber
local __string_match = string.match local __string_match = string.match
local DEVICE_PATHS = {} -- TODO any way to make better lambda functions?
for i = 1, #DEVICES do local DEVICE_PATHS = func.map(
DEVICE_PATHS[i] = string.format('/sys/block/%s/stat', DEVICES[i]) function(s) return string.format('/sys/block/%s/stat', s) end,
end DEVICES
)
local read_devices = function() local read_devices = function()
local read_bytes = 0 local read_bytes = 0