ruboty-stats 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +2 -0
- data/lib/ruboty/handlers/stats.rb +25 -0
- data/lib/ruboty/stats/actions/clear.rb +12 -0
- data/lib/ruboty/stats/actions/history.rb +13 -0
- data/lib/ruboty/stats/actions/stats.rb +23 -0
- data/lib/ruboty/stats/version.rb +5 -0
- data/lib/ruboty/stats.rb +33 -0
- data/ruboty-stats.gemspec +24 -0
- data/screenshot.png +0 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d7d0da07923c7536a63dab96c672b763ee63e7af
|
4
|
+
data.tar.gz: df8775db86a67727e48fb7eb658eb1c25fe9983e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b8444c27c9588ab725c4de7b123759449df80dd15a0e0f176e2d311aef45e61e3c653c4b68a67a55ae49d72e3adbba6a7d67d3290ba9440142ab8002d062ddc8
|
7
|
+
data.tar.gz: 9554858eaa90df7aa3943987ec41421ffed68fbda537169da1df9464b4f420671e49ba13063fc6c9103137fdbc6a29b9de27cd2bc7498b4bf9968abd062e92a4
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 block_given?
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Ruboty::Stats
|
2
|
+
|
3
|
+
ruboty plugin for record action stats.
|
4
|
+
|
5
|
+
![screenshot](screenshot.png)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'ruboty-stats'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install ruboty-stats
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
@ruboty stats
|
26
|
+
@ruboty stats Ruboty::Handlers::Stats#stats
|
27
|
+
@ruboty stats clear
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it ( https://github.com/blockgiven/ruboty-stats/fork )
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "ruboty/stats/actions/clear"
|
2
|
+
require "ruboty/stats/actions/history"
|
3
|
+
require "ruboty/stats/actions/stats"
|
4
|
+
|
5
|
+
module Ruboty
|
6
|
+
module Handlers
|
7
|
+
class Stats < Base
|
8
|
+
on /stats$/, name: 'stats', description: 'show stats'
|
9
|
+
on /stats (?<action_name>.*)/, name: 'history', description: 'show action_name history'
|
10
|
+
on /stats clear$/, name: 'clear', description: 'clear stats'
|
11
|
+
|
12
|
+
def clear(message)
|
13
|
+
Ruboty::Stats::Actions::Clear.new(message).call
|
14
|
+
end
|
15
|
+
|
16
|
+
def history(message)
|
17
|
+
Ruboty::Stats::Actions::History.new(message).call
|
18
|
+
end
|
19
|
+
|
20
|
+
def stats(message)
|
21
|
+
Ruboty::Stats::Actions::Stats.new(message).call
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Ruboty
|
2
|
+
module Stats
|
3
|
+
module Actions
|
4
|
+
class History < Ruboty::Actions::Base
|
5
|
+
def call
|
6
|
+
history = (::Ruboty::Stats.stats(message.robot)[message[:action_name]] || []).sort_by {|h| h[:time] }
|
7
|
+
history_message = history.map {|h| "#{h[:time]} #{h[:body]}" }.join($/)
|
8
|
+
message.reply(history_message)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Ruboty
|
2
|
+
module Stats
|
3
|
+
module Actions
|
4
|
+
class Stats < Ruboty::Actions::Base
|
5
|
+
def call
|
6
|
+
stats = ::Ruboty::Stats.stats(message.robot).map {|action_name, message_bodies|
|
7
|
+
{action_name: action_name, count: message_bodies.size}
|
8
|
+
}.sort_by(&:count)
|
9
|
+
|
10
|
+
name_column_size = stats.map {|s| s[:action_name].to_s.size }.max
|
11
|
+
count_column_size = stats.map {|s| s[:count].to_s.size }.max
|
12
|
+
|
13
|
+
stats_message = stats.map {|s|
|
14
|
+
"%-#{name_column_size}s | %#{count_column_size}s"
|
15
|
+
"%-#{name_column_size}s | %#{count_column_size}s" % [s[:action_name], s[:count]]
|
16
|
+
}.join($/)
|
17
|
+
|
18
|
+
message.reply(stats_message)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/ruboty/stats.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "ruboty"
|
2
|
+
require "ruboty/stats/version"
|
3
|
+
require "ruboty/handlers/stats"
|
4
|
+
|
5
|
+
module Ruboty
|
6
|
+
module Stats
|
7
|
+
NAMESPACE = 'stats'
|
8
|
+
|
9
|
+
module Recorder
|
10
|
+
def call(handler, message)
|
11
|
+
if perform?(handler, message)
|
12
|
+
action_name = "#{handler.class.name}##{name}"
|
13
|
+
Ruboty::Stats.stats(handler.robot)[action_name] ||= []
|
14
|
+
Ruboty::Stats.stats(handler.robot)[action_name] << {body: message.body, time: Time.now}
|
15
|
+
end
|
16
|
+
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
def perform?(handler, message)
|
21
|
+
message.match pattern_with(handler.robot.name)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module_function
|
26
|
+
|
27
|
+
def stats(robot)
|
28
|
+
robot.brain.data[NAMESPACE] ||= {}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
::Ruboty::Action.prepend(Ruboty::Stats::Recorder)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ruboty/stats/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ruboty-stats"
|
8
|
+
spec.version = Ruboty::Stats::VERSION
|
9
|
+
spec.authors = ["block_given?"]
|
10
|
+
spec.email = ["block_given@outlook.com"]
|
11
|
+
spec.summary = %q{ruboty plugin to record action stats.}
|
12
|
+
spec.homepage = "https://github.com/blockgiven/ruboty-stats"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_runtime_dependency "ruboty"
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "ruboty-hi"
|
24
|
+
end
|
data/screenshot.png
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruboty-stats
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- block_given?
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruboty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ruboty-hi
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- block_given@outlook.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/ruboty/handlers/stats.rb
|
82
|
+
- lib/ruboty/stats.rb
|
83
|
+
- lib/ruboty/stats/actions/clear.rb
|
84
|
+
- lib/ruboty/stats/actions/history.rb
|
85
|
+
- lib/ruboty/stats/actions/stats.rb
|
86
|
+
- lib/ruboty/stats/version.rb
|
87
|
+
- ruboty-stats.gemspec
|
88
|
+
- screenshot.png
|
89
|
+
homepage: https://github.com/blockgiven/ruboty-stats
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.2.2
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: ruboty plugin to record action stats.
|
113
|
+
test_files: []
|
114
|
+
has_rdoc:
|