ENH use function to format annotated plots
This commit is contained in:
parent
24101ebc11
commit
a3dad5997e
2
core
2
core
|
@ -1 +1 @@
|
||||||
Subproject commit ad5b95a0bd222ac4ec8078693637f312bc76a80c
|
Subproject commit 6ed12553c7f6d5c11bb3072af3f68fa1ab2aa44a
|
|
@ -184,17 +184,19 @@ end
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- scaled plot (with textual data above it)
|
-- scaled plot (with textual data above it)
|
||||||
|
|
||||||
M.initLabeledScalePlot = function(x, y, w, h, f, spacing, label)
|
M.initLabeledScalePlot = function(x, y, w, h, format_fun, label_fun, spacing, label)
|
||||||
return {
|
return {
|
||||||
label = _left_text(
|
label = _left_text(
|
||||||
_G_Widget_.make_point(x, y),
|
_G_Widget_.make_point(x, y),
|
||||||
label
|
label
|
||||||
),
|
),
|
||||||
value = _right_text(
|
value = _G_Widget_.formatted_text(
|
||||||
_G_Widget_.make_point(x + w, y),
|
_G_Widget_.make_point(x + w, y),
|
||||||
label
|
0,
|
||||||
|
M.right_text_style,
|
||||||
|
format_fun
|
||||||
),
|
),
|
||||||
plot = M.initThemedScalePlot(x, y + spacing, w, h, f),
|
plot = M.initThemedScalePlot(x, y + spacing, w, h, label_fun),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -207,10 +209,13 @@ M.annotated_scale_plot_draw_dynamic = function(asp, cr)
|
||||||
ScalePlot.draw_dynamic(asp.plot, cr)
|
ScalePlot.draw_dynamic(asp.plot, cr)
|
||||||
end
|
end
|
||||||
|
|
||||||
M.annotated_scale_plot_set = function(asp, cr, text_value, plot_value)
|
-- M.annotated_scale_plot_set = function(asp, cr, text_value, plot_value)
|
||||||
-- TODO this could be made more intelligent
|
-- Text.set(asp.value, cr, text_value)
|
||||||
Text.set(asp.value, cr, text_value)
|
-- ScalePlot.update(asp.plot, cr, plot_value)
|
||||||
ScalePlot.update(asp.plot, cr, plot_value)
|
-- end
|
||||||
|
M.annotated_scale_plot_set = function(asp, cr, value)
|
||||||
|
Text.set(asp.value, cr, value)
|
||||||
|
ScalePlot.update(asp.plot, cr, value)
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
|
@ -14,6 +14,11 @@ local network_label_function = function(bits)
|
||||||
return Util.round_to_string(new_value, precision)..' '..new_unit..'b/s'
|
return Util.round_to_string(new_value, precision)..' '..new_unit..'b/s'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local value_format_function = function(bits)
|
||||||
|
local unit, value = Util.convert_data_val(bits)
|
||||||
|
return Util.precision_round_to_string(value, 3)..' '..unit..'b/s'
|
||||||
|
end
|
||||||
|
|
||||||
local header = Common.Header(
|
local header = Common.Header(
|
||||||
_G_INIT_DATA_.CENTER_RIGHT_X,
|
_G_INIT_DATA_.CENTER_RIGHT_X,
|
||||||
_G_INIT_DATA_.TOP_Y,
|
_G_INIT_DATA_.TOP_Y,
|
||||||
|
@ -26,6 +31,7 @@ local dnload = Common.initLabeledScalePlot(
|
||||||
header.bottom_y,
|
header.bottom_y,
|
||||||
_G_INIT_DATA_.SECTION_WIDTH,
|
_G_INIT_DATA_.SECTION_WIDTH,
|
||||||
_PLOT_HEIGHT_,
|
_PLOT_HEIGHT_,
|
||||||
|
value_format_function,
|
||||||
network_label_function,
|
network_label_function,
|
||||||
_PLOT_SEC_BREAK_,
|
_PLOT_SEC_BREAK_,
|
||||||
'Download'
|
'Download'
|
||||||
|
@ -36,6 +42,7 @@ local upload = Common.initLabeledScalePlot(
|
||||||
header.bottom_y + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2,
|
header.bottom_y + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2,
|
||||||
_G_INIT_DATA_.SECTION_WIDTH,
|
_G_INIT_DATA_.SECTION_WIDTH,
|
||||||
_PLOT_HEIGHT_,
|
_PLOT_HEIGHT_,
|
||||||
|
value_format_function,
|
||||||
network_label_function,
|
network_label_function,
|
||||||
_PLOT_SEC_BREAK_,
|
_PLOT_SEC_BREAK_,
|
||||||
'Upload'
|
'Upload'
|
||||||
|
@ -86,19 +93,19 @@ local update = function(cr, update_frequency)
|
||||||
if tx_delta > 0 then uspeed = uspeed + tx_delta * update_frequency end
|
if tx_delta > 0 then uspeed = uspeed + tx_delta * update_frequency end
|
||||||
end
|
end
|
||||||
|
|
||||||
local dspeed_unit, dspeed_value = Util.convert_data_val(dspeed)
|
-- local dspeed_unit, dspeed_value = Util.convert_data_val(dspeed)
|
||||||
local uspeed_unit, uspeed_value = Util.convert_data_val(uspeed)
|
-- local uspeed_unit, uspeed_value = Util.convert_data_val(uspeed)
|
||||||
|
|
||||||
Common.annotated_scale_plot_set(
|
Common.annotated_scale_plot_set(
|
||||||
dnload,
|
dnload,
|
||||||
cr,
|
cr,
|
||||||
Util.precision_round_to_string(dspeed_value, 3)..' '..dspeed_unit..'b/s',
|
-- Util.precision_round_to_string(dspeed_value, 3)..' '..dspeed_unit..'b/s',
|
||||||
dspeed
|
dspeed
|
||||||
)
|
)
|
||||||
Common.annotated_scale_plot_set(
|
Common.annotated_scale_plot_set(
|
||||||
upload,
|
upload,
|
||||||
cr,
|
cr,
|
||||||
Util.precision_round_to_string(uspeed_value, 3)..' '..uspeed_unit..'b/s',
|
-- Util.precision_round_to_string(uspeed_value, 3)..' '..uspeed_unit..'b/s',
|
||||||
uspeed
|
uspeed
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,6 +18,18 @@ local calculate_power = function(prev_cnt, cnt, update_frequency)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local power_format_function = function(watts)
|
||||||
|
return Util.precision_round_to_string(watts, 3).." W"
|
||||||
|
end
|
||||||
|
|
||||||
|
local ac_format_function = function(watts)
|
||||||
|
if watts == 0 then
|
||||||
|
return "A/C"
|
||||||
|
else
|
||||||
|
return power_format_function(watts)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local header = Common.Header(
|
local header = Common.Header(
|
||||||
_G_INIT_DATA_.RIGHT_X,
|
_G_INIT_DATA_.RIGHT_X,
|
||||||
_MODULE_Y_,
|
_MODULE_Y_,
|
||||||
|
@ -30,11 +42,11 @@ local pkg0 = Common.initLabeledScalePlot(
|
||||||
header.bottom_y,
|
header.bottom_y,
|
||||||
_G_INIT_DATA_.SECTION_WIDTH,
|
_G_INIT_DATA_.SECTION_WIDTH,
|
||||||
_PLOT_HEIGHT_,
|
_PLOT_HEIGHT_,
|
||||||
|
power_format_function,
|
||||||
power_label_function,
|
power_label_function,
|
||||||
_PLOT_SEC_BREAK_,
|
_PLOT_SEC_BREAK_,
|
||||||
'PKG0'
|
'PKG0'
|
||||||
)
|
)
|
||||||
pkg0.value.append_end = ' W'
|
|
||||||
|
|
||||||
local _CORE_Y_ = header.bottom_y + _TEXT_SPACING_ + _PLOT_SEC_BREAK_ + _PLOT_HEIGHT_
|
local _CORE_Y_ = header.bottom_y + _TEXT_SPACING_ + _PLOT_SEC_BREAK_ + _PLOT_HEIGHT_
|
||||||
|
|
||||||
|
@ -43,6 +55,7 @@ local dram = Common.initLabeledScalePlot(
|
||||||
_CORE_Y_,
|
_CORE_Y_,
|
||||||
_G_INIT_DATA_.SECTION_WIDTH,
|
_G_INIT_DATA_.SECTION_WIDTH,
|
||||||
_PLOT_HEIGHT_,
|
_PLOT_HEIGHT_,
|
||||||
|
power_format_function,
|
||||||
power_label_function,
|
power_label_function,
|
||||||
_PLOT_SEC_BREAK_,
|
_PLOT_SEC_BREAK_,
|
||||||
'DRAM'
|
'DRAM'
|
||||||
|
@ -54,6 +67,7 @@ local battery_draw = Common.initLabeledScalePlot(
|
||||||
_CORE_Y_ + _PLOT_SEC_BREAK_ * 2 + _PLOT_HEIGHT_,
|
_CORE_Y_ + _PLOT_SEC_BREAK_ * 2 + _PLOT_HEIGHT_,
|
||||||
_G_INIT_DATA_.SECTION_WIDTH,
|
_G_INIT_DATA_.SECTION_WIDTH,
|
||||||
_PLOT_HEIGHT_,
|
_PLOT_HEIGHT_,
|
||||||
|
ac_format_function,
|
||||||
power_label_function,
|
power_label_function,
|
||||||
_PLOT_SEC_BREAK_,
|
_PLOT_SEC_BREAK_,
|
||||||
'Battery Draw'
|
'Battery Draw'
|
||||||
|
@ -71,23 +85,27 @@ local update = function(cr, update_frequency, is_using_ac)
|
||||||
|
|
||||||
local pkg0_power = calculate_power(prev_pkg0_uj_cnt, pkg0_uj_cnt, update_frequency)
|
local pkg0_power = calculate_power(prev_pkg0_uj_cnt, pkg0_uj_cnt, update_frequency)
|
||||||
|
|
||||||
Common.annotated_scale_plot_set(pkg0, cr, Util.precision_round_to_string(pkg0_power, 3), pkg0_power)
|
-- Common.annotated_scale_plot_set(pkg0, cr, Util.precision_round_to_string(pkg0_power, 3), pkg0_power)
|
||||||
|
Common.annotated_scale_plot_set(pkg0, cr, pkg0_power)
|
||||||
|
|
||||||
local dram_power = calculate_power(prev_dram_uj_cnt, dram_uj_cnt, update_frequency)
|
local dram_power = calculate_power(prev_dram_uj_cnt, dram_uj_cnt, update_frequency)
|
||||||
|
|
||||||
Common.annotated_scale_plot_set(dram, cr, Util.precision_round_to_string(dram_power, 3), dram_power)
|
-- Common.annotated_scale_plot_set(dram, cr, Util.precision_round_to_string(dram_power, 3), dram_power)
|
||||||
|
Common.annotated_scale_plot_set(dram, cr, dram_power)
|
||||||
|
|
||||||
prev_pkg0_uj_cnt = pkg0_uj_cnt
|
prev_pkg0_uj_cnt = pkg0_uj_cnt
|
||||||
prev_dram_uj_cnt = dram_uj_cnt
|
prev_dram_uj_cnt = dram_uj_cnt
|
||||||
|
|
||||||
if is_using_ac then
|
if is_using_ac then
|
||||||
Common.annotated_scale_plot_set(battery_draw, cr, 'A/C', 0)
|
-- Common.annotated_scale_plot_set(battery_draw, cr, 'A/C', 0)
|
||||||
|
Common.annotated_scale_plot_set(battery_draw, cr, 0)
|
||||||
else
|
else
|
||||||
local current = Util.read_file('/sys/class/power_supply/BAT0/current_now', nil, '*n')
|
local current = Util.read_file('/sys/class/power_supply/BAT0/current_now', nil, '*n')
|
||||||
local voltage = Util.read_file('/sys/class/power_supply/BAT0/voltage_now', nil, '*n')
|
local voltage = Util.read_file('/sys/class/power_supply/BAT0/voltage_now', nil, '*n')
|
||||||
local power = current * voltage * 0.000000000001
|
local power = current * voltage * 0.000000000001
|
||||||
local t = Util.precision_round_to_string(power, 3)..' W'
|
-- local t = Util.precision_round_to_string(power, 3)..' W'
|
||||||
Common.annotated_scale_plot_set(battery_draw, cr, t, power)
|
-- Common.annotated_scale_plot_set(battery_draw, cr, t, power)
|
||||||
|
Common.annotated_scale_plot_set(battery_draw, cr, power)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -24,15 +24,16 @@ local update_stat = function(cr, stat, byte_cnt, update_frequency)
|
||||||
local delta_bytes = byte_cnt - stat.prev_byte_cnt
|
local delta_bytes = byte_cnt - stat.prev_byte_cnt
|
||||||
stat.prev_byte_cnt = byte_cnt
|
stat.prev_byte_cnt = byte_cnt
|
||||||
|
|
||||||
local text_value = '0.00 B/s'
|
-- local text_value = '0.00 B/s'
|
||||||
local plot_value = 0
|
local plot_value = 0
|
||||||
if delta_bytes > 0 then
|
if delta_bytes > 0 then
|
||||||
local bps = delta_bytes * update_frequency
|
local bps = delta_bytes * update_frequency
|
||||||
local unit, value = Util.convert_data_val(bps)
|
-- local unit, value = Util.convert_data_val(bps)
|
||||||
text_value = Util.precision_round_to_string(value, 3)..' '..unit..'B/s'
|
-- text_value = Util.precision_round_to_string(value, 3)..' '..unit..'B/s'
|
||||||
plot_value = bps
|
plot_value = bps
|
||||||
end
|
end
|
||||||
Common.annotated_scale_plot_set(stat, cr, text_value, plot_value)
|
-- Common.annotated_scale_plot_set(stat, cr, text_value, plot_value)
|
||||||
|
Common.annotated_scale_plot_set(stat, cr, plot_value)
|
||||||
end
|
end
|
||||||
|
|
||||||
local io_label_function = function(bytes)
|
local io_label_function = function(bytes)
|
||||||
|
@ -44,6 +45,11 @@ local io_label_function = function(bytes)
|
||||||
return Util.round_to_string(new_value, precision)..' '..new_unit..'B/s'
|
return Util.round_to_string(new_value, precision)..' '..new_unit..'B/s'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local format_value_function = function(bps)
|
||||||
|
local unit, value = Util.convert_data_val(bps)
|
||||||
|
return Util.precision_round_to_string(value, 3)..' '..unit..'B/s'
|
||||||
|
end
|
||||||
|
|
||||||
local header = Common.Header(
|
local header = Common.Header(
|
||||||
_G_INIT_DATA_.CENTER_LEFT_X,
|
_G_INIT_DATA_.CENTER_LEFT_X,
|
||||||
_G_INIT_DATA_.TOP_Y,
|
_G_INIT_DATA_.TOP_Y,
|
||||||
|
@ -56,6 +62,7 @@ local reads = Common.initLabeledScalePlot(
|
||||||
header.bottom_y,
|
header.bottom_y,
|
||||||
_G_INIT_DATA_.SECTION_WIDTH,
|
_G_INIT_DATA_.SECTION_WIDTH,
|
||||||
_PLOT_HEIGHT_,
|
_PLOT_HEIGHT_,
|
||||||
|
format_value_function,
|
||||||
io_label_function,
|
io_label_function,
|
||||||
_PLOT_SEC_BREAK_,
|
_PLOT_SEC_BREAK_,
|
||||||
'Reads'
|
'Reads'
|
||||||
|
@ -66,6 +73,7 @@ local writes = Common.initLabeledScalePlot(
|
||||||
header.bottom_y + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2,
|
header.bottom_y + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2,
|
||||||
_G_INIT_DATA_.SECTION_WIDTH,
|
_G_INIT_DATA_.SECTION_WIDTH,
|
||||||
_PLOT_HEIGHT_,
|
_PLOT_HEIGHT_,
|
||||||
|
format_value_function,
|
||||||
io_label_function,
|
io_label_function,
|
||||||
_PLOT_SEC_BREAK_,
|
_PLOT_SEC_BREAK_,
|
||||||
'Writes'
|
'Writes'
|
||||||
|
|
Loading…
Reference in New Issue