all_seeing_eye 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -6,6 +6,7 @@ gem 'rbtree'
6
6
  gem 'sinatra'
7
7
  gem 'vegas'
8
8
  gem 'activesupport', '>=2.3.12'
9
+ gem 'i18n'
9
10
 
10
11
  group :development do
11
12
  gem "bundler", "~> 1.0.0"
data/Gemfile.lock CHANGED
@@ -4,6 +4,7 @@ GEM
4
4
  activesupport (3.0.9)
5
5
  chronic (0.6.2)
6
6
  git (1.2.5)
7
+ i18n (0.6.0)
7
8
  jeweler (1.6.4)
8
9
  bundler (~> 1.0)
9
10
  git (>= 1.2.5)
@@ -27,6 +28,7 @@ DEPENDENCIES
27
28
  activesupport (>= 2.3.12)
28
29
  bundler (~> 1.0.0)
29
30
  chronic
31
+ i18n
30
32
  jeweler (~> 1.6.4)
31
33
  rbtree
32
34
  rcov
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.12
1
+ 0.0.13
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{all_seeing_eye}
8
- s.version = "0.0.12"
8
+ s.version = "0.0.13"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Josh Symonds"]
@@ -68,6 +68,7 @@ Gem::Specification.new do |s|
68
68
  s.add_runtime_dependency(%q<sinatra>, [">= 0"])
69
69
  s.add_runtime_dependency(%q<vegas>, [">= 0"])
70
70
  s.add_runtime_dependency(%q<activesupport>, [">= 2.3.12"])
71
+ s.add_runtime_dependency(%q<i18n>, [">= 0"])
71
72
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
72
73
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
73
74
  s.add_development_dependency(%q<rcov>, [">= 0"])
@@ -78,6 +79,7 @@ Gem::Specification.new do |s|
78
79
  s.add_dependency(%q<sinatra>, [">= 0"])
79
80
  s.add_dependency(%q<vegas>, [">= 0"])
80
81
  s.add_dependency(%q<activesupport>, [">= 2.3.12"])
82
+ s.add_dependency(%q<i18n>, [">= 0"])
81
83
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
82
84
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
83
85
  s.add_dependency(%q<rcov>, [">= 0"])
@@ -89,6 +91,7 @@ Gem::Specification.new do |s|
89
91
  s.add_dependency(%q<sinatra>, [">= 0"])
90
92
  s.add_dependency(%q<vegas>, [">= 0"])
91
93
  s.add_dependency(%q<activesupport>, [">= 2.3.12"])
94
+ s.add_dependency(%q<i18n>, [">= 0"])
92
95
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
93
96
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
94
97
  s.add_dependency(%q<rcov>, [">= 0"])
@@ -93,7 +93,7 @@ class AllSeeingEye::Model
93
93
  self.find(AllSeeingEye.redis.zrange("allseeingeye:#{self.model_name}:fields:created_at", -1, -1))
94
94
  end
95
95
 
96
- def self.search(query)
96
+ def self.search(query, options = {})
97
97
  if query =~ /^[\sa-zA-Z0-9,-]*? to [\sa-zA-Z0-9,-]*?$/
98
98
  start = Chronic.parse(query.split(' to ').first, :context => :past)
99
99
  stop = Chronic.parse(query.split(' to ').last, :context => :past)
@@ -133,6 +133,22 @@ class AllSeeingEye::Model
133
133
  tree.to_a
134
134
  end
135
135
 
136
+ def self.created_count(start = '-inf', stop = '+inf')
137
+ start ||= Chronic.parse(start).to_i
138
+ stop ||= Chronic.parse(stop).to_i
139
+
140
+ raw_list = AllSeeingEye.redis.zrangebyscore("allseeingeye:#{self.model_name}:fields:created_at:count", start, stop, :with_scores => true)
141
+ list = []
142
+ raw_list.each_with_index do |value, index|
143
+ if index % 2 == 0
144
+ list << [value]
145
+ else
146
+ list.last[1] = value.to_i
147
+ end
148
+ end
149
+ list
150
+ end
151
+
136
152
  def initialize
137
153
  self.class.field_names.each do |key|
138
154
  self.class.send(:attr_accessor, key.to_sym)
@@ -152,6 +168,7 @@ class AllSeeingEye::Model
152
168
  next if value.nil? || (value.respond_to?(:empty?) && value.empty?)
153
169
  if value.is_a?(Time) || value.is_a?(DateTime) || value.is_a?(Date)
154
170
  AllSeeingEye.redis.zadd("allseeingeye:#{self.class.model_name}:fields:#{field}", value.to_i, id)
171
+ AllSeeingEye.redis.zincrby("allseeingeye:#{self.class.model_name}:fields:#{field}:count", 1, (value.to_i / 60) * 60)
155
172
  else
156
173
  AllSeeingEye.redis.lpush("allseeingeye:#{self.class.model_name}:fields:#{field}:#{value}", id)
157
174
  AllSeeingEye.redis.zincrby("allseeingeye:#{self.class.model_name}:fields:#{field}", 1, value)
@@ -73,8 +73,7 @@ class AllSeeingEye
73
73
  end
74
74
 
75
75
  get '/total' do
76
- @requests = AllSeeingEye::Request.search("one month ago to now")
77
- @counts = AllSeeingEye::Request.conglomerate(@requests)
76
+ @counts = AllSeeingEye::Request.created_count
78
77
  show :total
79
78
  end
80
79
 
data/test/model_test.rb CHANGED
@@ -226,6 +226,7 @@ end
226
226
 
227
227
  context 'many objects' do
228
228
  setup do
229
+ AllSeeingEye.redis.flushall
229
230
  @time = Time.now
230
231
 
231
232
  2000.times do |n|
@@ -237,10 +238,18 @@ context 'many objects' do
237
238
  results = AllSeeingEye::Model.all
238
239
  counts = AllSeeingEye::Model.conglomerate(results)
239
240
 
240
- assert_equal 500, counts.count
241
+ assert_equal 100, counts.count
241
242
  assert_equal 2000, counts.inject(0) {|sum, k| sum + k.last}
242
243
  assert_equal @obj999.created_at.to_i, counts.first.first
243
244
  end
245
+
246
+ test 'get the created count' do
247
+ counts = AllSeeingEye::Model.created_count
248
+
249
+ assert_equal (@obj999.created_at.to_i / 60) * 60, counts.first.first.to_i
250
+ assert_equal (@obj0.created_at.to_i / 60) * 60, counts.last.first.to_i
251
+ assert_equal 2000, counts.inject(0) {|sum, k| sum + k.last}
252
+ end
244
253
  end
245
254
 
246
255
  context 'instance methods' do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: all_seeing_eye
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 12
10
- version: 0.0.12
9
+ - 13
10
+ version: 0.0.13
11
11
  platform: ruby
12
12
  authors:
13
13
  - Josh Symonds
@@ -105,8 +105,22 @@ dependencies:
105
105
  version_requirements: *id006
106
106
  prerelease: false
107
107
  - !ruby/object:Gem::Dependency
108
- type: :development
108
+ type: :runtime
109
109
  requirement: &id007 !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ name: i18n
119
+ version_requirements: *id007
120
+ prerelease: false
121
+ - !ruby/object:Gem::Dependency
122
+ type: :development
123
+ requirement: &id008 !ruby/object:Gem::Requirement
110
124
  none: false
111
125
  requirements:
112
126
  - - ~>
@@ -118,11 +132,11 @@ dependencies:
118
132
  - 0
119
133
  version: 1.0.0
120
134
  name: bundler
121
- version_requirements: *id007
135
+ version_requirements: *id008
122
136
  prerelease: false
123
137
  - !ruby/object:Gem::Dependency
124
138
  type: :development
125
- requirement: &id008 !ruby/object:Gem::Requirement
139
+ requirement: &id009 !ruby/object:Gem::Requirement
126
140
  none: false
127
141
  requirements:
128
142
  - - ~>
@@ -134,11 +148,11 @@ dependencies:
134
148
  - 4
135
149
  version: 1.6.4
136
150
  name: jeweler
137
- version_requirements: *id008
151
+ version_requirements: *id009
138
152
  prerelease: false
139
153
  - !ruby/object:Gem::Dependency
140
154
  type: :development
141
- requirement: &id009 !ruby/object:Gem::Requirement
155
+ requirement: &id010 !ruby/object:Gem::Requirement
142
156
  none: false
143
157
  requirements:
144
158
  - - ">="
@@ -148,7 +162,7 @@ dependencies:
148
162
  - 0
149
163
  version: "0"
150
164
  name: rcov
151
- version_requirements: *id009
165
+ version_requirements: *id010
152
166
  prerelease: false
153
167
  description: AllSeeingEye observes all requests, with parameters that you specify, to Redis. Then it composes them into graphs for you to see.
154
168
  email: veraticus@gmail.com