refresh rate config property renaming
This commit is contained in:
parent
da26ba8165
commit
5a90d141ab
|
@ -13,7 +13,7 @@ type Component struct {
|
||||||
Title string
|
Title string
|
||||||
Location config.Location
|
Location config.Location
|
||||||
Size config.Size
|
Size config.Size
|
||||||
RefreshRateMs int
|
RateMs int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewComponent(dbl ui.Drawable, cmr *data.Consumer, cfg config.ComponentConfig) *Component {
|
func NewComponent(dbl ui.Drawable, cmr *data.Consumer, cfg config.ComponentConfig) *Component {
|
||||||
|
@ -24,7 +24,7 @@ func NewComponent(dbl ui.Drawable, cmr *data.Consumer, cfg config.ComponentConfi
|
||||||
Title: cfg.Title,
|
Title: cfg.Title,
|
||||||
Location: cfg.GetLocation(),
|
Location: cfg.GetLocation(),
|
||||||
Size: cfg.GetSize(),
|
Size: cfg.GetSize(),
|
||||||
RefreshRateMs: *cfg.RefreshRateMs,
|
RateMs: *cfg.RateMs,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ func NewRunChart(c config.RunChartConfig, palette console.Palette) *RunChart {
|
||||||
Block: component.NewBlock(c.Title, true, palette),
|
Block: component.NewBlock(c.Title, true, palette),
|
||||||
Consumer: data.NewConsumer(),
|
Consumer: data.NewConsumer(),
|
||||||
lines: []TimeLine{},
|
lines: []TimeLine{},
|
||||||
timescale: calculateTimescale(*c.RefreshRateMs),
|
timescale: calculateTimescale(*c.RateMs),
|
||||||
mutex: &sync.Mutex{},
|
mutex: &sync.Mutex{},
|
||||||
scale: *c.Scale,
|
scale: *c.Scale,
|
||||||
mode: ModeDefault,
|
mode: ModeDefault,
|
||||||
|
@ -367,9 +367,9 @@ func getMidRangeTime(r TimeRange) time.Time {
|
||||||
}
|
}
|
||||||
|
|
||||||
// time duration between grid lines
|
// time duration between grid lines
|
||||||
func calculateTimescale(refreshRateMs int) time.Duration {
|
func calculateTimescale(rateMs int) time.Duration {
|
||||||
|
|
||||||
multiplier := refreshRateMs * xAxisGridWidth / 2
|
multiplier := rateMs * xAxisGridWidth / 2
|
||||||
timescale := time.Duration(time.Millisecond * time.Duration(multiplier)).Round(time.Second)
|
timescale := time.Duration(time.Millisecond * time.Duration(multiplier)).Round(time.Second)
|
||||||
|
|
||||||
if timescale.Seconds() == 0 {
|
if timescale.Seconds() == 0 {
|
||||||
|
|
|
@ -32,7 +32,7 @@ runcharts:
|
||||||
sample: mongo --quiet --host=localhost blog --eval "db.getCollection('posts').find({status:'INACTIVE'}).itcount()"
|
sample: mongo --quiet --host=localhost blog --eval "db.getCollection('posts').find({status:'INACTIVE'}).itcount()"
|
||||||
barcharts:
|
barcharts:
|
||||||
- title: EVENTS BY STATUS
|
- title: EVENTS BY STATUS
|
||||||
refresh-rate-ms: 1000
|
rate-ms: 1000
|
||||||
position: [[0, 17], [27, 12]]
|
position: [[0, 17], [27, 12]]
|
||||||
scale: 0
|
scale: 0
|
||||||
items:
|
items:
|
||||||
|
|
|
@ -18,7 +18,7 @@ const (
|
||||||
|
|
||||||
type ComponentConfig struct {
|
type ComponentConfig struct {
|
||||||
Title string `yaml:"title"`
|
Title string `yaml:"title"`
|
||||||
RefreshRateMs *int `yaml:"refresh-rate-ms,omitempty"`
|
RateMs *int `yaml:"rate-ms,omitempty"`
|
||||||
Position [][]int `yaml:"position,flow"`
|
Position [][]int `yaml:"position,flow"`
|
||||||
Triggers []TriggerConfig `yaml:"triggers,omitempty"`
|
Triggers []TriggerConfig `yaml:"triggers,omitempty"`
|
||||||
Type ComponentType `yaml:",omitempty"`
|
Type ComponentType `yaml:",omitempty"`
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultRefreshRateMs = 1000
|
defaultRateMs = 1000
|
||||||
defaultScale = 1
|
defaultScale = 1
|
||||||
defaultTheme = console.ThemeDark
|
defaultTheme = console.ThemeDark
|
||||||
)
|
)
|
||||||
|
@ -28,9 +28,9 @@ func (c *Config) setDefaultValues() {
|
||||||
setDefaultTriggersValues(chart.Triggers)
|
setDefaultTriggersValues(chart.Triggers)
|
||||||
chart.ComponentConfig.Type = TypeRunChart
|
chart.ComponentConfig.Type = TypeRunChart
|
||||||
|
|
||||||
if chart.RefreshRateMs == nil {
|
if chart.RateMs == nil {
|
||||||
r := defaultRefreshRateMs
|
r := defaultRateMs
|
||||||
chart.RefreshRateMs = &r
|
chart.RateMs = &r
|
||||||
}
|
}
|
||||||
if chart.Scale == nil {
|
if chart.Scale == nil {
|
||||||
p := defaultScale
|
p := defaultScale
|
||||||
|
@ -49,9 +49,9 @@ func (c *Config) setDefaultValues() {
|
||||||
line.ComponentConfig.Type = TypeSparkLine
|
line.ComponentConfig.Type = TypeSparkLine
|
||||||
line.Item.Label = &line.Title
|
line.Item.Label = &line.Title
|
||||||
|
|
||||||
if line.RefreshRateMs == nil {
|
if line.RateMs == nil {
|
||||||
r := defaultRefreshRateMs
|
r := defaultRateMs
|
||||||
line.RefreshRateMs = &r
|
line.RateMs = &r
|
||||||
}
|
}
|
||||||
if line.Scale == nil {
|
if line.Scale == nil {
|
||||||
p := defaultScale
|
p := defaultScale
|
||||||
|
@ -65,9 +65,9 @@ func (c *Config) setDefaultValues() {
|
||||||
setDefaultTriggersValues(chart.Triggers)
|
setDefaultTriggersValues(chart.Triggers)
|
||||||
chart.ComponentConfig.Type = TypeBarChart
|
chart.ComponentConfig.Type = TypeBarChart
|
||||||
|
|
||||||
if chart.RefreshRateMs == nil {
|
if chart.RateMs == nil {
|
||||||
r := defaultRefreshRateMs
|
r := defaultRateMs
|
||||||
chart.RefreshRateMs = &r
|
chart.RateMs = &r
|
||||||
}
|
}
|
||||||
if chart.Scale == nil {
|
if chart.Scale == nil {
|
||||||
p := defaultScale
|
p := defaultScale
|
||||||
|
@ -81,9 +81,9 @@ func (c *Config) setDefaultValues() {
|
||||||
setDefaultTriggersValues(g.Triggers)
|
setDefaultTriggersValues(g.Triggers)
|
||||||
g.ComponentConfig.Type = TypeGauge
|
g.ComponentConfig.Type = TypeGauge
|
||||||
|
|
||||||
if g.RefreshRateMs == nil {
|
if g.RateMs == nil {
|
||||||
r := defaultRefreshRateMs
|
r := defaultRateMs
|
||||||
g.RefreshRateMs = &r
|
g.RateMs = &r
|
||||||
}
|
}
|
||||||
if g.Scale == nil {
|
if g.Scale == nil {
|
||||||
p := defaultScale
|
p := defaultScale
|
||||||
|
@ -106,9 +106,9 @@ func (c *Config) setDefaultValues() {
|
||||||
setDefaultTriggersValues(box.Triggers)
|
setDefaultTriggersValues(box.Triggers)
|
||||||
box.ComponentConfig.Type = TypeAsciiBox
|
box.ComponentConfig.Type = TypeAsciiBox
|
||||||
|
|
||||||
if box.RefreshRateMs == nil {
|
if box.RateMs == nil {
|
||||||
r := defaultRefreshRateMs
|
r := defaultRateMs
|
||||||
box.RefreshRateMs = &r
|
box.RateMs = &r
|
||||||
}
|
}
|
||||||
if box.Label == nil {
|
if box.Label == nil {
|
||||||
label := string(i)
|
label := string(i)
|
||||||
|
|
|
@ -18,7 +18,7 @@ type Item struct {
|
||||||
InitScript *string
|
InitScript *string
|
||||||
TransformScript *string
|
TransformScript *string
|
||||||
Color *ui.Color
|
Color *ui.Color
|
||||||
RefreshRateMs int
|
RateMs int
|
||||||
InteractiveShell *InteractiveShell
|
InteractiveShell *InteractiveShell
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ type InteractiveShell struct {
|
||||||
Cmd *exec.Cmd
|
Cmd *exec.Cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewItems(cfgs []config.Item, refreshRateMs int) []*Item {
|
func NewItems(cfgs []config.Item, rateMs int) []*Item {
|
||||||
|
|
||||||
items := make([]*Item, 0)
|
items := make([]*Item, 0)
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ func NewItems(cfgs []config.Item, refreshRateMs int) []*Item {
|
||||||
InitScript: i.InitScript,
|
InitScript: i.InitScript,
|
||||||
TransformScript: i.TransformScript,
|
TransformScript: i.TransformScript,
|
||||||
Color: i.Color,
|
Color: i.Color,
|
||||||
RefreshRateMs: refreshRateMs,
|
RateMs: rateMs,
|
||||||
}
|
}
|
||||||
items = append(items, item)
|
items = append(items, item)
|
||||||
}
|
}
|
||||||
|
@ -136,7 +136,7 @@ func (i *Item) executeInteractiveShellCmd(variables []string) (string, error) {
|
||||||
timeout := make(chan bool, 1)
|
timeout := make(chan bool, 1)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(time.Duration(i.RefreshRateMs))
|
time.Sleep(time.Duration(i.RateMs))
|
||||||
timeout <- true
|
timeout <- true
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
|
@ -84,15 +84,15 @@ func (h *Handler) handleExit() {
|
||||||
|
|
||||||
func calcMinRenderRate(layout *layout.Layout) time.Duration {
|
func calcMinRenderRate(layout *layout.Layout) time.Duration {
|
||||||
|
|
||||||
minRefreshRateMs := layout.Components[0].RefreshRateMs
|
minRateMs := layout.Components[0].RateMs
|
||||||
for _, c := range layout.Components {
|
for _, c := range layout.Components {
|
||||||
if c.RefreshRateMs < minRefreshRateMs {
|
if c.RateMs < minRateMs {
|
||||||
minRefreshRateMs = c.RefreshRateMs
|
minRateMs = c.RateMs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
renderRate := time.Duration(
|
renderRate := time.Duration(
|
||||||
int(float64(minRefreshRateMs)*refreshRateToRenderRateRatio)) * time.Millisecond
|
int(float64(minRateMs)*refreshRateToRenderRateRatio)) * time.Millisecond
|
||||||
|
|
||||||
if renderRate < console.MinRenderInterval {
|
if renderRate < console.MinRenderInterval {
|
||||||
return console.MinRenderInterval
|
return console.MinRenderInterval
|
||||||
|
|
2
main.go
2
main.go
|
@ -25,7 +25,7 @@ type Starter struct {
|
||||||
func (s *Starter) start(drawable ui.Drawable, consumer *data.Consumer, componentConfig config.ComponentConfig, itemsConfig []config.Item, triggersConfig []config.TriggerConfig) {
|
func (s *Starter) start(drawable ui.Drawable, consumer *data.Consumer, componentConfig config.ComponentConfig, itemsConfig []config.Item, triggersConfig []config.TriggerConfig) {
|
||||||
cpt := component.NewComponent(drawable, consumer, componentConfig)
|
cpt := component.NewComponent(drawable, consumer, componentConfig)
|
||||||
triggers := data.NewTriggers(triggersConfig, consumer, s.opt, s.player)
|
triggers := data.NewTriggers(triggersConfig, consumer, s.opt, s.player)
|
||||||
data.NewSampler(consumer, data.NewItems(itemsConfig, *componentConfig.RefreshRateMs), triggers, s.opt, *componentConfig.RefreshRateMs)
|
data.NewSampler(consumer, data.NewItems(itemsConfig, *componentConfig.RateMs), triggers, s.opt, *componentConfig.RateMs)
|
||||||
s.lout.AddComponent(cpt)
|
s.lout.AddComponent(cpt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue