reportier 0.5.6 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35c22449bf729329f9138fd15ec42ed74203bd9f
4
- data.tar.gz: 73c282dd8a894e9d9a7d92084c8e2ebea0662a8d
3
+ metadata.gz: 370f511dd07462a7eee6dbabe9ed0b69a1ad3871
4
+ data.tar.gz: 7663e4fb47322832da7aa8cd42234200a5fe093c
5
5
  SHA512:
6
- metadata.gz: 94527640a1856e2085ff45fe9dc9cdec99cc7cf0ac48cc18daa582496ecfe6113d2d2034baf4ba364fc955ccf533edcbd0d5d8ec979d227260dacb0257d03362
7
- data.tar.gz: b0fdf328874cd417415e6fd1781776ea9df3630532eb92974ccf5c834fa67cb7d1b0f276be136d1e46ca71402f2c83d827ebf96f677ec4ef989d200ac469e817
6
+ metadata.gz: 0281eecb8827893f544d8e32bb0c833c7224b360932fa9fe1585abb3ea728eff8824b8d22e183a2885e2c2e77d48bfe1e8fe223076a692671c5034290728cc19
7
+ data.tar.gz: 0e90955b777f0d2bb6c8a923126150f1506b04c74b6cc4c8c8290661cc6b2fedd695341f1a76b9b975c7e73682e5574ee331bb94f20929e4c33b9e769f2f4199
data/README.md CHANGED
@@ -1,75 +1,95 @@
1
1
  # Reportier the stat tracker
2
2
 
3
- This is a tracker that tracks the count of events.
3
+ This is a tracker that tracks the count of events. Most notable is that
4
+ as long as you keep addng items reportier will report automatically
5
+ without using 3rd party software like cron.
6
+
7
+ ## Usage
4
8
 
5
- ## Use
6
9
  `gem 'reportier'`
7
10
 
8
- Using the Tracker is fairly simple, by default there are 4 types of trackers.
9
- An `Hourly`, a `Daily` a `Weekly` and a `Monthly`.
10
- To add something to a tracker simply `.get` it and `#add` something.
11
+ Use Reportier to track how manny times something happened in a certain ammount of time.
12
+ Reportier has a minimal public interface however is quite powerfull inside.
11
13
 
12
- You can also `#report` the current state of the tracker, however trackers report and reset by themselves
13
- as long as you keep adding items to them.
14
+ To use first configure it with intervals by setting a name and when to report
14
15
 
15
- Examples:
16
+ Reportier.configure do |c|
17
+ # Time is in seconds
18
+ c.trackers = {
19
+ hourly: 60 * 60,
20
+ bidaily: 60 * 60 * 24 * 2
21
+ }
22
+ end
16
23
 
17
- ```
18
- Reportier::Tracker[:daily].add('new user registration')
24
+ Then you can add items to trackers and it will keep track of them.
19
25
 
20
- Reportier::Tracker[:daily].report
21
- # -> Daily report started at 2016-06-17T15:34:40+03:00
22
- # @new_user_registrations: 1
26
+ ```
27
+ Reportier[:hourly].add "Home page visit"
28
+ # or
29
+ Reportier[:bidaily].add @newly_registered_user # object of type User
23
30
  ```
24
31
 
25
- You can also use `Reportier.add_to_all('we need to track this')` and it will add the item to all trackers.
26
- If you keep adding this way, each tracker will report when his time is due, and you have to worry about
27
- nothing else.
32
+ Note that you can add objects and Reporiter will track their class.
33
+ You can also add the item to all trackers by doing
28
34
 
29
- Trackers also have a `#to_json` method for converting tracked items to json.
35
+ ```
36
+ Reportier.add_to_all @item
37
+ ```
30
38
 
39
+ You can make the tracker report or convert it to json.
31
40
 
32
- ## Setting defaults
41
+ ```
42
+ Reportier[:daily].add('new user registration')
33
43
 
34
- Reportier has 3 methods for setting defaults.
44
+ Reportier[:daily].report
45
+ # -> Daily report started at 2016-06-17T15:34:40+03:00
46
+ # new_user_registrations: 1
35
47
 
36
- `.set_default_reporting_vars`
48
+ Reportier[:daily].to_json
49
+ # -> "{\"new_user_registrations\": 1}"
50
+ ```
37
51
 
38
- This is for setting default things you want to track. Example use would be.
52
+ Tracker check if they have expired everytime an item is added.
53
+ And they will reset and report when they realise that they
39
54
 
40
- ```
41
- Reportier.set_default_reporting_vars active_users: User.active, open_conversations: Conversation.all.count
42
- ```
55
+ ## Persistance
43
56
 
44
- `.set_default_types`
57
+ Reportier saves items to memory by default however we also support long time
58
+ persistance with redis, and maybe postgres in the future.
45
59
 
46
- This is for setting default tracker types, by type we mean how much time it needs for reset.
47
- So the usage would be
60
+ To use redis look on setting defaults below.
48
61
 
62
+ ## Setting defaults
63
+
64
+ ### Persister
65
+ Right now we only support memory and redis.
66
+ Select peristance like so.
49
67
 
50
68
  ```
51
- Reportier.set_default_types yearly: 1.year, bidaily: 2.days
69
+ Reportier.configure do |c|
70
+ c.persister = :redis
71
+ end
52
72
  ```
53
73
 
54
- These new tracker classes will be created and can be used normally like any other tracker,
55
- also `Reportier.add_to_all` will take this new classes in account.
56
- Note that if you don't use Rails you can `import` or `extend` `Reportier::Time` to you current environment
57
- and use `hours(1)`, `days(1)`, `weeks(1)`, `months(1)`, `years(1)`, years and months are not exact.
74
+ ### Reporters
58
75
 
59
- `.set_default_reporters`
60
-
61
- This is for setting default reporters, by default Reportier will only report to console
62
- but we also support reporting to slack and logger, and you can easily create your custom reporting methods.
76
+ By default Reportier will only report to logger and console
77
+ but we also support reporting to slack through slack-reporter and to logger,
78
+ and you can easily create your custom reporting methods.
63
79
 
64
80
  ```
65
- Reportier.set_default_reporters slack: 'slack-reporter', logger: 'logger'
81
+ Reportier.configure do |c|
82
+ c.reporters = { logger: 'logger', slack: 'slack-reporter' }
83
+ end
84
+
85
+ ## Note you need to ass 'slack-reporter' to your gemfile
66
86
  ```
67
87
 
68
88
  If you want to add custom reporters just add their name and library and then define a `to_#{name)` method to the `Reporter`
69
89
  e.x.
70
90
 
71
91
  ```
72
- Reportier.set_default_reporters twilio: 'twilio-ruby'
92
+ Reportier.configure { |c| c.reporters = { twilio: 'twilio-ruby' } }
73
93
 
74
94
  class Reportier::Reporter
75
95
  def to_twilio
@@ -78,6 +98,31 @@ class Reportier::Reporter
78
98
  end
79
99
  ```
80
100
 
81
- ### TODO
101
+ ### Default reporting vars
102
+
103
+ Sometimes its usefull no have stats from other services or modules.
104
+ To do that you can configure reportier to have some default reporting variables
82
105
 
83
- When persisted through redis trackers need to get their starting time from redis
106
+ ```
107
+ Reportier.configure do |c|
108
+ # For adding reporting vars
109
+ c.reporting_vars = { active_users: UserRepo.active.count }
110
+ # For updating existing reporting vars
111
+ c.update_reporting_vars {
112
+ todays_messages: Message.where('created_at > ?', Datetime.yesterday)
113
+ }
114
+ end
115
+
116
+ ### Full configuration
117
+
118
+ Ofcourse you can you all this in a single configuration in the startup of your
119
+ application. A full configuration would look something like this.
120
+
121
+ ```
122
+ Reportier.configure do |c|
123
+ c.persister = :redis
124
+ c.trackers = { daily: 60 * 60 * 24
125
+ c.reporters = { logger: 'logger', slack: 'slack-reporter' }
126
+ c.reporting_vars = { active_users: UserRepo.active.count }
127
+ end
128
+ ```
@@ -9,11 +9,15 @@ require_relative 'reportier/version'
9
9
 
10
10
  module Reportier
11
11
  def self.add_to_all(item)
12
- Defaults.global.types.each do |type, v|
12
+ Defaults.global.trackers.each do |type, v|
13
13
  Tracker[type].add(item)
14
14
  end
15
15
  end
16
16
 
17
+ def self.[](type)
18
+ Tracker[type]
19
+ end
20
+
17
21
  def self.configure(&blk)
18
22
  Defaults.global.configure &blk
19
23
  end
@@ -1,6 +1,6 @@
1
1
  module Reportier
2
2
  class Defaults
3
- attr_accessor :types, :reporting_vars, :reporters,
3
+ attr_accessor :trackers, :reporting_vars, :reporters,
4
4
  :persister
5
5
 
6
6
  def self.global
@@ -20,9 +20,9 @@ module Reportier
20
20
  @reporting_vars.merge!(hash)
21
21
  end
22
22
 
23
- def types=(opts)
24
- @types = Hash.new(0)
25
- @types.merge! opts
23
+ def trackers=(opts)
24
+ @trackers = Hash.new(0)
25
+ @trackers.merge! opts
26
26
  end
27
27
 
28
28
  def reporters=(opts)
@@ -33,9 +33,9 @@ module Reportier
33
33
  private
34
34
 
35
35
  def initialize_defaults
36
- @types = Hash.new(0)
36
+ @trackers = Hash.new(0)
37
37
  @reporting_vars = Hash.new
38
- @reporters = Hash.new
38
+ @reporters = { console: nil, logger: 'logger' }
39
39
  @persister = :memory
40
40
  end
41
41
 
@@ -21,7 +21,7 @@ module Reportier
21
21
 
22
22
  def add(item)
23
23
  (report && clear) unless active?
24
- return if Defaults.global.types[@type] == 0
24
+ return if Defaults.global.trackers[@type] == 0
25
25
  @persister.save(Namer.new.name_item(item))
26
26
  end
27
27
 
@@ -52,7 +52,7 @@ module Reportier
52
52
  end
53
53
 
54
54
  def expires_at
55
- get_date + Defaults.global.types[@type]
55
+ get_date + Defaults.global.trackers[@type]
56
56
  end
57
57
 
58
58
  def get_date
@@ -71,7 +71,7 @@ module Reportier
71
71
  end
72
72
 
73
73
  def _long_due?
74
- expires_at < (DateTime.now - Defaults.global.types[@type])
74
+ expires_at < (DateTime.now - Defaults.global.trackers[@type])
75
75
  end
76
76
  end
77
77
  end
@@ -1,3 +1,3 @@
1
1
  module Reportier
2
- VERSION = '0.5.6'
2
+ VERSION = '0.6.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reportier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.6
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vasilis Spilka