nametrainer 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +12 -2
- data/lib/nametrainer/collection.rb +16 -11
- data/lib/nametrainer/gui.rb +18 -3
- data/lib/nametrainer/person.rb +1 -1
- data/lib/nametrainer/version.rb +2 -2
- data/nametrainer.gemspec +3 -3
- data/screenshot.png +0 -0
- data/test/test_collection.rb +9 -0
- data/test/test_person.rb +2 -2
- metadata +6 -6
data/README.md
CHANGED
@@ -15,7 +15,7 @@ use `nametrainer --demo` or `nametrainer -d`.
|
|
15
15
|
|
16
16
|
With a collection loaded, the application window will look similar to this:
|
17
17
|
|
18
|
-
<img src="https://github.com/stomar/nametrainer/raw/master/screenshot.png" alt="Screenshot" width="
|
18
|
+
<img src="https://github.com/stomar/nametrainer/raw/master/screenshot.png" alt="Screenshot" width="455" height="403" />
|
19
19
|
|
20
20
|
`nametrainer` shows a randomly chosen image.
|
21
21
|
You can then display the corresponding name and tell the application
|
@@ -24,7 +24,17 @@ Persons that you do not know will be shown more often.
|
|
24
24
|
|
25
25
|
Note that for reasons of speed and convenience it is not necessary
|
26
26
|
to type in the name (so be honest to yourself).
|
27
|
-
There are also keyboard shortcuts for "power users".
|
27
|
+
There are also keyboard shortcuts for "power users" (see the application's `Help`).
|
28
|
+
|
29
|
+
Additional settings:
|
30
|
+
|
31
|
+
- Check `Non-random order` to show the images in ordered sequence.
|
32
|
+
|
33
|
+
- Check `Display name at once` to display the names immediately when
|
34
|
+
a person is shown.
|
35
|
+
|
36
|
+
These settings facilitate quick recapitulation of already learned names
|
37
|
+
or learning of new names.
|
28
38
|
|
29
39
|
Collections
|
30
40
|
-----------
|
@@ -38,16 +38,14 @@ module Nametrainer
|
|
38
38
|
super()
|
39
39
|
@directory = directory
|
40
40
|
@extensions = extensions.to_set
|
41
|
-
@extensions.merge extensions.map {|i| i.upcase}
|
41
|
+
@extensions.merge extensions.map {|i| i.upcase }
|
42
42
|
self.concat self.class.load(@directory, @extensions.to_a)
|
43
43
|
end
|
44
44
|
|
45
45
|
# Returns an array of all names.
|
46
46
|
def names
|
47
47
|
all_names = Array.new
|
48
|
-
self.each
|
49
|
-
all_names << person.name
|
50
|
-
end
|
48
|
+
self.each {|person| all_names << person.name }
|
51
49
|
|
52
50
|
all_names
|
53
51
|
end
|
@@ -55,9 +53,7 @@ module Nametrainer
|
|
55
53
|
# Returns a hash with the score of all persons (name => score).
|
56
54
|
def scores
|
57
55
|
all_scores = {}
|
58
|
-
self.each
|
59
|
-
all_scores[person.name] = person.score
|
60
|
-
end
|
56
|
+
self.each {|person| all_scores[person.name] = person.score }
|
61
57
|
|
62
58
|
all_scores
|
63
59
|
end
|
@@ -81,9 +77,7 @@ module Nametrainer
|
|
81
77
|
# Export all scores to file (YAML).
|
82
78
|
def export_scores
|
83
79
|
filename = File.expand_path("#{@directory}/#{SCORE_FILE}")
|
84
|
-
File.open(filename, 'w')
|
85
|
-
f.write(scores.to_yaml)
|
86
|
-
end
|
80
|
+
File.open(filename, 'w') {|f| f.write(scores.to_yaml) }
|
87
81
|
end
|
88
82
|
|
89
83
|
# Returns a random element, preferring persons with a smaller score.
|
@@ -91,6 +85,17 @@ module Nametrainer
|
|
91
85
|
self.shuffle.sort[weighted_random_index] # shuffle first, so that elements with equal scores get mixed up
|
92
86
|
end
|
93
87
|
|
88
|
+
# Returns the successor of the specified element.
|
89
|
+
# The successor of the last element is the first element.
|
90
|
+
#
|
91
|
+
# +element+ - element whose successor should be returned
|
92
|
+
def successor(element)
|
93
|
+
index = self.index(element)
|
94
|
+
return nil if index.nil?
|
95
|
+
|
96
|
+
(index == self.size - 1) ? self[0] : self[index + 1]
|
97
|
+
end
|
98
|
+
|
94
99
|
private
|
95
100
|
|
96
101
|
# Returns a random index (obsolete).
|
@@ -132,7 +137,7 @@ module Nametrainer
|
|
132
137
|
# from file name (remove extension, convert underscores).
|
133
138
|
def self.get_name(file, extensions)
|
134
139
|
name = file.dup
|
135
|
-
extensions.each {|ext| name.gsub!(/\.#{ext}
|
140
|
+
extensions.each {|ext| name.gsub!(/\.#{ext}\Z/, '') } # remove file extension
|
136
141
|
begin
|
137
142
|
info_file = "#{name}.txt"
|
138
143
|
File.read(info_file).chomp
|
data/lib/nametrainer/gui.rb
CHANGED
@@ -28,6 +28,8 @@ module Nametrainer
|
|
28
28
|
@image = Qt::Pixmap.new
|
29
29
|
@name_label = Qt::Label.new
|
30
30
|
@statistics_label = Qt::Label.new @statistics.to_s
|
31
|
+
@ordered_checkbox = Qt::CheckBox.new 'Non-random order'
|
32
|
+
@display_checkbox = Qt::CheckBox.new "Display name at once"
|
31
33
|
|
32
34
|
init_gui
|
33
35
|
show
|
@@ -93,13 +95,19 @@ module Nametrainer
|
|
93
95
|
answer_buttons.add_widget @correct
|
94
96
|
answer_buttons.add_widget @wrong
|
95
97
|
|
98
|
+
@ordered_checkbox.set_checked false
|
99
|
+
@display_checkbox.set_checked false
|
100
|
+
|
96
101
|
right = Qt::VBoxLayout.new
|
97
102
|
right.add_widget @show
|
98
103
|
right.add_layout answer_buttons
|
99
104
|
right.add_stretch 1
|
100
105
|
right.add_widget Qt::Label.new 'Statistics:'
|
101
106
|
right.add_widget @statistics_label
|
102
|
-
right.add_stretch
|
107
|
+
right.add_stretch 1
|
108
|
+
right.add_widget @ordered_checkbox
|
109
|
+
right.add_widget @display_checkbox
|
110
|
+
right.add_stretch 1
|
103
111
|
right.add_widget load_collection
|
104
112
|
right.add_widget help
|
105
113
|
right.add_widget quit
|
@@ -215,13 +223,20 @@ module Nametrainer
|
|
215
223
|
end
|
216
224
|
|
217
225
|
# Chooses and displays the next person,
|
218
|
-
# erases the displayed name and enables the <tt>Display Name</tt> button.
|
226
|
+
# erases the displayed name, and enables the <tt>Display Name</tt> button.
|
227
|
+
# "Next" means a random sample or, if the <tt>Non-random order</tt> checkbox is checked,
|
228
|
+
# the successor of the current person in the collection array.
|
219
229
|
def choose_person
|
220
230
|
@name_label.set_text ''
|
221
|
-
|
231
|
+
if @ordered_checkbox.is_checked
|
232
|
+
@person = @person.nil? ? @collection[0] : @collection.successor(@person)
|
233
|
+
else
|
234
|
+
@person = @collection.sample
|
235
|
+
end
|
222
236
|
@image.load @person.image or @image = Qt::Pixmap.new # delete image when load fails
|
223
237
|
show_image
|
224
238
|
enable_buttons
|
239
|
+
display_name if @display_checkbox.is_checked
|
225
240
|
end
|
226
241
|
|
227
242
|
# Repaints the image when the application window is resized.
|
data/lib/nametrainer/person.rb
CHANGED
@@ -12,7 +12,7 @@ module Nametrainer
|
|
12
12
|
# person1 = Person.new('Albert', nil)
|
13
13
|
# person2 = Person.new('Isaac', nil)
|
14
14
|
# person1.increase_score
|
15
|
-
# puts [person1, person2].sort.map{|p| p.name} => Isaac, Albert
|
15
|
+
# puts [person1, person2].sort.map{|p| p.name } => Isaac, Albert
|
16
16
|
class Person
|
17
17
|
|
18
18
|
attr_reader :name, :image
|
data/lib/nametrainer/version.rb
CHANGED
data/nametrainer.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
|
13
13
|
s.summary = 'nametrainer is a name learning trainer using the Qt GUI toolkit.'
|
14
14
|
s.description = s.summary + ' ' +
|
15
|
-
|
15
|
+
"It will assist you in learning people's names from a collection of images."
|
16
16
|
|
17
17
|
s.authors = ['Marcus Stollsteimer']
|
18
18
|
s.email = 'sto.mar@web.de'
|
@@ -31,11 +31,11 @@ Gem::Specification.new do |s|
|
|
31
31
|
|
32
32
|
s.files = %w{
|
33
33
|
README.md
|
34
|
-
screenshot.png
|
35
34
|
Rakefile
|
36
35
|
nametrainer.gemspec
|
36
|
+
screenshot.png
|
37
37
|
} +
|
38
|
-
Dir.glob('{bin,demo_collection,lib,
|
38
|
+
Dir.glob('{bin,demo_collection,lib,test}/**/*')
|
39
39
|
|
40
40
|
#s.add_dependency('iconv') # only for 1.8; problematic on Windows (build tools necessary)
|
41
41
|
s.add_development_dependency('rake')
|
data/screenshot.png
CHANGED
Binary file
|
data/test/test_collection.rb
CHANGED
@@ -67,6 +67,15 @@ describe Nametrainer::Collection do
|
|
67
67
|
@collection.sample.must_be_instance_of Nametrainer::Person
|
68
68
|
end
|
69
69
|
|
70
|
+
it 'can return the successor of a person' do
|
71
|
+
p1 = @collection[0]
|
72
|
+
p2 = @collection[1]
|
73
|
+
p3 = @collection[2]
|
74
|
+
@collection.successor(p1).name.must_equal p2.name
|
75
|
+
@collection.successor(p2).name.must_equal p3.name
|
76
|
+
@collection.successor(p3).name.must_equal p1.name
|
77
|
+
end
|
78
|
+
|
70
79
|
it 'can increase the score for a specified person' do
|
71
80
|
person = @collection.last
|
72
81
|
person.score.must_equal 0
|
data/test/test_person.rb
CHANGED
@@ -25,8 +25,8 @@ describe Nametrainer::Person do
|
|
25
25
|
p1 = Nametrainer::Person.new('Albert', nil)
|
26
26
|
p2 = Nametrainer::Person.new('Isaac', nil)
|
27
27
|
p1.score = 1
|
28
|
-
[p1, p2].sort.map{|p| p.name}.must_equal ['Isaac', 'Albert']
|
28
|
+
[p1, p2].sort.map{|p| p.name }.must_equal ['Isaac', 'Albert']
|
29
29
|
p2.score = 2
|
30
|
-
[p1, p2].sort.map{|p| p.name}.must_equal ['Albert', 'Isaac']
|
30
|
+
[p1, p2].sort.map{|p| p.name }.must_equal ['Albert', 'Isaac']
|
31
31
|
end
|
32
32
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nametrainer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 0
|
9
8
|
- 1
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Marcus Stollsteimer
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-04-
|
18
|
+
date: 2012-04-13 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rake
|
@@ -45,7 +45,7 @@ dependencies:
|
|
45
45
|
version: "0"
|
46
46
|
type: :development
|
47
47
|
version_requirements: *id002
|
48
|
-
description:
|
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.
|
49
49
|
email: sto.mar@web.de
|
50
50
|
executables:
|
51
51
|
- nametrainer
|
@@ -55,9 +55,9 @@ extra_rdoc_files: []
|
|
55
55
|
|
56
56
|
files:
|
57
57
|
- README.md
|
58
|
-
- screenshot.png
|
59
58
|
- Rakefile
|
60
59
|
- nametrainer.gemspec
|
60
|
+
- screenshot.png
|
61
61
|
- bin/nametrainer
|
62
62
|
- demo_collection/Erwin_Schroedinger.png
|
63
63
|
- demo_collection/Erwin_Schroedinger.txt
|