appstats 0.12.1 → 0.12.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/appstats/date_range.rb +16 -6
- data/lib/appstats/version.rb +1 -1
- data/spec/date_range_spec.rb +22 -2
- data/spec/entry_spec.rb +4 -4
- data/spec/logger_spec.rb +18 -18
- metadata +3 -3
data/Gemfile.lock
CHANGED
data/lib/appstats/date_range.rb
CHANGED
@@ -45,13 +45,23 @@ module Appstats
|
|
45
45
|
when :exclusive then
|
46
46
|
"occurred_at > '#{from_date_to_s}'"
|
47
47
|
when :fixed_point then
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
answer
|
52
|
-
|
48
|
+
if !@from.quarter.nil?
|
49
|
+
answer = "(year=#{@from.year} and quarter=#{@from.quarter})"
|
50
|
+
elsif !@from.week.nil? && @from.week == -1
|
51
|
+
answer = "((year=#{@from.year - 1} and week=#{EntryDate.calculate_week_of(@from.to_time.beginning_of_week)}) or (year=#{@from.year} and week=#{@from.week}))"
|
52
|
+
elsif !@from.week.nil? && @from.to_time.end_of_week.year != @from.year
|
53
|
+
answer = "((year=#{@from.year} and week=#{@from.week}) or (year=#{@from.year+1} and week=-1))"
|
54
|
+
elsif !@from.week.nil?
|
55
|
+
answer = "(year=#{@from.year} and week=#{@from.week})"
|
56
|
+
else
|
57
|
+
answer = "("
|
58
|
+
[:year,:month,:day,:hour,:min,:sec].each do |t|
|
59
|
+
next if @from.send(t).nil?
|
60
|
+
answer += " and " unless answer.size == 1
|
61
|
+
answer += "#{t}=#{from.send(t)}"
|
62
|
+
end
|
63
|
+
answer += ")"
|
53
64
|
end
|
54
|
-
answer += ")"
|
55
65
|
answer
|
56
66
|
end
|
57
67
|
elsif @from.nil? && !@to.nil?
|
data/lib/appstats/version.rb
CHANGED
data/spec/date_range_spec.rb
CHANGED
@@ -325,10 +325,30 @@ module Appstats
|
|
325
325
|
DateRange.new(:from => @date1, :format => :exclusive).to_sql.should == "occurred_at > '2010-10-31 23:59:59'"
|
326
326
|
end
|
327
327
|
|
328
|
-
it "should support from, fixed_point" do
|
328
|
+
it "should support from, fixed_point, month" do
|
329
329
|
DateRange.new(:from => @date1, :format => :fixed_point).to_sql.should == "(year=2010 and month=10)"
|
330
330
|
end
|
331
|
-
|
331
|
+
|
332
|
+
it "should support from, fixed_point, quarter" do
|
333
|
+
quarter = EntryDate.new(:year => 2010, :month => 3, :quarter => 1)
|
334
|
+
DateRange.new(:from => quarter, :format => :fixed_point).to_sql.should == "(year=2010 and quarter=1)"
|
335
|
+
end
|
336
|
+
|
337
|
+
it "should support from, fixed_point, week" do
|
338
|
+
week = EntryDate.new(:year => 2010, :month => 1, :day => 15, :week => 2)
|
339
|
+
DateRange.new(:from => week, :format => :fixed_point).to_sql.should == "(year=2010 and week=2)"
|
340
|
+
end
|
341
|
+
|
342
|
+
it "should support from, fixed_point, last week of year" do
|
343
|
+
week = EntryDate.new(:year => 2010, :month => 12, :day => 30, :week => 52)
|
344
|
+
DateRange.new(:from => week, :format => :fixed_point).to_sql.should == "((year=2010 and week=52) or (year=2011 and week=-1))"
|
345
|
+
end
|
346
|
+
|
347
|
+
it "should support from, fixed_point, first week of year" do
|
348
|
+
week = EntryDate.new(:year => 2011, :month => 1, :day => 1, :week => -1)
|
349
|
+
DateRange.new(:from => week, :format => :fixed_point).to_sql.should == "((year=2010 and week=52) or (year=2011 and week=-1))"
|
350
|
+
end
|
351
|
+
|
332
352
|
it "should support to, inclusive" do
|
333
353
|
DateRange.new(:to => @date1, :format => :inclusive).to_sql.should == "occurred_at <= '2010-10-31 23:59:59'"
|
334
354
|
end
|
data/spec/entry_spec.rb
CHANGED
@@ -193,18 +193,18 @@ module Appstats
|
|
193
193
|
end
|
194
194
|
|
195
195
|
it "should understand an entry without contexts" do
|
196
|
-
entry = Entry.create_from_logger_string("0.12.
|
196
|
+
entry = Entry.create_from_logger_string("0.12.2 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search")
|
197
197
|
Entry.count.should == @before_count + 1
|
198
198
|
entry.action.should == "address_search"
|
199
|
-
entry.raw_entry.should == "0.12.
|
199
|
+
entry.raw_entry.should == "0.12.2 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search"
|
200
200
|
entry.occurred_at.should == Time.parse("2010-09-21 23:15:20")
|
201
201
|
end
|
202
202
|
|
203
203
|
it "should understand contexts" do
|
204
|
-
entry = Entry.create_from_logger_string("0.12.
|
204
|
+
entry = Entry.create_from_logger_string("0.12.2 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live")
|
205
205
|
Entry.count.should == @before_count + 1
|
206
206
|
entry.action.should == "address_filter"
|
207
|
-
entry.raw_entry.should == "0.12.
|
207
|
+
entry.raw_entry.should == "0.12.2 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live"
|
208
208
|
entry.occurred_at.should == Time.parse("2010-09-21 23:15:20")
|
209
209
|
entry.contexts.size.should == 2
|
210
210
|
entry.contexts[0].context_key = "app_name"
|
data/spec/logger_spec.rb
CHANGED
@@ -115,7 +115,7 @@ module Appstats
|
|
115
115
|
|
116
116
|
it "should accept numbers" do
|
117
117
|
Appstats::Logger.entry(5, :blah => 6)
|
118
|
-
Appstats::Logger.raw_read.should == ["0.12.
|
118
|
+
Appstats::Logger.raw_read.should == ["0.12.2 setup[:,=,-n] 2010-09-21 23:15:20 action=5 : blah=6"]
|
119
119
|
end
|
120
120
|
|
121
121
|
end
|
@@ -124,7 +124,7 @@ module Appstats
|
|
124
124
|
|
125
125
|
it "should look similar to regular entry" do
|
126
126
|
Appstats::Logger.exception_entry(RuntimeError.new("blah"),:on => "login")
|
127
|
-
Appstats::Logger.raw_read.should == ["0.12.
|
127
|
+
Appstats::Logger.raw_read.should == ["0.12.2 setup[:,=,-n] 2010-09-21 23:15:20 action=appstats-exception : error=blah : on=login"]
|
128
128
|
end
|
129
129
|
|
130
130
|
end
|
@@ -141,29 +141,29 @@ module Appstats
|
|
141
141
|
|
142
142
|
it "should handle a statistics entry" do
|
143
143
|
expected = { :action => "address_search", :timestamp => "2010-09-21 23:15:20" }
|
144
|
-
actual = Appstats::Logger.entry_to_hash("0.12.
|
144
|
+
actual = Appstats::Logger.entry_to_hash("0.12.2 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search")
|
145
145
|
actual.should == expected
|
146
146
|
end
|
147
147
|
|
148
148
|
it "should handle contexts" do
|
149
149
|
expected = { :action => "address_filter", :timestamp => "2010-09-21 23:15:20", :server => "Live", :app_name => 'Market' }
|
150
|
-
actual = Appstats::Logger.entry_to_hash("0.12.
|
150
|
+
actual = Appstats::Logger.entry_to_hash("0.12.2 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live")
|
151
151
|
actual.should == expected
|
152
152
|
end
|
153
153
|
|
154
154
|
it "should handle actions with the delimiter (and change the delimiter)" do
|
155
155
|
expected = { :action => "address:=search-n", :timestamp => "2010-09-21 23:15:20" }
|
156
|
-
actual = Appstats::Logger.entry_to_hash("0.12.
|
156
|
+
actual = Appstats::Logger.entry_to_hash("0.12.2 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=search-n")
|
157
157
|
actual.should == expected
|
158
158
|
|
159
159
|
expected = { :action => "address::search==--n", :timestamp => "2010-09-21 23:15:20" }
|
160
|
-
actual = Appstats::Logger.entry_to_hash("0.12.
|
160
|
+
actual = Appstats::Logger.entry_to_hash("0.12.2 setup[:::,===,---n] 2010-09-21 23:15:20 action===address::search==--n")
|
161
161
|
actual.should == expected
|
162
162
|
end
|
163
163
|
|
164
164
|
it "should handle contexts with the delimiter (and change the delimiter)" do
|
165
165
|
expected = { :action => "address", :timestamp => "2010-09-21 23:15:20", :server => "market:eval=-n" }
|
166
|
-
actual = Appstats::Logger.entry_to_hash("0.12.
|
166
|
+
actual = Appstats::Logger.entry_to_hash("0.12.2 setup[::,==,--n] 2010-09-21 23:15:20 action==address :: server==market:eval=-n")
|
167
167
|
actual.should == expected
|
168
168
|
end
|
169
169
|
|
@@ -172,66 +172,66 @@ module Appstats
|
|
172
172
|
describe "#entry_to_s" do
|
173
173
|
|
174
174
|
it "should handle a statistics entry" do
|
175
|
-
expected = "0.12.
|
175
|
+
expected = "0.12.2 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search"
|
176
176
|
actual = Appstats::Logger.entry_to_s("address_search")
|
177
177
|
actual.should == expected
|
178
178
|
end
|
179
179
|
|
180
180
|
it "should handle numbers" do
|
181
|
-
expected = "0.12.
|
181
|
+
expected = "0.12.2 setup[:,=,-n] 2010-09-21 23:15:20 action=1 : note=2.2"
|
182
182
|
actual = Appstats::Logger.entry_to_s(1,:note => 2.2)
|
183
183
|
actual.should == expected
|
184
184
|
end
|
185
185
|
|
186
186
|
it "should handle default contexts" do
|
187
187
|
Appstats::Logger.default_contexts[:app_name] = "market"
|
188
|
-
expected = "0.12.
|
188
|
+
expected = "0.12.2 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search : app_name=market"
|
189
189
|
actual = Appstats::Logger.entry_to_s("address_search")
|
190
190
|
actual.should == expected
|
191
191
|
end
|
192
192
|
|
193
193
|
it "should handle contexts (and sort them by symbol)" do
|
194
|
-
expected = "0.12.
|
194
|
+
expected = "0.12.2 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live"
|
195
195
|
actual = Appstats::Logger.entry_to_s("address_filter", { :server => "Live", :app_name => 'Market' })
|
196
196
|
actual.should == expected
|
197
197
|
end
|
198
198
|
|
199
199
|
it "should handle actions with the delimiter (and change the delimiter)" do
|
200
|
-
expected = "0.12.
|
200
|
+
expected = "0.12.2 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=search-n"
|
201
201
|
actual = Appstats::Logger.entry_to_s("address:=search-n")
|
202
202
|
actual.should == expected
|
203
203
|
|
204
|
-
expected = "0.12.
|
204
|
+
expected = "0.12.2 setup[:::,===,---n] 2010-09-21 23:15:20 action===address::search==--n"
|
205
205
|
actual = Appstats::Logger.entry_to_s("address::search==--n")
|
206
206
|
actual.should == expected
|
207
207
|
end
|
208
208
|
|
209
209
|
it "should handle contexts with the delimiter (and change the delimiter)" do
|
210
|
-
expected = "0.12.
|
210
|
+
expected = "0.12.2 setup[::,==,--n] 2010-09-21 23:15:20 action==address :: server==market:eval=-n"
|
211
211
|
actual = Appstats::Logger.entry_to_s("address", :server => 'market:eval=-n')
|
212
212
|
actual.should == expected
|
213
213
|
end
|
214
214
|
|
215
215
|
it "should ignore spaces" do
|
216
|
-
expected = "0.12.
|
216
|
+
expected = "0.12.2 setup[:,=,-n] 2010-09-21 23:15:20 action=address search"
|
217
217
|
actual = Appstats::Logger.entry_to_s("address search")
|
218
218
|
actual.should == expected
|
219
219
|
end
|
220
220
|
|
221
221
|
it "should convert newlines in action" do
|
222
|
-
expected = "0.12.
|
222
|
+
expected = "0.12.2 setup[:,=,-n] 2010-09-21 23:15:20 action=address_-nsearch"
|
223
223
|
actual = Appstats::Logger.entry_to_s("address_\nsearch")
|
224
224
|
actual.should == expected
|
225
225
|
end
|
226
226
|
|
227
227
|
it "should convert newlines in context" do
|
228
|
-
expected = "0.12.
|
228
|
+
expected = "0.12.2 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search : blah=some-nlong-nstatement"
|
229
229
|
actual = Appstats::Logger.entry_to_s("address_search",:blah => "some\nlong\nstatement")
|
230
230
|
actual.should == expected
|
231
231
|
end
|
232
232
|
|
233
233
|
it "should convert newlines based on the delimiter" do
|
234
|
-
expected = "0.12.
|
234
|
+
expected = "0.12.2 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=--nsearch-n"
|
235
235
|
actual = Appstats::Logger.entry_to_s("address:=\nsearch-n")
|
236
236
|
actual.should == expected
|
237
237
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appstats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 43
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 12
|
9
|
-
-
|
10
|
-
version: 0.12.
|
9
|
+
- 2
|
10
|
+
version: 0.12.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andrew Forward
|