nametrainer 0.1.0 → 0.2.0

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.
data/README.md CHANGED
@@ -35,6 +35,8 @@ Additional settings:
35
35
 
36
36
  These settings facilitate quick recapitulation of already learned names
37
37
  or learning of new names.
38
+ Starting the application with `nametrainer --learning-mode` or with
39
+ `nametrainer -l` activates both settings.
38
40
 
39
41
  Collections
40
42
  -----------
@@ -1,7 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
2
 
3
- require 'Qt'
4
-
5
3
  require 'nametrainer'
6
4
 
7
5
  SRCPATH = File.dirname(__FILE__)
@@ -34,5 +32,5 @@ end
34
32
 
35
33
  # start
36
34
  app = Qt::Application.new ARGV
37
- Nametrainer::GUI.new(options[:collection])
35
+ Nametrainer::GUI.new(options)
38
36
  app.exec
@@ -16,7 +16,10 @@
16
16
  #
17
17
  # == Options
18
18
  #
19
- # -d, --demo:: Starts the application with a demo collection.
19
+ # -d, --[no-]demo:: Start the application with a demo collection.
20
+ #
21
+ # -l, --[no-]learning-mode:: Start the application in `learning-mode':
22
+ # use non-random order, display names at once.
20
23
  #
21
24
  # -h, --help:: Prints a brief help message and exits.
22
25
  #
@@ -35,7 +38,7 @@ require 'nametrainer/optionparser'
35
38
  require 'nametrainer/statistics'
36
39
  require 'nametrainer/version'
37
40
 
38
- # This module contains the classes for the +nametrainer+ tool
41
+ # This module contains the classes for the +nametrainer+ tool.
39
42
  module Nametrainer
40
43
 
41
44
  FILE_EXTENSIONS = %w{png jpg jpeg}
@@ -105,25 +105,33 @@ module Nametrainer
105
105
 
106
106
  # Returns a random index, preferring smaller indices.
107
107
  def weighted_random_index
108
- max_index = self.size - 1
109
- weighting_factor = 6 # index 0 will be about weighting_factor times more probable than max_index
110
-
111
- # construct an array with indices by repeatedly adding different parts of a range of indices
112
- indices = Array.new
113
- range = Array.new(self.size) {|i| i }
114
- 1.upto(weighting_factor) do
115
- |i| indices += range[0..(i.to_f/weighting_factor * max_index).ceil]
116
- end
108
+ indices = indices_urn(:size => self.size, :weighting_factor => 6)
117
109
 
118
110
  indices[rand(indices.size)]
119
111
  end
120
112
 
113
+ # Returns an array of all indices from 0 to :size - 1, where lower indices are
114
+ # more frequent than higher indices. Index 0 will be about :weighting_factor
115
+ # times more probable then the highest index.
116
+ def indices_urn(options)
117
+ size = options[:size]
118
+ weighting_factor = options[:weighting_factor]
119
+ urn = Array.new
120
+ # repeatedly add partial ranges of indices to urn
121
+ 1.upto(weighting_factor) do |i|
122
+ count = (i.to_f/weighting_factor * size).ceil
123
+ urn += (0...count).to_a
124
+ end
125
+
126
+ urn
127
+ end
128
+
121
129
  # class methods
122
130
 
123
131
  # Load a collection. Returns an array of Person instances.
124
132
  def self.load(directory, extensions)
125
133
  extension_list = extensions.join(',')
126
- files = Dir.glob("#{directory}/*.{#{extension_list}}")
134
+ files = Dir.glob("#{directory}/*.{#{extension_list}}").sort
127
135
  result = Array.new
128
136
  files.each do |file|
129
137
  name = get_name(file, extensions)
@@ -10,7 +10,7 @@ module Nametrainer
10
10
  # You can specify a collection that is loaded at startup.
11
11
  #
12
12
  # +collection_dir+ - path to collection
13
- def initialize(collection_dir = nil)
13
+ def initialize(options)
14
14
  super()
15
15
 
16
16
  set_window_title 'Name Trainer'
@@ -31,9 +31,15 @@ module Nametrainer
31
31
  @ordered_checkbox = Qt::CheckBox.new 'Non-random order'
32
32
  @display_checkbox = Qt::CheckBox.new "Display name at once"
33
33
 
34
+ if options[:learning_mode]
35
+ @ordered_checkbox.set_checked true
36
+ @display_checkbox.set_checked true
37
+ end
38
+
34
39
  init_gui
35
40
  show
36
41
 
42
+ collection_dir = options[:collection]
37
43
  init_collection File.expand_path(collection_dir) unless collection_dir.nil?
38
44
  end
39
45
 
@@ -95,9 +101,6 @@ module Nametrainer
95
101
  answer_buttons.add_widget @correct
96
102
  answer_buttons.add_widget @wrong
97
103
 
98
- @ordered_checkbox.set_checked false
99
- @display_checkbox.set_checked false
100
-
101
104
  right = Qt::VBoxLayout.new
102
105
  right.add_widget @show
103
106
  right.add_layout answer_buttons
@@ -143,6 +146,7 @@ module Nametrainer
143
146
  @collection_label.set_text "Collection: #{File.basename(@collection_dir)}"
144
147
  @statistics.reset
145
148
  @statistics_label.set_text @statistics.to_s
149
+ @person = nil
146
150
  choose_person
147
151
  end
148
152
 
@@ -18,8 +18,9 @@ module Nametrainer
18
18
  def self.parse!(argv)
19
19
 
20
20
  options = {
21
- :collection => nil,
22
- :demo => false
21
+ :collection => nil,
22
+ :demo => false,
23
+ :learning_mode => false
23
24
  }
24
25
 
25
26
  opt_parser = OptionParser.new do |opt|
@@ -48,8 +49,14 @@ module Nametrainer
48
49
  exit
49
50
  end
50
51
 
51
- opt.on('-d', '--demo', 'Starts the application with a demo collection.') do
52
- options[:demo] = true
52
+ opt.on('-d', '--[no-]demo', 'Start the application with a demo collection.') do |d|
53
+ options[:demo] = d
54
+ end
55
+
56
+ opt.on('-l', '--[no-]learning-mode',
57
+ "Start the application in `learning-mode':",
58
+ 'use non-random order, display names at once.') do |l|
59
+ options[:learning_mode] = l
53
60
  end
54
61
 
55
62
  opt.separator ''
@@ -1,12 +1,12 @@
1
1
  module Nametrainer
2
2
 
3
3
  PROGNAME = 'nametrainer'
4
- VERSION = '0.1.0'
5
- DATE = '2012-04-13'
4
+ VERSION = '0.2.0'
5
+ DATE = '2012-09-22'
6
6
  HOMEPAGE = 'https://github.com/stomar/nametrainer/'
7
7
 
8
8
  COPYRIGHT = "Copyright (C) 2012 Marcus Stollsteimer.\n" +
9
- "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n" +
9
+ "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n" +
10
10
  "This is free software: you are free to change and redistribute it.\n" +
11
11
  "There is NO WARRANTY, to the extent permitted by law."
12
12
 
@@ -1,4 +1,4 @@
1
- require 'lib/nametrainer/version'
1
+ require './lib/nametrainer/version'
2
2
 
3
3
  version = Nametrainer::VERSION
4
4
  date = Nametrainer::DATE
@@ -55,14 +55,6 @@ describe Nametrainer::Collection do
55
55
  @collection.sort.last.name.must_equal 'Albert Einstein'
56
56
  end
57
57
 
58
- it 'can return a random index' do
59
- samples = 100
60
- indices = Array.new(samples) { @collection.send(:weighted_random_index) }
61
- indices.size.must_equal samples
62
- indices.sort.first.must_be :>=, 0
63
- indices.sort.last.must_be :<, @collection.size
64
- end
65
-
66
58
  it 'can return a random person' do
67
59
  @collection.sample.must_be_instance_of Nametrainer::Person
68
60
  end
@@ -82,4 +74,22 @@ describe Nametrainer::Collection do
82
74
  person.increase_score
83
75
  @collection.last.score.must_equal 1
84
76
  end
77
+
78
+ # private methods
79
+ it 'can return a weighted index list' do
80
+ expected = [0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
81
+ 3, 3, 3, 4, 4, 4, 5, 5, 5,
82
+ 6, 6, 7, 7, 8, 8,
83
+ 9, 10, 11]
84
+ indices = @collection.send(:indices_urn, :size => 12, :weighting_factor => 4)
85
+ indices.sort.must_equal expected
86
+ end
87
+
88
+ it 'returns random indices in the correct range' do
89
+ samples = 100
90
+ indices = Array.new(samples) { @collection.send(:weighted_random_index) }
91
+ indices.size.must_equal samples
92
+ indices.sort.first.must_be :>=, 0
93
+ indices.sort.last.must_be :<, @collection.size
94
+ end
85
95
  end
@@ -9,7 +9,8 @@ describe Nametrainer::Optionparser do
9
9
  options = Nametrainer::Optionparser.parse!(['collection'])
10
10
  expected = {
11
11
  :collection => 'collection',
12
- :demo => false
12
+ :demo => false,
13
+ :learning_mode => false
13
14
  }
14
15
  options.must_equal expected
15
16
  end
@@ -20,6 +21,22 @@ describe Nametrainer::Optionparser do
20
21
  options[:demo].must_equal true
21
22
  end
22
23
 
24
+ it 'should recognize the --no-demo option' do
25
+ options = Nametrainer::Optionparser.parse!(['--no-demo'])
26
+ options[:demo].must_equal false
27
+ end
28
+
29
+ it 'should recognize the -l option' do
30
+ options = Nametrainer::Optionparser.parse!(['-l'])
31
+ options[:collection].must_be_nil
32
+ options[:learning_mode].must_equal true
33
+ end
34
+
35
+ it 'should recognize the --no-learning-mode option' do
36
+ options = Nametrainer::Optionparser.parse!(['--no-learning-mode'])
37
+ options[:learning_mode].must_equal false
38
+ end
39
+
23
40
  it 'should not accept wrong number of arguments' do
24
41
  lambda { Nametrainer::Optionparser.parse!(['collection1', 'collection2']) }.must_raise ArgumentError
25
42
  lambda { Nametrainer::Optionparser.parse!(['']) }.must_raise ArgumentError
metadata CHANGED
@@ -1,59 +1,46 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: nametrainer
3
- version: !ruby/object:Gem::Version
4
- hash: 27
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 0
10
- version: 0.1.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Marcus Stollsteimer
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-04-13 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-09-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: rake
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &72380950 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
32
22
  type: :development
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: minitest
36
23
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *72380950
25
+ - !ruby/object:Gem::Dependency
26
+ name: minitest
27
+ requirement: &72379800 !ruby/object:Gem::Requirement
38
28
  none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
46
33
  type: :development
47
- version_requirements: *id002
48
- description: nametrainer is a name learning trainer using the Qt GUI toolkit. It will assist you in learning people's names from a collection of images.
34
+ prerelease: false
35
+ version_requirements: *72379800
36
+ description: nametrainer is a name learning trainer using the Qt GUI toolkit. It will
37
+ assist you in learning people's names from a collection of images.
49
38
  email: sto.mar@web.de
50
- executables:
39
+ executables:
51
40
  - nametrainer
52
41
  extensions: []
53
-
54
42
  extra_rdoc_files: []
55
-
56
- files:
43
+ files:
57
44
  - README.md
58
45
  - Rakefile
59
46
  - nametrainer.gemspec
@@ -85,40 +72,35 @@ files:
85
72
  - test/collection/002.JPG
86
73
  - test/collection/nametrainer.dat
87
74
  homepage: https://github.com/stomar/nametrainer/
88
- licenses:
75
+ licenses:
89
76
  - GPL-3
90
77
  post_install_message:
91
- rdoc_options:
78
+ rdoc_options:
92
79
  - --charset=UTF-8
93
- require_paths:
80
+ require_paths:
94
81
  - lib
95
- required_ruby_version: !ruby/object:Gem::Requirement
82
+ required_ruby_version: !ruby/object:Gem::Requirement
96
83
  none: false
97
- requirements:
98
- - - ">="
99
- - !ruby/object:Gem::Version
100
- hash: 3
101
- segments:
102
- - 0
103
- version: "0"
104
- required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
89
  none: false
106
- requirements:
107
- - - ">="
108
- - !ruby/object:Gem::Version
109
- hash: 3
110
- segments:
111
- - 0
112
- version: "0"
113
- requirements:
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements:
114
95
  - the Qt toolkit and Qt bindings for Ruby
115
96
  rubyforge_project: nametrainer
116
- rubygems_version: 1.7.2
97
+ rubygems_version: 1.8.11
117
98
  signing_key:
118
99
  specification_version: 3
119
100
  summary: nametrainer is a name learning trainer using the Qt GUI toolkit.
120
- test_files:
101
+ test_files:
121
102
  - test/test_person.rb
122
103
  - test/test_statistics.rb
123
104
  - test/test_collection.rb
124
105
  - test/test_optionparser.rb
106
+ has_rdoc: