litestack 0.4.1 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.standard.yml +3 -0
  3. data/BENCHMARKS.md +23 -7
  4. data/CHANGELOG.md +35 -0
  5. data/Gemfile +1 -7
  6. data/README.md +124 -6
  7. data/ROADMAP.md +45 -0
  8. data/Rakefile +3 -1
  9. data/WHYLITESTACK.md +1 -1
  10. data/assets/litecache_metrics.png +0 -0
  11. data/assets/litedb_metrics.png +0 -0
  12. data/assets/litemetric_logo_teal.png +0 -0
  13. data/assets/litesearch_logo_teal.png +0 -0
  14. data/bench/bench.rb +17 -10
  15. data/bench/bench_cache_rails.rb +45 -14
  16. data/bench/bench_cache_raw.rb +44 -28
  17. data/bench/bench_jobs_rails.rb +18 -12
  18. data/bench/bench_jobs_raw.rb +17 -10
  19. data/bench/bench_queue.rb +4 -6
  20. data/bench/rails_job.rb +5 -7
  21. data/bench/skjob.rb +4 -4
  22. data/bench/uljob.rb +6 -6
  23. data/bin/liteboard +2 -1
  24. data/lib/action_cable/subscription_adapter/litecable.rb +5 -8
  25. data/lib/active_job/queue_adapters/litejob_adapter.rb +6 -8
  26. data/lib/active_record/connection_adapters/litedb_adapter.rb +72 -84
  27. data/lib/active_support/cache/litecache.rb +61 -41
  28. data/lib/generators/litestack/install/install_generator.rb +3 -3
  29. data/lib/generators/litestack/install/templates/cable.yml +0 -3
  30. data/lib/generators/litestack/install/templates/database.yml +7 -1
  31. data/lib/litestack/liteboard/liteboard.rb +269 -149
  32. data/lib/litestack/litecable.rb +41 -37
  33. data/lib/litestack/litecable.sql.yml +22 -11
  34. data/lib/litestack/litecache.rb +118 -93
  35. data/lib/litestack/litecache.sql.yml +83 -22
  36. data/lib/litestack/litecache.yml +1 -1
  37. data/lib/litestack/litedb.rb +35 -40
  38. data/lib/litestack/litejob.rb +30 -29
  39. data/lib/litestack/litejobqueue.rb +63 -65
  40. data/lib/litestack/litemetric.rb +80 -92
  41. data/lib/litestack/litemetric.sql.yml +244 -234
  42. data/lib/litestack/litemetric_collector.sql.yml +38 -41
  43. data/lib/litestack/litequeue.rb +39 -41
  44. data/lib/litestack/litequeue.sql.yml +39 -31
  45. data/lib/litestack/litescheduler.rb +24 -18
  46. data/lib/litestack/litesearch/index.rb +93 -63
  47. data/lib/litestack/litesearch/model.rb +66 -65
  48. data/lib/litestack/litesearch/schema.rb +53 -56
  49. data/lib/litestack/litesearch/schema_adapters/backed_adapter.rb +46 -50
  50. data/lib/litestack/litesearch/schema_adapters/basic_adapter.rb +44 -35
  51. data/lib/litestack/litesearch/schema_adapters/contentless_adapter.rb +3 -6
  52. data/lib/litestack/litesearch/schema_adapters/standalone_adapter.rb +7 -9
  53. data/lib/litestack/litesearch/schema_adapters.rb +4 -9
  54. data/lib/litestack/litesearch.rb +6 -9
  55. data/lib/litestack/litesupport.rb +78 -87
  56. data/lib/litestack/railtie.rb +1 -1
  57. data/lib/litestack/version.rb +2 -2
  58. data/lib/litestack.rb +6 -4
  59. data/lib/railties/rails/commands/dbconsole.rb +16 -20
  60. data/lib/sequel/adapters/litedb.rb +16 -21
  61. data/lib/sequel/adapters/shared/litedb.rb +168 -168
  62. data/scripts/build_metrics.rb +91 -0
  63. data/scripts/test_cable.rb +30 -0
  64. data/scripts/test_job_retry.rb +33 -0
  65. data/scripts/test_metrics.rb +60 -0
  66. data/template.rb +2 -2
  67. metadata +115 -7
@@ -1,18 +1,17 @@
1
1
  # frozen_string_literal: true
2
- require 'hanami/router'
3
- require 'tilt'
4
- require 'erubi'
5
2
 
6
- # require relative so we pick the gem version that corresponds to the liteboard binary
7
- require_relative '../../litestack/litemetric'
3
+ require "hanami/router"
4
+ require "tilt"
5
+ require "erubi"
8
6
 
9
- class Liteboard
7
+ # require relative so we pick the gem version that corresponds to the liteboard binary
8
+ require_relative "../../litestack/litemetric"
10
9
 
11
- @@resolutions = {'minute' => [300, 12], 'hour' => [3600, 24], 'day' => [3600*24, 7], 'week' => [3600*24*7, 53], 'year' => [3600*24*365, 100] }
12
- @@res_mapping = {'hour' => 'minute', 'day' => 'hour', 'week' => 'day', 'year' => 'week'}
10
+ class Liteboard
11
+ @@resolutions = {"minute" => [300, 12], "hour" => [3600, 24], "day" => [3600 * 24, 7], "week" => [3600 * 24 * 7, 53], "year" => [3600 * 24 * 365, 100]}
12
+ @@res_mapping = {"hour" => "minute", "day" => "hour", "week" => "day", "year" => "week"}
13
13
  @@templates = {}
14
14
  @@app = Hanami::Router.new do
15
-
16
15
  get "/", to: ->(env) do
17
16
  Liteboard.new(env).call(:index)
18
17
  end
@@ -24,7 +23,7 @@ class Liteboard
24
23
  get "/topics/Litecache", to: ->(env) do
25
24
  Liteboard.new(env).call(:litecache)
26
25
  end
27
-
26
+
28
27
  get "/topics/Litedb", to: ->(env) do
29
28
  Liteboard.new(env).call(:litedb)
30
29
  end
@@ -32,9 +31,7 @@ class Liteboard
32
31
  get "/topics/Litecable", to: ->(env) do
33
32
  Liteboard.new(env).call(:litecable)
34
33
  end
35
-
36
- end
37
-
34
+ end
38
35
 
39
36
  def initialize(env)
40
37
  @env = env
@@ -43,8 +40,8 @@ class Liteboard
43
40
  @lm = Litemetric.instance
44
41
  end
45
42
 
46
- def params(key)
47
- URI.decode_uri_component("#{@params[key]}")
43
+ def params(key)
44
+ URI.decode_uri_component(@params[key].to_s)
48
45
  end
49
46
 
50
47
  def call(method)
@@ -52,24 +49,24 @@ class Liteboard
52
49
  res = send(method)
53
50
  after(res)
54
51
  end
55
-
56
- def after(body=nil)
57
- [200, {'Cache-Control' => 'no-cache'}, [body]]
52
+
53
+ def after(body = nil)
54
+ [200, {"Cache-Control" => "no-cache"}, [body]]
58
55
  end
59
56
 
60
57
  def before
61
- @res = params(:res) || 'day'
58
+ @res = params(:res) || "day"
62
59
  @resolution = @@res_mapping[@res]
63
- if not @resolution
64
- @res = 'day'
65
- @resolution = @@res_mapping[@res]
60
+ if !@resolution
61
+ @res = "day"
62
+ @resolution = @@res_mapping[@res]
66
63
  end
67
64
  @step = @@resolutions[@resolution][0]
68
65
  @count = @@resolutions[@resolution][1]
69
- @order = params(:order)
70
- @order = nil if @order == ''
71
- @dir = params(:dir)
72
- @dir = 'desc' if @dir.nil? || @dir == ''
66
+ @order = params(:order)
67
+ @order = nil if @order == ""
68
+ @dir = params(:dir)
69
+ @dir = "desc" if @dir.nil? || @dir == ""
73
70
  @dir = @dir.downcase
74
71
  @idir = if @dir == "asc"
75
72
  "desc"
@@ -77,149 +74,277 @@ class Liteboard
77
74
  "asc"
78
75
  end
79
76
  @search = params(:search)
80
- @search = nil if @search == ''
77
+ @search = nil if @search == ""
81
78
  @topics = @lm.topic_summaries(@resolution, @step * @count, @order, @dir, @search)
82
79
  end
83
-
80
+
84
81
  def index
85
- @order = 'topic' unless @order
82
+ @order ||= "topic"
86
83
  @topics.each do |topic|
87
- data_points = @lm.topic_data_points(@step, @count, @resolution, topic[0])
88
- topic << data_points.collect{|r| [r[0],r[2] || 0]}
89
- end
84
+ data_points = @lm.topic_data_points(@step, @count, @resolution, topic[0])
85
+ topic << data_points.collect { |r| [r[0], r[2] || 0] }
86
+ end
90
87
  render :index
91
88
  end
92
-
89
+
93
90
  def litecache
94
- @order = 'rcount' unless @order
95
- @topic = 'Litecache'
91
+ @order ||= "rcount"
92
+ @topic = "Litecache"
96
93
  @events = @lm.events_summaries(@topic, @resolution, @order, @dir, @search, @step * @count)
97
94
  @events.each do |event|
98
- data_points = @lm.event_data_points(@step, @count, @resolution, @topic, event['name'])
99
- event['counts'] = data_points.collect{|r| [r['rtime'],r['rcount']]}
100
- event['values'] = data_points.collect{|r| [r['rtime'],r['ravg']]}
95
+ data_points = @lm.event_data_points(@step, @count, @resolution, @topic, event["name"])
96
+ event["counts"] = data_points.collect { |r| [r["rtime"], r["rcount"]] }
97
+ event["values"] = data_points.collect { |r| [r["rtime"], r["ravg"]] }
101
98
  end
102
99
  @snapshot = read_snapshot(@topic)
103
- @size = @snapshot[0][:summary][:size] rescue 0
104
- @max_size = @snapshot[0][:summary][:max_size] rescue 0
105
- @full = (@size / @max_size)*100 rescue 0
106
- @entries = @snapshot[0][:summary][:entries] rescue 0
107
- @gets = @events.find{|t| t['name'] == 'get'}
108
- @sets = @events.find{|t| t['name'] == 'set'}
109
- @reads = @gets['rcount'] rescue 0
110
- @writes = @sets['rcount'] rescue 0
111
- @hitrate = @gets['ravg'] rescue 0
100
+ @size = begin
101
+ @snapshot[0][:summary][:size]
102
+ rescue
103
+ 0
104
+ end
105
+ @max_size = begin
106
+ @snapshot[0][:summary][:max_size]
107
+ rescue
108
+ 0
109
+ end
110
+ @full = begin
111
+ (@size / @max_size) * 100
112
+ rescue
113
+ 0
114
+ end
115
+ @entries = begin
116
+ @snapshot[0][:summary][:entries]
117
+ rescue
118
+ 0
119
+ end
120
+ @gets = @events.find { |t| t["name"] == "get" }
121
+ @sets = @events.find { |t| t["name"] == "set" }
122
+ @reads = begin
123
+ @gets["rcount"]
124
+ rescue
125
+ 0
126
+ end
127
+ @writes = begin
128
+ @sets["rcount"]
129
+ rescue
130
+ 0
131
+ end
132
+ @hitrate = begin
133
+ @gets["ravg"]
134
+ rescue
135
+ 0
136
+ end
112
137
  @hits = @reads * @hitrate
113
138
  @misses = @reads - @hits
114
- @reads_vs_writes = @gets['counts'].collect.with_index{|obj, i| obj.clone << @sets['counts'][i][1] } rescue []
115
- @hits_vs_misses = @gets['values'].collect.with_index{|obj, i| [obj[0], obj[1].to_f * @gets['counts'][i][1].to_f, (1 - obj[1].to_f) * @gets['counts'][i][1].to_f] } rescue []
116
- @top_reads = @lm.keys_summaries(@topic, 'get', @resolution, @order, @dir, nil, @step * @count).first(8)
117
- @top_writes = @lm.keys_summaries(@topic, 'set', @resolution, @order, @dir, nil, @step * @count).first(8)
139
+ @reads_vs_writes = begin
140
+ @gets["counts"].collect.with_index { |obj, i| obj.clone << @sets["counts"][i][1] }
141
+ rescue
142
+ []
143
+ end
144
+ @hits_vs_misses = begin
145
+ @gets["values"].collect.with_index { |obj, i| [obj[0], obj[1].to_f * @gets["counts"][i][1].to_f, (1 - obj[1].to_f) * @gets["counts"][i][1].to_f] }
146
+ rescue
147
+ []
148
+ end
149
+ @top_reads = @lm.keys_summaries(@topic, "get", @resolution, @order, @dir, nil, @step * @count).first(8)
150
+ @top_writes = @lm.keys_summaries(@topic, "set", @resolution, @order, @dir, nil, @step * @count).first(8)
118
151
  render :litecache
119
152
  end
120
-
153
+
121
154
  def litedb
122
- @order = 'rcount' unless @order
123
- @topic = 'Litedb'
155
+ @order ||= "rcount"
156
+ @topic = "Litedb"
124
157
  @events = @lm.events_summaries(@topic, @resolution, @order, @dir, @search, @step * @count)
125
158
  @events.each do |event|
126
- data_points = @lm.event_data_points(@step, @count, @resolution, @topic, event['name'])
127
- event['counts'] = data_points.collect{|r| [r['rtime'],r['rcount'] || 0]}
128
- event['values'] = data_points.collect{|r| [r['rtime'],r['rtotal'] || 0]}
159
+ data_points = @lm.event_data_points(@step, @count, @resolution, @topic, event["name"])
160
+ event["counts"] = data_points.collect { |r| [r["rtime"], r["rcount"] || 0] }
161
+ event["values"] = data_points.collect { |r| [r["rtime"], r["rtotal"] || 0] }
129
162
  end
130
163
  @snapshot = read_snapshot(@topic)
131
- @size = @snapshot[0][:summary][:size] rescue 0
132
- @tables = @snapshot[0][:summary][:tables] rescue 0
133
- @indexes = @snapshot[0][:summary][:indexes] rescue 0
134
- @gets = @events.find{|t| t['name'] == 'Read'}
135
- @sets = @events.find{|t| t['name'] == 'Write'}
136
- @reads = @gets['rcount'] rescue 0
137
- @writes = @sets['rcount'] rescue 0
138
- @time = @gets['ravg'] rescue 0
139
- @reads_vs_writes = @gets['counts'].collect.with_index{|obj, i| obj.clone << @sets['counts'][i][1] } rescue []
140
- @reads_vs_writes_times = @gets['values'].collect.with_index{|obj, i| [obj[0], obj[1], @sets['values'][i][1].to_f] } rescue []
141
- @read_times = @gets['rtotal'] rescue 0
142
- @write_times = @sets['rtotal'] rescue 0
143
- @slowest = @lm.keys_summaries(@topic, 'Read', @resolution, 'ravg', 'desc', nil, @step * @count).first(8)
144
- @slowest += @lm.keys_summaries(@topic, 'Write', @resolution, 'ravg', 'desc', nil, @step * @count).first(8)
145
- @slowest = @slowest.sort{|a, b| a['ravg'] <=> b['ravg']}.reverse.first(8)
146
- @popular = @lm.keys_summaries(@topic, 'Read', @resolution, 'rtotal', 'desc', nil, @step * @count).first(8)
147
- @popular += @lm.keys_summaries(@topic, 'Write', @resolution, 'rtotal', 'desc', nil, @step * @count).first(8)
148
- @popular = @popular.sort{|a, b| a['rtotal'] <=> b['rtotal']}.reverse.first(8)
164
+ @size = begin
165
+ @snapshot[0][:summary][:size]
166
+ rescue
167
+ 0
168
+ end
169
+ @tables = begin
170
+ @snapshot[0][:summary][:tables]
171
+ rescue
172
+ 0
173
+ end
174
+ @indexes = begin
175
+ @snapshot[0][:summary][:indexes]
176
+ rescue
177
+ 0
178
+ end
179
+ @gets = @events.find { |t| t["name"] == "Read" }
180
+ @sets = @events.find { |t| t["name"] == "Write" }
181
+ @reads = begin
182
+ @gets["rcount"]
183
+ rescue
184
+ 0
185
+ end
186
+ @writes = begin
187
+ @sets["rcount"]
188
+ rescue
189
+ 0
190
+ end
191
+ @time = begin
192
+ @gets["ravg"]
193
+ rescue
194
+ 0
195
+ end
196
+ @reads_vs_writes = begin
197
+ @gets["counts"].collect.with_index { |obj, i| obj.clone << @sets["counts"][i][1] }
198
+ rescue
199
+ []
200
+ end
201
+ @reads_vs_writes_times = begin
202
+ @gets["values"].collect.with_index { |obj, i| [obj[0], obj[1], @sets["values"][i][1].to_f] }
203
+ rescue
204
+ []
205
+ end
206
+ @read_times = begin
207
+ @gets["rtotal"]
208
+ rescue
209
+ 0
210
+ end
211
+ @write_times = begin
212
+ @sets["rtotal"]
213
+ rescue
214
+ 0
215
+ end
216
+ @slowest = @lm.keys_summaries(@topic, "Read", @resolution, "ravg", "desc", nil, @step * @count).first(8)
217
+ @slowest += @lm.keys_summaries(@topic, "Write", @resolution, "ravg", "desc", nil, @step * @count).first(8)
218
+ @slowest = @slowest.sort_by { |a| a["ravg"] }.last(8).reverse
219
+ @popular = @lm.keys_summaries(@topic, "Read", @resolution, "rtotal", "desc", nil, @step * @count).first(8)
220
+ @popular += @lm.keys_summaries(@topic, "Write", @resolution, "rtotal", "desc", nil, @step * @count).first(8)
221
+ @popular = @popular.sort_by { |a| a["rtotal"] }.last(8).reverse
149
222
  render :litedb
150
223
  end
151
-
224
+
152
225
  def litejob
153
- @order = 'rcount' unless @order
154
- @topic = 'Litejob'
226
+ @order ||= "rcount"
227
+ @topic = "Litejob"
155
228
  @events = @lm.events_summaries(@topic, @resolution, @order, @dir, @search, @step * @count)
156
229
  @events.each do |event|
157
- data_points = @lm.event_data_points(@step, @count, @resolution, @topic, event['name'])
158
- event['counts'] = data_points.collect{|r| [r['rtime'],r['rcount'] || 0]}
159
- event['values'] = data_points.collect{|r| [r['rtime'],r['rtotal'] || 0]}
230
+ data_points = @lm.event_data_points(@step, @count, @resolution, @topic, event["name"])
231
+ event["counts"] = data_points.collect { |r| [r["rtime"], r["rcount"] || 0] }
232
+ event["values"] = data_points.collect { |r| [r["rtime"], r["rtotal"] || 0] }
160
233
  end
161
234
  @snapshot = read_snapshot(@topic)
162
- @size = @snapshot[0][:summary][:size] rescue 0
163
- @jobs = @snapshot[0][:summary][:jobs] rescue 0
164
- @queues = @snapshot[0][:queues] rescue {}
165
- @processed_jobs = @events.find{|e|e['name'] == 'perform'}
166
- @processed_count = @processed_jobs['rcount'] rescue 0
167
- @processing_time = @processed_jobs['rtotal'] rescue 0
168
- keys_summaries = @lm.keys_summaries(@topic, 'perform', @resolution, 'rcount', 'desc', nil, @step * @count)
169
- @processed_count_by_queue = keys_summaries.collect{|r|[r['key'], r['rcount']]}
170
- @processing_time_by_queue = keys_summaries.collect{|r|[r['key'], r['rtotal']]} #.sort{|r1, r2| r1['rtotal'] > r2['rtotal'] }
171
- @processed_count_over_time = @events.find{|e| e['name'] == 'perform'}['counts'] rescue []
172
- @processing_time_over_time = @events.find{|e| e['name'] == 'perform'}['values'] rescue []
173
- @processed_count_over_time_by_queues = []
235
+ @size = begin
236
+ @snapshot[0][:summary][:size]
237
+ rescue
238
+ 0
239
+ end
240
+ @jobs = begin
241
+ @snapshot[0][:summary][:jobs]
242
+ rescue
243
+ 0
244
+ end
245
+ @queues = begin
246
+ @snapshot[0][:queues]
247
+ rescue
248
+ {}
249
+ end
250
+ @processed_jobs = @events.find { |e| e["name"] == "perform" }
251
+ @processed_count = begin
252
+ @processed_jobs["rcount"]
253
+ rescue
254
+ 0
255
+ end
256
+ @processing_time = begin
257
+ @processed_jobs["rtotal"]
258
+ rescue
259
+ 0
260
+ end
261
+ keys_summaries = @lm.keys_summaries(@topic, "perform", @resolution, "rcount", "desc", nil, @step * @count)
262
+ @processed_count_by_queue = keys_summaries.collect { |r| [r["key"], r["rcount"]] }
263
+ @processing_time_by_queue = keys_summaries.collect { |r| [r["key"], r["rtotal"]] } # .sort{|r1, r2| r1['rtotal'] > r2['rtotal'] }
264
+ @processed_count_over_time = begin
265
+ @events.find { |e| e["name"] == "perform" }["counts"]
266
+ rescue
267
+ []
268
+ end
269
+ @processing_time_over_time = begin
270
+ @events.find { |e| e["name"] == "perform" }["values"]
271
+ rescue
272
+ []
273
+ end
274
+ @processed_count_over_time_by_queues = []
174
275
  @processing_time_over_time_by_queues = []
175
- keys = ['Time']
176
- keys_summaries.each_with_index do |summary,i|
177
- key = summary['key']
276
+ keys = ["Time"]
277
+ keys_summaries.each_with_index do |summary, i|
278
+ key = summary["key"]
178
279
  keys << key
179
- data_points = @lm.key_data_points(@step, @count, @resolution, @topic, 'perform', key)
280
+ data_points = @lm.key_data_points(@step, @count, @resolution, @topic, "perform", key)
180
281
  if i == 0
181
- data_points.each do |dp|
182
- @processed_count_over_time_by_queues << [dp['rtime']]
183
- @processing_time_over_time_by_queues << [dp['rtime']]
282
+ data_points.each do |dp|
283
+ @processed_count_over_time_by_queues << [dp["rtime"]]
284
+ @processing_time_over_time_by_queues << [dp["rtime"]]
184
285
  end
185
286
  end
186
287
  data_points.each_with_index do |dp, j|
187
- @processed_count_over_time_by_queues[j] << (dp['rcount'] || 0)
188
- @processing_time_over_time_by_queues[j] << (dp['rtotal'] || 0)
288
+ @processed_count_over_time_by_queues[j] << (dp["rcount"] || 0)
289
+ @processing_time_over_time_by_queues[j] << (dp["rtotal"] || 0)
189
290
  end
190
291
  end
191
292
  @processed_count_over_time_by_queues.unshift(keys)
192
- @processing_time_over_time_by_queues.unshift(keys)
293
+ @processing_time_over_time_by_queues.unshift(keys)
193
294
  render :litejob
194
295
  end
195
-
296
+
196
297
  def litecable
197
- @order = 'rcount' unless @order
198
- @topic = 'Litecable'
298
+ @order ||= "rcount"
299
+ @topic = "Litecable"
199
300
  @events = @lm.events_summaries(@topic, @resolution, @order, @dir, @search, @step * @count)
200
301
  @events.each do |event|
201
- data_points = @lm.event_data_points(@step, @count, @resolution, @topic, event['name'])
202
- event['counts'] = data_points.collect{|r| [r['rtime'],r['rcount'] || 0]}
302
+ data_points = @lm.event_data_points(@step, @count, @resolution, @topic, event["name"])
303
+ event["counts"] = data_points.collect { |r| [r["rtime"], r["rcount"] || 0] }
304
+ end
305
+
306
+ @subscription_count = begin
307
+ @events.find { |t| t["name"] == "subscribe" }["rcount"]
308
+ rescue
309
+ 0
310
+ end
311
+ @broadcast_count = begin
312
+ @events.find { |t| t["name"] == "broadcast" }["rcount"]
313
+ rescue
314
+ 0
315
+ end
316
+ @message_count = begin
317
+ @events.find { |t| t["name"] == "message" }["rcount"]
318
+ rescue
319
+ 0
203
320
  end
204
321
 
205
- @subscription_count = @events.find{|t| t['name'] == 'subscribe'}['rcount'] rescue 0
206
- @broadcast_count = @events.find{|t| t['name'] == 'broadcast'}['rcount'] rescue 0
207
- @message_count = @events.find{|t| t['name'] == 'message'}['rcount'] rescue 0
322
+ @subscriptions_over_time = begin
323
+ @events.find { |t| t["name"] == "subscribe" }["counts"]
324
+ rescue
325
+ []
326
+ end
327
+ @broadcasts_over_time = begin
328
+ @events.find { |t| t["name"] == "broadcast" }["counts"]
329
+ rescue
330
+ []
331
+ end
332
+ @messages_over_time = begin
333
+ @events.find { |t| t["name"] == "message" }["counts"]
334
+ rescue
335
+ []
336
+ end
337
+ @messages_over_time = @messages_over_time.collect.with_index { |msg, i| [msg[0], @broadcasts_over_time[i][1], msg[1]] }
208
338
 
209
- @subscriptions_over_time = @events.find{|t| t['name'] == 'subscribe'}['counts'] rescue []
210
- @broadcasts_over_time = @events.find{|t| t['name'] == 'broadcast'}['counts'] rescue []
211
- @messages_over_time = @events.find{|t| t['name'] == 'message'}['counts'] rescue []
212
- @messages_over_time = @messages_over_time.collect.with_index{|msg, i| [msg[0], @broadcasts_over_time[i][1], msg[1]]}
213
-
214
- @top_subscribed_channels = @lm.keys_summaries(@topic, 'subscribe', @resolution, @order, @dir, @search, @step * @count).first(8)
215
- @top_messaged_channels = @lm.keys_summaries(@topic, 'message', @resolution, @order, @dir, @search, @step * @count).first(8)
339
+ @top_subscribed_channels = @lm.keys_summaries(@topic, "subscribe", @resolution, @order, @dir, @search, @step * @count).first(8)
340
+ @top_messaged_channels = @lm.keys_summaries(@topic, "message", @resolution, @order, @dir, @search, @step * @count).first(8)
216
341
  render :litecable
217
342
  end
218
-
343
+
219
344
  def index_url
220
345
  "/?res=#{@res}&order=#{@order}&dir=#{@dir}&search=#{@search}"
221
346
  end
222
-
347
+
223
348
  def topic_url(topic)
224
349
  "/topics/#{encode(topic)}?res=#{@res}&order=#{@order}&dir=#{@dir}&search=#{@search}"
225
350
  end
@@ -227,58 +352,58 @@ class Liteboard
227
352
  def index_sort_url(field)
228
353
  "/?#{compose_query(field)}"
229
354
  end
230
-
355
+
231
356
  def topic_sort_url(field)
232
357
  "/topics/#{encode(@topic)}?#{compose_query(field)}"
233
358
  end
234
-
359
+
235
360
  def event_sort_url(field)
236
361
  "/topics/#{encode(@topic)}/events/#{encode(@event)}?#{compose_query(field)}"
237
362
  end
238
-
363
+
239
364
  def compose_query(field)
240
365
  field.downcase!
241
- "res=#{@res}&order=#{field}&dir=#{@order == field ? @idir : @dir}&search=#{@search}"
366
+ "res=#{@res}&order=#{field}&dir=#{(@order == field) ? @idir : @dir}&search=#{@search}"
242
367
  end
243
-
368
+
244
369
  def sorted?(field)
245
370
  @order == field
246
371
  end
247
-
372
+
248
373
  def dir(field)
249
374
  if sorted?(field)
250
- if @dir == 'asc'
251
- return "<span class='material-icons'>arrow_drop_up</span>"
375
+ if @dir == "asc"
376
+ return "<span class='material-icons'>arrow_drop_up</span>"
252
377
  else
253
378
  return "<span class='material-icons'>arrow_drop_down</span>"
254
379
  end
255
380
  end
256
- '&nbsp;&nbsp;'
381
+ "&nbsp;&nbsp;"
257
382
  end
258
-
383
+
259
384
  def encode(text)
260
385
  URI.encode_uri_component(text)
261
386
  end
262
-
387
+
263
388
  def round(float)
264
389
  return 0 unless float.is_a? Numeric
265
- ((float * 100).round).to_f / 100
390
+ (float * 100).round.to_f / 100
266
391
  end
267
-
392
+
268
393
  def format(float)
269
394
  string = float.to_s
270
- whole, decimal = string.split('.')
271
- whole = whole.split('').reverse.each_slice(3).map(&:join).join(',').reverse
272
- whole = [whole, decimal].join('.') if decimal
395
+ whole, decimal = string.split(".")
396
+ whole = whole.chars.reverse.each_slice(3).map(&:join).join(",").reverse
397
+ whole = [whole, decimal].join(".") if decimal
273
398
  whole
274
399
  end
275
-
400
+
276
401
  def self.app
277
- @@app
402
+ @@app
278
403
  end
279
404
 
280
405
  private
281
-
406
+
282
407
  def read_snapshot(topic)
283
408
  snapshot = @lm.snapshot(topic)
284
409
  if snapshot.empty?
@@ -286,20 +411,15 @@ class Liteboard
286
411
  else
287
412
  snapshot[0] = Oj.load(snapshot[0]) unless snapshot[0].nil?
288
413
  end
289
- snapshot
414
+ snapshot
290
415
  end
291
-
416
+
292
417
  def render(tpl_name)
293
418
  layout = Tilt.new("#{__dir__}/views/layout.erb")
294
- tpl_path = "#{__dir__}/views/#{tpl_name.to_s}.erb"
419
+ tpl_path = "#{__dir__}/views/#{tpl_name}.erb"
295
420
  tpl = Tilt.new(tpl_path)
296
- res = layout.render(self){tpl.render(self)}
421
+ layout.render(self) { tpl.render(self) }
297
422
  end
298
-
299
-
300
423
  end
301
424
 
302
-
303
-
304
-
305
- #Rack::Server.start({app: Litebaord.app, daemonize: false})
425
+ # Rack::Server.start({app: Litebaord.app, daemonize: false})