Skip to content

Commit c1239ee

Browse files
committed
test mode for local dev
1 parent b2fe089 commit c1239ee

14 files changed

Lines changed: 86 additions & 95 deletions

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Activity tracker
22

3-
[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go) [![codecov](https://codecov.io/gh/prashantgupta24/activity-tracker/branch/master/graph/badge.svg)](https://codecov.io/gh/prashantgupta24/activity-tracker) [![Go Report Card](https://goreportcard.com/badge/github.com/prashantgupta24/activity-tracker)](https://goreportcard.com/report/github.com/prashantgupta24/activity-tracker) [![version][version-badge]][RELEASES]
3+
[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go) [![codecov](https://codecov.io/gh/resousse/activity-tracker/branch/master/graph/badge.svg)](https://codecov.io/gh/prashantgupta24/activity-tracker) [![Go Report Card](https://goreportcard.com/badge/github.com/prashantgupta24/activity-tracker)](https://goreportcard.com/report/github.com/prashantgupta24/activity-tracker) [![version][version-badge]][RELEASES]
44

55
It is a libary that lets you monitor certain activities on your machine, and then sends a [heartbeat](https://github.com/prashantgupta24/activity-tracker#heartbeat-struct) at a periodic (configurable) time detailing all the activity changes during that time. The activities that you want to track are monitored by **pluggable** handlers for those activities and can be added or removed according to your needs. An example of an activity is `MouseCursorActivity`, i.e. whether your mouse cursor was moved or not.
66

@@ -212,12 +212,12 @@ Thanks to [robotgo](https://github.com/go-vgo/robotgo) for making a lot of the h
212212

213213
## Example
214214

215-
Check out the example [here](https://github.com/prashantgupta24/activity-tracker/blob/master/example/example.go)
215+
Check out the example [here](https://github.com/resousse/activity-tracker/blob/master/example/example.go)
216216

217217
## Projects using this library
218218

219219
- [automatic-mouse-mover](https://github.com/prashantgupta24/automatic-mouse-mover): a minimalistic go library/app to prevent your mac from going to sleep
220220

221221

222222
[version-badge]: https://img.shields.io/github/release/prashantgupta24/activity-tracker.svg
223-
[RELEASES]: https://github.com/prashantgupta24/activity-tracker/releases
223+
[RELEASES]: https://github.com/resousse/activity-tracker/releases

doc.go

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@ at a periodic (configurable) time detailing all the activity changes during that
44
to track are monitored by pluggable handlers for those activities and can be added or removed according to
55
your needs. An example of an activity is MouseCursorActivity, i.e. whether your mouse cursor was moved or not.
66
7-
Installation
7+
# Installation
88
99
The library can be installed using:
1010
1111
go get -u github.com/prashantgupta24/activity-tracker
1212
13-
Usage
13+
# Usage
1414
1515
The usage is as following:
1616
17-
1817
heartbeatInterval := 60 //value always in seconds
1918
workerInterval := 5 //seconds
2019
@@ -46,16 +45,14 @@ The usage is as following:
4645
}
4746
}
4847
49-
50-
Output
48+
# Output
5149
5250
The above code created a tracker with all
5351
('Mouse-click', 'Mouse-movement', 'screen-change' and 'machine-sleep') handlers activated.
5452
5553
The heartbeat Interval is set to 60 seconds, i.e. every 60 seconds
5654
I received a heartbeat which mentioned all activities that were captured.
5755
58-
5956
INFO[2019-03-30T15:52:01-07:00] starting activity tracker with 60s heartbeat and 5s worker Interval...
6057
6158
INFO[2019-03-30T15:53:01-07:00] activity detected in the last 60 seconds.
@@ -67,20 +64,19 @@ I received a heartbeat which mentioned all activities that were captured.
6764
INFO[2019-03-30T15:53:01-07:00] activityType : machine-sleep times: 1
6865
INFO[2019-03-30T15:53:01-07:00] activityType : machine-wake times: 1
6966
70-
71-
How it works
67+
# How it works
7268
7369
There are 2 primary configs required for the tracker to work:
7470
75-
- HeartbeatInterval
71+
- HeartbeatInterval
7672
77-
The Interval at which you want the heartbeat (in seconds, default 60s)
73+
The Interval at which you want the heartbeat (in seconds, default 60s)
7874
7975
and
8076
81-
- WorkerInterval
77+
- WorkerInterval
8278
83-
The Interval at which you want the checks to happen within a heartbeat (default 60s).
79+
The Interval at which you want the checks to happen within a heartbeat (default 60s).
8480
8581
The activity tracker gives you a heartbeat object every 60 seconds, that is based on the
8682
'HeartbeatInterval'. But there is something else to understand here. In order for the
@@ -113,14 +109,13 @@ you might want to set the 'WorkerInterval' to a low value, so that it keeps quer
113109
you can set 'WorkerInterval' to a high number (something around 10-15 seconds should do the
114110
trick). That way, the workers need not be bothered a lot of times within a 'heartbeat'.
115111
116-
117112
Note: If the 'WorkerInterval' and the 'HeartbeatInterval' are set the same, then the
118113
'WorkerInterval' always is started a fraction of a second before the 'HeartbeatInterval'
119114
kicks in. This is done so that when the 'heartbeat' is going to be generated at the end
120115
of 'HeartbeatInterval', the worker should have done its job of querying each of the
121116
handlers before that.
122117
123-
Usecase
118+
# Usecase
124119
125120
Suppose you want to track Activities A, B and C on your machine, and you want to know
126121
how many times they occurred every minute.
@@ -140,8 +135,7 @@ to 5 minutes. The 'Start' function of the library gives you a channel which rece
140135
a 'heartbeat' every 5 minutes, and it has details on whether there was a 'click' in
141136
those 5 minutes, and if yes, the times the click happened.
142137
143-
144-
Components
138+
# Components
145139
146140
- Heartbeat struct
147141
@@ -153,15 +147,14 @@ It is the data packet sent from the tracker library to the user.
153147
Time time.Time //heartbeat time
154148
}
155149
156-
157150
'WasAnyActivity' tells if there was any activity within that time frame
158151
If there was, then the 'ActivityMap' will tell you what type of activity it was and
159152
what all times it occurred.
160153
161154
The 'Time' field is the time of the Heartbeat sent (not to be confused with
162155
the activity time, which is the time the activity occurred within the 'heartbeat').
163156
164-
Tracker
157+
# Tracker
165158
166159
The tracker is the main struct for the library. The fields inside it are:
167160
@@ -170,7 +163,6 @@ The tracker is the main struct for the library. The fields inside it are:
170163
LogLevel string //info or debug
171164
LogFormat string //text or json
172165
173-
174166
'HeartbeatInterval'
175167
176168
The Interval at which you want the heartbeat (in seconds, default 60s)
@@ -187,7 +179,7 @@ The 'WorkerInterval ' value can be set anywhere between 4 seconds - 60 seconds.
187179
CANNOT be more than 'HeartbeatInterval' for obvious reasons. Not setting it or setting
188180
it to anything other than the allowed range will revert it to default of 60s.
189181
190-
State
182+
# State
191183
192184
The 'system.State' struct captures the current state of the tracker, and the whole system
193185
in general. It is used by some of the handlers to respond to a certain system state.
@@ -201,7 +193,7 @@ system remains in the sleep state.
201193
202194
Note: It also serves as a way of inter-handler communication.
203195
204-
Types of handlers
196+
# Types of handlers
205197
206198
There are 2 types of handlers:
207199
@@ -222,7 +214,7 @@ It is up to you to define how to implement the handler. Some make sense to be pu
222214
since it is going to be memory intensive to make the mouse cursor movement handler
223215
push-based. It made sense to make it 'pull' based.
224216
225-
New pluggable handlers for activities
217+
# New pluggable handlers for activities
226218
227219
Any new type of handler for an activity can be easily added, it just needs to
228220
implement the above 'Handler' interface below:
@@ -233,7 +225,6 @@ implement the above 'Handler' interface below:
233225
Trigger(system.State) //used to activate pull-based handlers
234226
Close()
235227
236-
237228
It also needs to define what 'type' of activity it is going to
238229
track (also add the new 'activity' as well if it's a new activity), that's it! It can
239230
be plugged in with the tracker and then the tracker will include those activity checks
@@ -246,7 +237,7 @@ On the other hand, each activity should be tracked by only ONE handler (which ma
246237
As a fail-safe, if the tracker is started with more than one handler tracking the same
247238
activity, then only 1 handler will get registered for that activity.
248239
249-
Supported list of activities and their handlers
240+
# Supported list of activities and their handlers
250241
251242
Currently supported activities are:
252243
@@ -263,14 +254,13 @@ Corresponding handlers:
263254
screenChangeHandler
264255
machineSleepHandler
265256
266-
267257
- Mouse click (whether any mouse click happened during the time frame)
268258
- Mouse cursor movement (whether the mouse cursor was moved during the time frame)
269259
- Screen change handler (whether the active window was changed)
270260
- Machine sleep/wake handler (**this is added by default for fail-safe measures**)
271261
272-
Example
262+
# Example
273263
274-
Check out the example here : https://github.com/prashantgupta24/activity-tracker/blob/master/example/example.go
264+
Check out the example here : https://github.com/resousse/activity-tracker/blob/master/example/example.go
275265
*/
276266
package main

example/example.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"fmt"
55
"time"
66

7-
"github.com/prashantgupta24/activity-tracker/internal/pkg/logging"
8-
"github.com/prashantgupta24/activity-tracker/pkg/tracker"
7+
"github.com/resousse/activity-tracker/internal/pkg/logging"
8+
"github.com/resousse/activity-tracker/pkg/tracker"
99
)
1010

1111
func main() {

internal/pkg/handler/handler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package handler
22

33
import (
4-
"github.com/prashantgupta24/activity-tracker/pkg/activity"
5-
"github.com/prashantgupta24/activity-tracker/pkg/system"
4+
"github.com/resousse/activity-tracker/pkg/activity"
5+
"github.com/resousse/activity-tracker/pkg/system"
66
log "github.com/sirupsen/logrus"
77
)
88

99
const (
1010
timeout = 100 //ms
1111
)
1212

13-
//Instance is the main interface for a handler for the tracker
13+
// Instance is the main interface for a handler for the tracker
1414
type Instance interface {
1515
Start(*log.Logger, chan *activity.Instance)
1616
Type() activity.Type

internal/pkg/handler/machineSleepHandler.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package handler
22

33
import (
4-
"github.com/prashantgupta24/activity-tracker/pkg/activity"
5-
"github.com/prashantgupta24/activity-tracker/pkg/system"
64
"github.com/prashantgupta24/mac-sleep-notifier/notifier"
5+
"github.com/resousse/activity-tracker/pkg/activity"
6+
"github.com/resousse/activity-tracker/pkg/system"
77
log "github.com/sirupsen/logrus"
88
)
99

@@ -12,13 +12,13 @@ const (
1212
machineWake = activity.MachineWake
1313
)
1414

15-
//MachineSleepHanderStruct is a handler for machine sleep/awake related events
15+
// MachineSleepHanderStruct is a handler for machine sleep/awake related events
1616
type MachineSleepHanderStruct struct {
1717
sleepHandlerLogger *log.Entry
1818
quit chan struct{}
1919
}
2020

21-
//Start the handler
21+
// Start the handler
2222
func (m *MachineSleepHanderStruct) Start(logger *log.Logger, activityCh chan *activity.Instance) {
2323
m.quit = make(chan struct{})
2424
m.sleepHandlerLogger = logger.WithFields(log.Fields{
@@ -57,20 +57,20 @@ func (m *MachineSleepHanderStruct) Start(logger *log.Logger, activityCh chan *ac
5757
}()
5858
}
5959

60-
//MachineSleepHandler returns an instance of the struct
60+
// MachineSleepHandler returns an instance of the struct
6161
func MachineSleepHandler() *MachineSleepHanderStruct {
6262
return &MachineSleepHanderStruct{}
6363
}
6464

65-
//Type returns the type of handler
65+
// Type returns the type of handler
6666
func (m *MachineSleepHanderStruct) Type() activity.Type {
6767
return machineSleep
6868
}
6969

70-
//Trigger the handler - empty since it's a push based handler
70+
// Trigger the handler - empty since it's a push based handler
7171
func (m *MachineSleepHanderStruct) Trigger(system.State) {}
7272

73-
//Close closes the handler
73+
// Close closes the handler
7474
func (m *MachineSleepHanderStruct) Close() {
7575
m.quit <- struct{}{}
7676
}

internal/pkg/handler/mouseClickHandler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package handler
33
import (
44
log "github.com/sirupsen/logrus"
55

6-
"github.com/prashantgupta24/activity-tracker/pkg/activity"
7-
"github.com/prashantgupta24/activity-tracker/pkg/system"
6+
"github.com/resousse/activity-tracker/pkg/activity"
7+
"github.com/resousse/activity-tracker/pkg/system"
88
hook "github.com/robotn/gohook"
99
)
1010

internal/pkg/handler/mouseCursorHandler.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ import (
55

66
log "github.com/sirupsen/logrus"
77

8-
"github.com/prashantgupta24/activity-tracker/internal/pkg/mouse"
9-
"github.com/prashantgupta24/activity-tracker/pkg/activity"
10-
"github.com/prashantgupta24/activity-tracker/pkg/system"
8+
"github.com/resousse/activity-tracker/internal/pkg/mouse"
9+
"github.com/resousse/activity-tracker/pkg/activity"
10+
"github.com/resousse/activity-tracker/pkg/system"
1111
)
1212

1313
const (
1414
mouseMoveActivity = activity.MouseCursorMovement
1515
)
1616

17-
//MouseCursorHandlerStruct is the handler for mouse cursor movements
17+
// MouseCursorHandlerStruct is the handler for mouse cursor movements
1818
type MouseCursorHandlerStruct struct {
1919
cursurHandlerLogger *log.Entry
2020
tickerCh chan struct{}
@@ -25,7 +25,7 @@ type cursorInfo struct {
2525
currentMousePos *mouse.Position
2626
}
2727

28-
//Start the handler
28+
// Start the handler
2929
func (m *MouseCursorHandlerStruct) Start(logger *log.Logger, activityCh chan *activity.Instance) {
3030

3131
m.tickerCh = make(chan struct{})
@@ -57,12 +57,12 @@ func (m *MouseCursorHandlerStruct) Start(logger *log.Logger, activityCh chan *ac
5757
}()
5858
}
5959

60-
//MouseCursorHandler returns an instance of the struct
60+
// MouseCursorHandler returns an instance of the struct
6161
func MouseCursorHandler() *MouseCursorHandlerStruct {
6262
return &MouseCursorHandlerStruct{}
6363
}
6464

65-
//Trigger the handler
65+
// Trigger the handler
6666
func (m *MouseCursorHandlerStruct) Trigger(state system.State) {
6767
//no point triggering the handler since the system is asleep
6868
if state.IsSystemSleep {
@@ -77,12 +77,12 @@ func (m *MouseCursorHandlerStruct) Trigger(state system.State) {
7777
}
7878
}
7979

80-
//Type returns the type of handler
80+
// Type returns the type of handler
8181
func (m *MouseCursorHandlerStruct) Type() activity.Type {
8282
return mouseMoveActivity
8383
}
8484

85-
//Close closes the handler
85+
// Close closes the handler
8686
func (m *MouseCursorHandlerStruct) Close() {
8787
close(m.tickerCh)
8888
}

0 commit comments

Comments
 (0)