quixote 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .rvmrc
6
+ .DS_Store
7
+
8
+ # docs
9
+ rdoc
10
+ doc
11
+ .yardoc
12
+
13
+ # vim
14
+ *.swp
15
+
16
+ # rcov generated
17
+ coverage
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in quixote.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,12 @@
1
+ Copyright (c) 2012. Matt Sanders.
2
+ All rights reserved.
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. No attribution is required by products that make use of this software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9
+
10
+ Except as contained in this notice, the name(s) of the above copyright holders shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization.
11
+
12
+ Contributors to this project agree to grant all rights to the copyright holder of the primary product. Attribution is maintained in the source control history of the product.
@@ -0,0 +1,59 @@
1
+ Quixote
2
+ =======
3
+
4
+ A simple tool for statefully generating time-series data.
5
+
6
+ ## Installation
7
+
8
+ In your shell:
9
+
10
+ gem install quixote
11
+
12
+ Then, in your application or script:
13
+
14
+ require 'quixote'
15
+
16
+ ## Basic Usage
17
+
18
+ For each data stream you want to generate, set up a `Quixote` object. Here are some examples:
19
+
20
+ percentage = Quixote.new(:min => 0, :max => 100, :range_by => 10)
21
+ fahrenheit = Quixote.new(:min => -30.0, :max => 120.0, :range_by => 3.0)
22
+
23
+ If you don't specify any initialization options the object will be assumed to be a percentage and will default to the settings of the `percentage` object above.
24
+
25
+ An initial value will be randomly generated and can be accessed with `#last`:
26
+
27
+ percentage.last #=> 58
28
+
29
+ If you want to enforce a certain starting value, just set last to whatever you want:
30
+
31
+ percentage.last = 60
32
+
33
+ By default each following value will range up or down by a random value up to a max of `range_by`. To get a series of stateful values just call `#next`:
34
+
35
+ percentage.next #=> 64
36
+ percentage.next #=> 66
37
+ percentage.next #=> 58
38
+
39
+ You can use `#last` to retrieve the most recently generated number or move the range to a number you select at any time.
40
+
41
+ This makes it trivial to generate stateful runs of any length you want:
42
+
43
+ values = []
44
+ 100.times { values << percentage.next }
45
+
46
+ values #=> [49, 55, 48, …]
47
+
48
+
49
+ ## Contribution
50
+
51
+ * Check the latest master to make sure the feature hasn't been implemented / the bug hasn't been fixed yet.
52
+ * Check the issue tracker to see if someone has already requested and/or contributed it.
53
+ * Fork the project and submit a pull request from a feature or bugfix branch.
54
+ * Please include tests. This is important so we don't break your changes unintentionally in a future version.
55
+ * Please don't modify the gemspec, Rakefile, version, or changelog. If you do change these files, please isolate a separate commit so we can cherry-pick around it.
56
+
57
+ ## Copyright
58
+
59
+ Copyright (c) 2012 Matt Sanders. See LICENSE for details.
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ task :default => :test
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'test'
8
+ end
9
+
10
+ # IRB
11
+ desc "Open an irb session preloaded with this library"
12
+ task :console do
13
+ sh "irb -rubygems -r ./lib/quixote.rb"
14
+ end
@@ -0,0 +1,49 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require "quixote/version"
5
+
6
+ class Quixote
7
+ attr_accessor :min, :max, :range_by, :last
8
+
9
+ def initialize(options={})
10
+ defaults = {
11
+ :max => 100,
12
+ :min => 0,
13
+ :range_by => 10
14
+ }
15
+
16
+ defaults.merge(options).each do |key, value|
17
+ send("#{key}=", value)
18
+ end
19
+
20
+ @last = random_start_point
21
+ end
22
+
23
+ def next
24
+ if last == max
25
+ decrement
26
+ elsif last == min || (rand < 0.5)
27
+ increment
28
+ else
29
+ decrement
30
+ end
31
+ last
32
+ end
33
+
34
+ private
35
+
36
+ def increment
37
+ @last += rand(range_by+1)
38
+ @last = max if last > max
39
+ end
40
+
41
+ def decrement
42
+ @last -= rand(range_by+1)
43
+ @last = min if last < min
44
+ end
45
+
46
+ def random_start_point
47
+ rand((max-min)+1) + min
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ class Quixote
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "quixote/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "quixote"
7
+ s.version = Quixote::VERSION
8
+
9
+ s.authors = ["Matt Sanders"]
10
+ s.email = ["matt@modal.org"]
11
+ s.homepage = "https://github.com/nextmat/quixote"
12
+ s.summary = %q{Simple stateful generator for time-series data}
13
+ s.description = %q{A flexible, stateful generator for sample time-series data}
14
+
15
+ #s.rubyforge_project = "quixote"
16
+
17
+ s.rdoc_options = ["--charset=UTF-8"]
18
+ s.extra_rdoc_files = %w[LICENSE]
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ # s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
24
+
25
+ # specify any dependencies here; for example:
26
+ # s.add_development_dependency "rspec"
27
+ # s.add_runtime_dependency "rest-client"
28
+ end
@@ -0,0 +1,10 @@
1
+ require 'minitest/autorun'
2
+ require 'pp'
3
+
4
+ # require pry if available
5
+ begin
6
+ require 'pry'
7
+ rescue LoadError
8
+ end
9
+
10
+ require 'quixote'
@@ -0,0 +1,53 @@
1
+ puts "running"
2
+
3
+ require "helper"
4
+
5
+ class TextQuixote < MiniTest::Spec
6
+
7
+ def test_defaults
8
+ q = Quixote.new
9
+ assert_equal 100, q.max
10
+ assert_equal 0, q.min
11
+ assert_equal 10, q.range_by
12
+ end
13
+
14
+ def test_initialization
15
+ q = Quixote.new(:min => 50, :max => 200, :range_by => 80)
16
+ assert_equal 50, q.min
17
+ assert_equal 200, q.max
18
+ assert_equal 80, q.range_by
19
+ end
20
+
21
+ def test_starting_point
22
+ 100.times do
23
+ q = Quixote.new(:max => 20, :min => 10)
24
+ assert q.last >= 10, "#{q.last} is < min (10)"
25
+ assert q.last <= 20, "#{q.last} is > max (20)"
26
+ end
27
+
28
+ q = Quixote.new
29
+ q.last = 25
30
+ assert_equal 25, q.last, 'last should be settable'
31
+ end
32
+
33
+ def test_range_limits
34
+ q = Quixote.new(:min => 1, :max => 10, :range_by => 4)
35
+ values = []
36
+ 1000.times { values << q.next } # build up a bunch of values
37
+ assert values.min >= 1, 'should never range below min'
38
+ assert values.max <= 10, 'should never range above max'
39
+ end
40
+
41
+ def test_range_size
42
+ q = Quixote.new(:min => 1, :max => 20, :range_by => 6)
43
+ last = q.last
44
+ deltas = []
45
+ 1000.times do
46
+ deltas << (q.next - last).abs
47
+ last = q.last
48
+ end
49
+ assert_equal 6, deltas.max
50
+ assert_equal 0, deltas.min
51
+ end
52
+
53
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: quixote
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matt Sanders
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-15 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A flexible, stateful generator for sample time-series data
15
+ email:
16
+ - matt@modal.org
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files:
20
+ - LICENSE
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - LICENSE
25
+ - README.md
26
+ - Rakefile
27
+ - lib/quixote.rb
28
+ - lib/quixote/version.rb
29
+ - quixote.gemspec
30
+ - test/helper.rb
31
+ - test/test_quixote.rb
32
+ homepage: https://github.com/nextmat/quixote
33
+ licenses: []
34
+ post_install_message:
35
+ rdoc_options:
36
+ - --charset=UTF-8
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 1.8.16
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: Simple stateful generator for time-series data
57
+ test_files:
58
+ - test/helper.rb
59
+ - test/test_quixote.rb
60
+ has_rdoc: