shiba-stats 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: da2995d29b0ce3cf91159c0345f5d998d2ac02f24a108d366b2c79ec5790fdd8
4
+ data.tar.gz: 419932bc7fce61beed50ab7cd52a0643fc569b3024ac2ec9806034c0afe442e1
5
+ SHA512:
6
+ metadata.gz: 9ab7afad0351849c550d9e8d066ab921ec63a71f452934f954a61431faf0b05b9d4d1e713575319151dc6eebcc32509aaf24468115dd7801528ed8da7951296e
7
+ data.tar.gz: 1ecff8d5b82a64eb2367ec0e9b59843fd56a17ce7ac54f4f0439d7c2178122881988538c1c28f37451d4e7d760d06960e65082bff201502cb3a49b8b02adf1d4
@@ -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: []