time_trap 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: decaa1492bb3108915fc2d0d23de83bc1bd4b3fd
4
- data.tar.gz: f0c33bec056e1164c9dae75a52aa980b3aa93090
3
+ metadata.gz: 9361576b04ddf585f8d821923da1e6ea6f5f72a4
4
+ data.tar.gz: 66c919c5dee91255159444cd84a36f763f1974ee
5
5
  SHA512:
6
- metadata.gz: c0aa92b03f7c0715bec78922c79176b49cd35e3e0d228cf06740f035142f66ef7222335ac42eaf58be5ac6f8def6051f3a105baf5748ab4a161e2b65c9ab2244
7
- data.tar.gz: 98518edd71bcb487521d4e31a1f813a963322dc845718bd8dc92fa2c52031a7cd1a24126de7e8daf4eed24edbee6be22c6449da600e0d780dc4d77d6bdc6ed11
6
+ metadata.gz: 2a4d5b58a2a1d820877ceb73565b5ffd68936aadb683c81bec8410c6f16b93c884deae21562ee0c18dd900a64fda10313e60eddf247b9f1d9fb7cf32147a9084
7
+ data.tar.gz: 995f619ce1d64aa20e17859a5859d1f9b66e2cfd0f6e78d74ee0c5c2d1f96499a1ec18c86f814aea13dccec31627360ef2c911491b8c4a82d163e0aa048aac01
data/README.md CHANGED
@@ -7,7 +7,7 @@ as they are created (eg. tweets, exceptions in a log file, or :Q
7
7
 
8
8
  Add this line to your application's Gemfile:
9
9
 
10
- gem 'timetrap'
10
+ gem 'time_trap'
11
11
 
12
12
  And then execute:
13
13
 
@@ -15,10 +15,15 @@ And then execute:
15
15
 
16
16
  Or install it yourself as:
17
17
 
18
- $ gem install timetrap
18
+ $ gem install time_trap
19
19
 
20
20
  ## Usage
21
21
 
22
+ tt = TimeTrap.new
23
+ tt.add("benedict")
24
+ tt.add("cumberbatch")
25
+
26
+
22
27
  ## Contributing
23
28
 
24
29
  1. Fork it ( http://github.com/<my-github-username>/timetrap/fork )
@@ -30,11 +30,16 @@ class TimeTrap
30
30
  @tt.sort_by(&block)
31
31
  end
32
32
 
33
- def top_x(rank)
33
+ def top(rank)
34
34
  ret = @tt.sort_by {|k,v| -v.count}.map{|k,v| k}
35
35
  return ret[0..rank - 1]
36
36
  end
37
37
 
38
+ def last(secs)
39
+ t = Time.now.to_i
40
+ return window(t - secs, t)
41
+ end
42
+
38
43
  def has_key?(key)
39
44
  return @tt.has_key?(key)
40
45
  end
@@ -1,3 +1,3 @@
1
1
  module Timetrap
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -73,12 +73,12 @@ describe TimeTrap do
73
73
  end
74
74
  end
75
75
 
76
- context "#top_x" do
76
+ context "#top" do
77
77
  it "gives you the top values sorted by code block" do
78
78
  (0..0).each {|i| ttrap.add("1")}
79
79
  (0..1).each {|i| ttrap.add("2")}
80
80
  (0..2).each {|i| ttrap.add("3")}
81
- arr = ttrap.top_x(1)
81
+ arr = ttrap.top(1)
82
82
  expect(arr).to match_array(["3"])
83
83
  end
84
84
  end
@@ -96,4 +96,27 @@ describe TimeTrap do
96
96
  expect(ttrap.window(t - 60, t).size).to eq(0)
97
97
  end
98
98
  end
99
+
100
+ context "#last" do
101
+ it "gives last day's worth of data" do
102
+ t = Time.now.to_i
103
+ (0..9).each{|i| ttrap.add(i, t - 60*60*24 - 1)}
104
+ (10..19).each{|i| ttrap.add(i, t) }
105
+ expect(ttrap.last(60*60*24).keys).to match_array((10..19).to_a)
106
+ end
107
+
108
+ it "gives last hour's worth of data" do
109
+ t = Time.now.to_i
110
+ (0..9).each{|i| ttrap.add(i, t - 60*24 - 1)}
111
+ (10..19).each{|i| ttrap.add(i, t) }
112
+ expect(ttrap.last(60*24).keys).to match_array((10..19).to_a)
113
+ end
114
+
115
+ it "gives last minute's worth of data" do
116
+ t = Time.now.to_i
117
+ (0..9).each{|i| ttrap.add(i, t - 60 - 1)}
118
+ (10..19).each{|i| ttrap.add(i, t) }
119
+ expect(ttrap.last(60).keys).to match_array((10..19).to_a)
120
+ end
121
+ end
99
122
  end
data/time_trap.gemspec CHANGED
@@ -7,10 +7,10 @@ Gem::Specification.new do |spec|
7
7
  spec.name = "time_trap"
8
8
  spec.version = Timetrap::VERSION
9
9
  spec.authors = ["Pat Farrell"]
10
- spec.email = ["pfarrell@ulive.com"]
10
+ spec.email = ["mr.patfarrell@gmail.com"]
11
11
  spec.summary = %q{"exposes a data structure suitable for capturing and inspecting moving windows of data"}
12
12
  spec.description = %q{"timetrap is a work in progress to create a simple data strucutre that allows for windowed inspection of counts added to a hash"}
13
- spec.homepage = ""
13
+ spec.homepage = "http://github.com/pfarrell/timetrap"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time_trap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Farrell
@@ -97,7 +97,7 @@ dependencies:
97
97
  description: "\"timetrap is a work in progress to create a simple data strucutre that
98
98
  allows for windowed inspection of counts added to a hash\""
99
99
  email:
100
- - pfarrell@ulive.com
100
+ - mr.patfarrell@gmail.com
101
101
  executables: []
102
102
  extensions: []
103
103
  extra_rdoc_files: []
@@ -116,7 +116,7 @@ files:
116
116
  - spec/timetrap/deque_spec.rb
117
117
  - spec/timetrap/timetrap_spec.rb
118
118
  - time_trap.gemspec
119
- homepage: ''
119
+ homepage: http://github.com/pfarrell/timetrap
120
120
  licenses:
121
121
  - MIT
122
122
  metadata: {}