estimator 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2845164bd7621caea7c3d9723f4f548ca070a9bc
4
- data.tar.gz: f6710f320d6f4d55bf49085683fa3bcffb4c636e
3
+ metadata.gz: d42b21689bf6ebcbd2d922c3493497e529b9c2c7
4
+ data.tar.gz: dd163639bdb879081bbc0e1858d5f838cbb95497
5
5
  SHA512:
6
- metadata.gz: 7858fb248066599e0c546a740602269527df372c89187e7a5bb92e9af30eb16305a931b086920903b71c0d05e6e6b4710044c558528d13572de1613e1addf5c6
7
- data.tar.gz: 50e1dcfe8d96b89d297807458fc26f3f8a24ffa2931335bf22be013e4155c4d08c506416a29a80e5d77d27dcf357c77b6bef2068ecde0dad244fabb2ecb345ba
6
+ metadata.gz: c4cd3f8c31e88b9d323ca525214f3bb8e4d0ba6648ea46863d97970de93c160e57221a2d608c1469564714ca91f1c62d6c3b7fea139a893e22b509242cf3b515
7
+ data.tar.gz: 3151b8a4285cab073b67fabaf063963806d7aa2cc898bf0f460c9d55e1f98cddcb7c474a5794e8ec3ed01ad44dbfceec0207180c69df5b78207342bd696265d8
data/Rakefile CHANGED
@@ -23,39 +23,17 @@ def dump_load_path
23
23
  puts "Found in #{path}"
24
24
  end
25
25
  end
26
+
26
27
  require 'bundler'
27
28
  require 'rake/clean'
28
-
29
29
  require 'rake/testtask'
30
30
 
31
- require 'cucumber'
32
- require 'cucumber/rake/task'
33
- gem 'rdoc' # we need the installed RDoc gem, not the system one
34
- require 'rdoc/task'
35
-
36
31
  include Rake::DSL
37
32
 
38
33
  Bundler::GemHelper.install_tasks
39
34
 
40
-
41
35
  Rake::TestTask.new do |t|
42
- t.pattern = 'test/tc_*.rb'
43
- end
44
-
45
-
46
- CUKE_RESULTS = 'results.html'
47
- CLEAN << CUKE_RESULTS
48
- Cucumber::Rake::Task.new(:features) do |t|
49
- t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty --no-source -x"
50
- t.fork = false
36
+ t.pattern = 'test/*_test.rb'
51
37
  end
52
38
 
53
- Rake::RDocTask.new do |rd|
54
-
55
- rd.main = "README.rdoc"
56
-
57
- rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
58
- end
59
-
60
- task :default => [:test,:features]
61
-
39
+ task :default => :test
data/bin/estimator CHANGED
@@ -1,38 +1,42 @@
1
1
  #!/usr/bin/env ruby
2
-
3
2
  require 'optparse'
4
3
  require 'methadone'
5
4
  require 'estimator'
6
5
 
7
6
  class App
8
- include Methadone::Main
9
- include Methadone::CLILogging
7
+ include Methadone::Main
8
+ include Methadone::CLILogging
10
9
 
11
- main do |value, time|
12
- fm = Estimator::Estimate.new( options[:file] )
13
- fm.load
10
+ main do |value, time|
11
+ estimator_db_name = options.fetch( :file, 'estimator_db.yml' )
12
+ estimator_db_path = "#{Dir.pwd}/#{estimator_db_name}"
13
+ debug "creating estimator with db [#{estimator_db_path}]"
14
14
 
15
- if value.nil?
16
- if options[:'last-estimate']
17
- puts fm.last_estimate
18
- else
19
- puts fm.estimate
20
- end
21
- else
22
- time = fm.add_value( value, time )
23
- puts "added #{value} on #{time}"
24
- end
15
+ fm = Estimator::Estimate.new( estimator_db_path )
16
+ # TODO: check for exception
17
+ fm.load
25
18
 
26
- fm.save!
27
- end
19
+ unless value.nil?
20
+ time = fm.add_value( value, time )
21
+ info "added #{value} on #{time}"
22
+ else
23
+ if options[:'last-estimate']
24
+ info fm.last_estimate
25
+ else
26
+ info fm.estimate
27
+ end
28
+ end
29
+
30
+ fm.save!
31
+ end
28
32
 
29
- description "Estimate remaining time based on previous values"
30
- on '--file NAME', 'Database file name'
31
- on '--last-estimate', 'Show last estimate (saved on database)'
32
- arg :value, :optional, 'Value to estimate'
33
- arg :time, :optional, 'When the value happened'
33
+ description 'Estimate remaining time based on previous values'
34
+ on '--file NAME', 'Database file name'
35
+ on '--last-estimate', 'Show last estimate (saved on database)'
36
+ arg :value, :optional, 'Value to estimate'
37
+ arg :time, :optional, 'When the value happened'
34
38
 
35
- version Estimator::VERSION
36
- use_log_level_option
37
- go!
39
+ version Estimator::VERSION
40
+ use_log_level_option
41
+ go!
38
42
  end
data/estimator.gemspec CHANGED
@@ -4,21 +4,22 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'estimator/version'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
- gem.name = "estimator"
8
- gem.version = Estimator::VERSION
9
- gem.authors = ["Marcos Trovilho"]
10
- gem.email = ["marcos@trovilho.com"]
11
- gem.description = %q{Estimate remaining time based on previous values}
12
- gem.summary = %q{Estimate remaining time based on previous values}
13
- gem.homepage = ""
7
+ gem.name = 'estimator'
8
+ gem.version = Estimator::VERSION
9
+ gem.authors = ['Marcos Trovilho']
10
+ gem.email = ['marcos@trovilho.com']
11
+ gem.description = %q{Estimate remaining time based on previous values}
12
+ gem.summary = %q{Estimate remaining time based on previous values}
13
+ gem.homepage = 'https://github.com/mtrovilho/estimator'
14
+ gem.license = 'MIT'
14
15
 
15
- gem.files = `git ls-files`.split($/)
16
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
- gem.require_paths = ["lib"]
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ['lib']
19
20
 
20
- gem.add_dependency('methadone')
21
+ gem.add_dependency 'methadone'
21
22
 
22
- gem.add_development_dependency('rake')
23
- gem.add_development_dependency('aruba')
23
+ gem.add_development_dependency 'bundler'
24
+ gem.add_development_dependency 'rake'
24
25
  end
@@ -1,3 +1,3 @@
1
1
  module Estimator
2
- VERSION = "0.0.2"
2
+ VERSION = '0.0.3'
3
3
  end
data/lib/estimator.rb CHANGED
@@ -2,46 +2,54 @@ require 'estimator/version'
2
2
  require 'yaml'
3
3
 
4
4
  module Estimator
5
- class Estimate
6
- attr_reader :values
7
- attr_reader :last_estimate
8
- attr_reader :file_path
9
-
10
- def initialize( file_name )
11
- file_name = 'estimator_db.yml' if file_path.nil?
12
- @file_path = "#{Dir.pwd}/#{file_name}"
13
- end
5
+ class Estimate
6
+ LAST_ESTIMATE_EMPTY_STRING = 'last estimate is empty'
14
7
 
15
- def load
16
- save! unless File.exists?( @file_path )
17
- yaml_file = ( YAML.load_file( @file_path ) || {} )
18
- @values = ( yaml_file[:values] || {} )
19
- @last_estimate = ( yaml_file[:last_estimate] || 'last estimate is empty' )
20
- end
8
+ attr_reader :values
9
+ attr_reader :last_estimate
10
+ attr_reader :file_path
21
11
 
22
- def save!
23
- File.open( @file_path, 'w' ) do |f|
24
- f.write( {
25
- values: @values,
26
- last_estimate: @last_estimate
27
- }.to_yaml )
28
- end
29
- end
12
+ # TODO: handle file better
13
+ def initialize( file_path )
14
+ @file_path = file_path
15
+ @values = {}
16
+ @last_estimate = LAST_ESTIMATE_EMPTY_STRING
17
+ end
30
18
 
31
- def add_value( value, time = nil )
32
- time = Time.now if time.nil?
33
- @values[value.to_i] = time
34
- end
19
+ def load( file_path = @file_path )
20
+ # TODO: change to exception?
21
+ return nil unless File.exists?( file_path )
22
+ # TODO: check for exception
23
+ yaml_file = YAML.load_file( file_path )
24
+ @values = yaml_file.fetch( :values, {} )
25
+ @last_estimate = yaml_file.fetch( :last_estimate, LAST_ESTIMATE_EMPTY_STRING )
26
+ end
35
27
 
36
- def estimate
37
- return 'add more values before estimating' unless @values.count > 1
38
- # y = ax+b
39
- b = @values.keys.sort.last
40
- y = @values.keys.sort.first
41
- x = @values[y] - @values[b]
42
- a = (y-b)/x
43
- @last_estimate = @values[b] + (-b/a)
44
- end
28
+ def save!
29
+ File.open( @file_path, 'w' ) do |f|
30
+ f.write( {
31
+ values: @values,
32
+ last_estimate: @last_estimate
33
+ }.to_yaml )
34
+ end
35
+ end
36
+
37
+ def add_value( value, time = nil )
38
+ time = Time.now if time.nil?
39
+ @values[value] = time
40
+ end
45
41
 
46
- end
42
+ # TODO: Moving Averages
43
+ # http://en.wikipedia.org/wiki/Moving_average
44
+ def estimate
45
+ return 'add more values before estimating' unless @values.count > 1
46
+ # y = ax+b
47
+ b = @values.keys.sort.last
48
+ y = @values.keys.sort.first
49
+ x = @values[y] - @values[b]
50
+ a = (y-b)/x
51
+ @last_estimate = @values[b] + (-b/a)
52
+ end
53
+
54
+ end
47
55
  end
@@ -1,9 +1,37 @@
1
- require 'minitest/autoload'
1
+ require 'minitest/autorun'
2
+ require 'estimator'
3
+ require 'yaml'
4
+ require 'time'
2
5
 
3
6
  class EstimatorTest < MiniTest::Unit::TestCase
4
7
 
5
- def test_truth
6
- assert true
7
- end
8
+ def setup
9
+ yaml_file = "#{Dir.pwd}/test/fixtures/sample_db.yml"
10
+ @yaml = YAML.load_file( yaml_file )
11
+ @estimator = Estimator::Estimate.new( yaml_file )
12
+ end
13
+
14
+ def test_load_yaml
15
+ yaml_file = "#{Dir.pwd}/test/fixtures/sample_db.yml"
16
+ yaml = YAML.load_file( yaml_file )
17
+ @estimator.load( yaml_file )
18
+
19
+ yaml[:values].each do |key, value|
20
+ assert_equal value, @estimator.values[key]
21
+ end
22
+ assert_equal yaml[:last_estimate], @estimator.last_estimate
23
+ end
24
+
25
+ def test_add_value
26
+ value = Random.rand
27
+ @estimator.add_value( value )
28
+ assert @estimator.values.has_key?( value )
29
+ end
30
+
31
+ def test_estimate
32
+ @estimator.add_value( 100, Time.parse('2014-05-07') )
33
+ @estimator.add_value( 50, Time.parse('2014-05-08') )
34
+ assert_equal Time.parse('2014-05-09'), @estimator.estimate
35
+ end
8
36
 
9
37
  end
@@ -0,0 +1,5 @@
1
+ ---
2
+ :values:
3
+ 100.0: 2014-05-07 20:16:32.954822000 -03:00
4
+ 50.0: 2014-05-07 20:16:38.054459000 -03:00
5
+ :last_estimate: 2014-05-07 20:16:43.154095999 -03:00
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: estimator
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
  - Marcos Trovilho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-05 00:00:00.000000000 Z
11
+ date: 2014-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: methadone
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '>='
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: aruba
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '>='
@@ -67,14 +67,13 @@ files:
67
67
  - Rakefile
68
68
  - bin/estimator
69
69
  - estimator.gemspec
70
- - features/estimator.feature
71
- - features/step_definitions/estimator_steps.rb
72
- - features/support/env.rb
73
70
  - lib/estimator.rb
74
71
  - lib/estimator/version.rb
75
72
  - test/estimator_test.rb
76
- homepage: ''
77
- licenses: []
73
+ - test/fixtures/sample_db.yml
74
+ homepage: https://github.com/mtrovilho/estimator
75
+ licenses:
76
+ - MIT
78
77
  metadata: {}
79
78
  post_install_message:
80
79
  rdoc_options: []
@@ -97,8 +96,6 @@ signing_key:
97
96
  specification_version: 4
98
97
  summary: Estimate remaining time based on previous values
99
98
  test_files:
100
- - features/estimator.feature
101
- - features/step_definitions/estimator_steps.rb
102
- - features/support/env.rb
103
99
  - test/estimator_test.rb
100
+ - test/fixtures/sample_db.yml
104
101
  has_rdoc:
@@ -1,13 +0,0 @@
1
- Feature: My bootstrapped app kinda works
2
- In order to get going on coding my awesome app
3
- I want to have aruba and cucumber setup
4
- So I don't have to do it myself
5
-
6
- Scenario: App just runs
7
- When I get help for "estimator"
8
- Then the exit status should be 0
9
- And the banner should be present
10
- And the banner should document that this app takes options
11
- And the following options should be documented:
12
- |--version|
13
- And the banner should document that this app takes no arguments
@@ -1 +0,0 @@
1
- # Put your step definitions here
@@ -1,16 +0,0 @@
1
- require 'aruba/cucumber'
2
- require 'methadone/cucumber'
3
-
4
- ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
5
- LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
6
-
7
- Before do
8
- # Using "announce" causes massive warnings on 1.9.2
9
- @puts = true
10
- @original_rubylib = ENV['RUBYLIB']
11
- ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
12
- end
13
-
14
- After do
15
- ENV['RUBYLIB'] = @original_rubylib
16
- end