added usage time statistics
This commit is contained in:
parent
a506bb92eb
commit
d7d3831d7d
|
@ -10,29 +10,29 @@ import (
|
||||||
|
|
||||||
type Menu struct {
|
type Menu struct {
|
||||||
*ui.Block
|
*ui.Block
|
||||||
options []MenuOption
|
options []menuOption
|
||||||
component Component
|
component Component
|
||||||
mode MenuMode
|
mode menuMode
|
||||||
option MenuOption
|
option menuOption
|
||||||
palette console.Palette
|
palette console.Palette
|
||||||
}
|
}
|
||||||
|
|
||||||
type MenuMode rune
|
type menuMode rune
|
||||||
|
|
||||||
const (
|
const (
|
||||||
MenuModeIdle MenuMode = 0
|
menuModeIdle menuMode = 0
|
||||||
MenuModeHighlight MenuMode = 1
|
menuModeHighlight menuMode = 1
|
||||||
MenuModeOptionSelect MenuMode = 2
|
menuModeOptionSelect menuMode = 2
|
||||||
MenuModeMoveAndResize MenuMode = 3
|
menuModeMoveAndResize menuMode = 3
|
||||||
)
|
)
|
||||||
|
|
||||||
type MenuOption string
|
type menuOption string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
MenuOptionMove MenuOption = "MOVE"
|
MenuOptionMove menuOption = "MOVE"
|
||||||
MenuOptionResize MenuOption = "RESIZE"
|
MenuOptionResize menuOption = "RESIZE"
|
||||||
MenuOptionPinpoint MenuOption = "PINPOINT"
|
MenuOptionPinpoint menuOption = "PINPOINT"
|
||||||
MenuOptionResume MenuOption = "RESUME"
|
MenuOptionResume menuOption = "RESUME"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -42,30 +42,30 @@ const (
|
||||||
func NewMenu(palette console.Palette) *Menu {
|
func NewMenu(palette console.Palette) *Menu {
|
||||||
return &Menu{
|
return &Menu{
|
||||||
Block: NewBlock("", true, palette),
|
Block: NewBlock("", true, palette),
|
||||||
options: []MenuOption{MenuOptionMove, MenuOptionResize, MenuOptionPinpoint, MenuOptionResume},
|
options: []menuOption{MenuOptionMove, MenuOptionResize, MenuOptionPinpoint, MenuOptionResume},
|
||||||
mode: MenuModeIdle,
|
mode: menuModeIdle,
|
||||||
option: MenuOptionMove,
|
option: MenuOptionMove,
|
||||||
palette: palette,
|
palette: palette,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Menu) GetSelectedOption() MenuOption {
|
func (m *Menu) GetSelectedOption() menuOption {
|
||||||
return m.option
|
return m.option
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Menu) Highlight(component *Component) {
|
func (m *Menu) Highlight(component *Component) {
|
||||||
m.component = *component
|
m.component = *component
|
||||||
m.updateDimensions()
|
m.updateDimensions()
|
||||||
m.mode = MenuModeHighlight
|
m.mode = menuModeHighlight
|
||||||
m.Title = component.Title
|
m.Title = component.Title
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Menu) Choose() {
|
func (m *Menu) Choose() {
|
||||||
m.mode = MenuModeOptionSelect
|
m.mode = menuModeOptionSelect
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Menu) Idle() {
|
func (m *Menu) Idle() {
|
||||||
m.mode = MenuModeIdle
|
m.mode = menuModeIdle
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Menu) Up() {
|
func (m *Menu) Up() {
|
||||||
|
@ -93,12 +93,12 @@ func (m *Menu) Down() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Menu) MoveOrResize() {
|
func (m *Menu) MoveOrResize() {
|
||||||
m.mode = MenuModeMoveAndResize
|
m.mode = menuModeMoveAndResize
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Menu) Draw(buffer *ui.Buffer) {
|
func (m *Menu) Draw(buffer *ui.Buffer) {
|
||||||
|
|
||||||
if m.mode == MenuModeIdle {
|
if m.mode == menuModeIdle {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,11 +112,11 @@ func (m *Menu) Draw(buffer *ui.Buffer) {
|
||||||
m.Block.Draw(buffer)
|
m.Block.Draw(buffer)
|
||||||
|
|
||||||
switch m.mode {
|
switch m.mode {
|
||||||
case MenuModeHighlight:
|
case menuModeHighlight:
|
||||||
m.renderHighlight(buffer)
|
m.renderHighlight(buffer)
|
||||||
case MenuModeMoveAndResize:
|
case menuModeMoveAndResize:
|
||||||
m.renderMoveAndResize(buffer)
|
m.renderMoveAndResize(buffer)
|
||||||
case MenuModeOptionSelect:
|
case menuModeOptionSelect:
|
||||||
m.renderOptions(buffer)
|
m.renderOptions(buffer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,10 +56,10 @@ func (s *SparkLine) consumeSample(sample *data.Sample) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.HandleConsumeFailure("Failed to parse a number", err, sample)
|
s.HandleConsumeFailure("Failed to parse a number", err, sample)
|
||||||
return
|
return
|
||||||
} else {
|
|
||||||
s.HandleConsumeSuccess()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.HandleConsumeSuccess()
|
||||||
|
|
||||||
s.values = append(s.values, float)
|
s.values = append(s.values, float)
|
||||||
max, min := s.values[0], s.values[0]
|
max, min := s.values[0], s.values[0]
|
||||||
|
|
||||||
|
|
6
main.go
6
main.go
|
@ -77,6 +77,7 @@ func main() {
|
||||||
license := metadata.GetLicense()
|
license := metadata.GetLicense()
|
||||||
|
|
||||||
defer handleCrash(statistics, opt, bc)
|
defer handleCrash(statistics, opt, bc)
|
||||||
|
defer updateStatistics(cfg, time.Now())
|
||||||
|
|
||||||
if opt.LicenseKey != nil {
|
if opt.LicenseKey != nil {
|
||||||
registerLicense(statistics, opt, bc)
|
registerLicense(statistics, opt, bc)
|
||||||
|
@ -108,7 +109,6 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata.PersistStatistics(cfg)
|
|
||||||
starter := &Starter{player, lout, palette, opt, *cfg}
|
starter := &Starter{player, lout, palette, opt, *cfg}
|
||||||
samplers := starter.startAll()
|
samplers := starter.startAll()
|
||||||
|
|
||||||
|
@ -126,6 +126,10 @@ func handleCrash(statistics *metadata.Statistics, opt config.Options, bc *client
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func updateStatistics(cfg *config.Config, startTime time.Time) {
|
||||||
|
metadata.PersistStatistics(cfg, time.Since(startTime))
|
||||||
|
}
|
||||||
|
|
||||||
func registerLicense(statistics *metadata.Statistics, opt config.Options, bc *client.BackendClient) {
|
func registerLicense(statistics *metadata.Statistics, opt config.Options, bc *client.BackendClient) {
|
||||||
lc, err := bc.RegisterLicenseKey(*opt.LicenseKey, statistics)
|
lc, err := bc.RegisterLicenseKey(*opt.LicenseKey, statistics)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"log"
|
"log"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Statistics represents anonymous usage data, which we collect for analyses and improvements
|
// Statistics represents anonymous usage data, which we collect for analyses and improvements
|
||||||
|
@ -17,13 +18,13 @@ type Statistics struct {
|
||||||
WindowWidth int `yaml:"ww"`
|
WindowWidth int `yaml:"ww"`
|
||||||
WindowHeight int `yaml:"wh"`
|
WindowHeight int `yaml:"wh"`
|
||||||
LaunchCount int `yaml:"lc"`
|
LaunchCount int `yaml:"lc"`
|
||||||
|
UsageTime int `yaml:"ut"`
|
||||||
ComponentsCount map[string]int `yaml:"cc"`
|
ComponentsCount map[string]int `yaml:"cc"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const statisticsFileName = "statistics.yml"
|
const statisticsFileName = "statistics.yml"
|
||||||
|
|
||||||
// PersistStatistics in file
|
func PersistStatistics(config *config.Config, uptime time.Duration) *Statistics {
|
||||||
func PersistStatistics(config *config.Config) *Statistics {
|
|
||||||
|
|
||||||
statistics := new(Statistics)
|
statistics := new(Statistics)
|
||||||
w, h := ui.TerminalDimensions()
|
w, h := ui.TerminalDimensions()
|
||||||
|
@ -43,14 +44,16 @@ func PersistStatistics(config *config.Config) *Statistics {
|
||||||
statistics.WindowWidth = w
|
statistics.WindowWidth = w
|
||||||
statistics.WindowHeight = h
|
statistics.WindowHeight = h
|
||||||
statistics.LaunchCount += 1
|
statistics.LaunchCount += 1
|
||||||
|
statistics.UsageTime += int(uptime.Seconds())
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
statistics = &Statistics{
|
statistics = &Statistics{
|
||||||
Version: console.AppVersion,
|
Version: console.AppVersion,
|
||||||
OS: runtime.GOOS,
|
OS: runtime.GOOS,
|
||||||
LaunchCount: 1,
|
|
||||||
WindowWidth: w,
|
WindowWidth: w,
|
||||||
WindowHeight: h,
|
WindowHeight: h,
|
||||||
|
LaunchCount: 1,
|
||||||
|
UsageTime: 0,
|
||||||
ComponentsCount: countComponentsPerType(config),
|
ComponentsCount: countComponentsPerType(config),
|
||||||
}
|
}
|
||||||
initStorage()
|
initStorage()
|
||||||
|
@ -66,7 +69,6 @@ func PersistStatistics(config *config.Config) *Statistics {
|
||||||
return statistics
|
return statistics
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetStatistics from file
|
|
||||||
func GetStatistics(cfg *config.Config) *Statistics {
|
func GetStatistics(cfg *config.Config) *Statistics {
|
||||||
|
|
||||||
if !fileExists(statisticsFileName) {
|
if !fileExists(statisticsFileName) {
|
||||||
|
|
Loading…
Reference in New Issue