shiba_stats 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/shiba_stats.rb +16 -0
- data/lib/shiba_stats_helper.rb +50 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0b7f2e2f37b798499dc34254960a3b6b342f0d487cb41f06b2227b4207a62b2b
|
4
|
+
data.tar.gz: 4cc01b106f20a684f31b6e9e1d0bb9f1078ea61f6699f3ad2934263eff60574f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 25aadeaa7a5f0c231941f4a9a2df4e3dfd0cf2698752922d74f445ca38d72c4489968d37a35ae4251c760ba9aee0a307a8d3352a974fe3a2fad55bbdc1625051
|
7
|
+
data.tar.gz: 06c4185538770671f77517fbd36977e6ed4226e6fd3c224abd9de4622026133302f69ba0d86088681eeff3505b16796ed7d4ab34c8834dd0e34d01c9d065ed9e
|
data/lib/shiba_stats.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
class ShibaStats
|
2
|
+
ActionView::Base.send :include, ShibaStatsHelper
|
3
|
+
|
4
|
+
|
5
|
+
def self.add(key, amount = 1)
|
6
|
+
time_series(key).add(amount)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.count(key, amount = 1)
|
10
|
+
time_series(key).incrby(amount)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.time_series(key)
|
14
|
+
Redis::TimeSeries.new(key)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module ShibaStatsHelper
|
2
|
+
def shiba_line(keys, chart_options = {}, options = {})
|
3
|
+
line_chart prepare_data(keys, options), **chart_options
|
4
|
+
end
|
5
|
+
|
6
|
+
def shiba_area(keys, chart_options = {}, options = {})
|
7
|
+
chart_options[:stacked] ||= true
|
8
|
+
area_chart prepare_data(keys, options), **chart_options
|
9
|
+
end
|
10
|
+
|
11
|
+
def shiba_bar(keys, chart_options = {}, options = {})
|
12
|
+
bar_chart prepare_data(keys, options), **chart_options
|
13
|
+
end
|
14
|
+
|
15
|
+
def shiba_pie(keys, chart_options = {}, options = {})
|
16
|
+
pie_chart(prepare_pie_data(keys, options), **chart_options)
|
17
|
+
end
|
18
|
+
|
19
|
+
def prepare_data(keys, options)
|
20
|
+
keys = [keys] unless keys.is_a?(Array)
|
21
|
+
data = []
|
22
|
+
options[:start_time] ||= Time.zone.now - 24.hours
|
23
|
+
options[:end_time] ||= Time.zone.now
|
24
|
+
|
25
|
+
keys.each do |key|
|
26
|
+
key_data = { name: key, data: {}}
|
27
|
+
time_series = ShibaStats.time_series(key).range(options[:start_time]..options[:end_time], aggregation: [:count, 1.seconds])
|
28
|
+
time_series.each do |point|
|
29
|
+
key_data[:data][point.time] = point.value
|
30
|
+
end
|
31
|
+
|
32
|
+
data << key_data
|
33
|
+
end
|
34
|
+
|
35
|
+
return data
|
36
|
+
end
|
37
|
+
|
38
|
+
def prepare_pie_data(keys, options)
|
39
|
+
keys = [keys] unless keys.is_a?(Array)
|
40
|
+
data = {}
|
41
|
+
|
42
|
+
keys.each do |key|
|
43
|
+
time_series = ShibaStats.time_series(key).range(Time.zone.now-24.hours..Time.zone.now)
|
44
|
+
data[key] = time_series.count
|
45
|
+
end
|
46
|
+
|
47
|
+
return data
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shiba_stats
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Will DeWind
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-08-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: chartkick
|
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: redis-time-series
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: A small gem for measuring things
|
42
|
+
email: will.dewind@gmail.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- lib/shiba_stats.rb
|
48
|
+
- lib/shiba_stats_helper.rb
|
49
|
+
homepage: https://rubygems.org/gems/shiba_stats
|
50
|
+
licenses:
|
51
|
+
- MIT
|
52
|
+
metadata: {}
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubygems_version: 3.3.7
|
69
|
+
signing_key:
|
70
|
+
specification_version: 4
|
71
|
+
summary: ShibaStats
|
72
|
+
test_files: []
|