Specific begin/end of time period, changed duration of period
This commit is contained in:
14
main.go
14
main.go
@@ -26,7 +26,7 @@ const (
|
|||||||
DATABASE_NAME = "file:gokeystat.db?cache=shared&mode=rwc"
|
DATABASE_NAME = "file:gokeystat.db?cache=shared&mode=rwc"
|
||||||
|
|
||||||
// time in seconds between capturing keyboard to db
|
// time in seconds between capturing keyboard to db
|
||||||
CAPTURE_TIME = 5
|
CAPTURE_TIME = 900
|
||||||
)
|
)
|
||||||
|
|
||||||
// StatForTime stotres pressed keys and beginning time
|
// StatForTime stotres pressed keys and beginning time
|
||||||
@@ -36,8 +36,8 @@ type StatForTime struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Init set time to Now().Unix() and keys to empty map
|
// Init set time to Now().Unix() and keys to empty map
|
||||||
func (stat *StatForTime) Init() {
|
func (stat *StatForTime) Init(timePeriodEnd int64) {
|
||||||
stat.time = time.Now().Unix()
|
stat.time = timePeriodEnd - CAPTURE_TIME
|
||||||
stat.keys = make(map[uint8]int)
|
stat.keys = make(map[uint8]int)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -322,8 +322,9 @@ func main() {
|
|||||||
// output of xinput command
|
// output of xinput command
|
||||||
buf := make([]byte, KEYBOARD_BUFER_SIZE)
|
buf := make([]byte, KEYBOARD_BUFER_SIZE)
|
||||||
|
|
||||||
|
timePeriodEnd := time.Now().Unix() - time.Now().Unix()%CAPTURE_TIME + CAPTURE_TIME
|
||||||
var curStat StatForTime
|
var curStat StatForTime
|
||||||
curStat.Init()
|
curStat.Init(timePeriodEnd)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
n, err := stdout.Read(buf)
|
n, err := stdout.Read(buf)
|
||||||
@@ -337,9 +338,10 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Every CAPTURE_TIME seconds save to BD
|
// Every CAPTURE_TIME seconds save to BD
|
||||||
if time.Now().Unix()-curStat.time > CAPTURE_TIME {
|
if time.Now().Unix()-timePeriodEnd > 0 {
|
||||||
AddStatTimeToDb(db, curStat, keyMap)
|
AddStatTimeToDb(db, curStat, keyMap)
|
||||||
curStat.Init()
|
timePeriodEnd += CAPTURE_TIME
|
||||||
|
curStat.Init(timePeriodEnd)
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(SLEEP_TIME)
|
time.Sleep(SLEEP_TIME)
|
||||||
|
|||||||
Reference in New Issue
Block a user