cw 0.2.4 → 0.3.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.
- checksums.yaml +4 -4
- data/.cw_config +18 -0
- data/.gitignore +10 -1
- data/LICENSE +2 -1
- data/README.md +212 -96
- data/Rakefile +15 -2
- data/VERSION +1 -1
- data/Vagrantfile +45 -0
- data/cw.gemspec +6 -1
- data/data/text/book_to_read.txt +4 -0
- data/data/text/english.txt +10000 -0
- data/example.rb +172 -106
- data/lib/cw.rb +10 -126
- data/lib/cw/alphabet.rb +53 -46
- data/lib/cw/audio_player.rb +83 -72
- data/lib/cw/book.rb +160 -185
- data/lib/cw/book_details.rb +38 -49
- data/lib/cw/cl.rb +101 -95
- data/lib/cw/common_words.rb +76 -0
- data/lib/cw/config.rb +50 -0
- data/lib/cw/current_word.rb +23 -24
- data/lib/cw/cw_dsl.rb +264 -131
- data/lib/cw/cw_encoding.rb +63 -69
- data/lib/cw/cw_stream.rb +86 -82
- data/lib/cw/cw_threads.rb +132 -22
- data/lib/cw/element.rb +60 -54
- data/lib/cw/file_details.rb +26 -11
- data/lib/cw/key_input.rb +53 -35
- data/lib/cw/numbers.rb +26 -19
- data/lib/cw/os.rb +13 -0
- data/lib/cw/play.rb +92 -0
- data/lib/cw/print.rb +102 -100
- data/lib/cw/process.rb +3 -0
- data/lib/cw/progress.rb +20 -17
- data/lib/cw/randomize.rb +56 -52
- data/lib/cw/repeat_word.rb +59 -66
- data/lib/cw/reveal.rb +32 -31
- data/lib/cw/rss.rb +52 -48
- data/lib/cw/sentence.rb +83 -76
- data/lib/cw/speak.rb +8 -4
- data/lib/cw/spoken.rb +8 -4
- data/lib/cw/str.rb +62 -30
- data/lib/cw/test_letters.rb +20 -28
- data/lib/cw/test_words.rb +25 -31
- data/lib/cw/tester.rb +219 -226
- data/lib/cw/text_helpers.rb +19 -15
- data/lib/cw/timing.rb +63 -67
- data/lib/cw/tone_generator.rb +176 -153
- data/lib/cw/tone_helpers.rb +15 -23
- data/lib/cw/voice.rb +12 -8
- data/lib/cw/words.rb +136 -106
- data/run_script_tests.rb +165 -0
- data/test/my_words.txt +1 -0
- data/test/test_common_words.rb +71 -0
- data/test/test_config.rb +98 -0
- data/test/test_current_word.rb +62 -0
- data/test/test_cw.rb +87 -120
- data/test/test_cw_threads.rb +123 -0
- data/test/test_filtering.rb +439 -0
- data/test/test_params.rb +28 -0
- data/test/test_play.rb +51 -0
- data/test/test_stream.rb +83 -83
- data/test/test_tester.rb +9 -27
- data/test/test_timing.rb +212 -0
- metadata +94 -12
- data/lib/cw/config_file.rb +0 -69
- data/lib/cw/monitor_keys.rb +0 -37
- data/lib/cw/params.rb +0 -104
data/lib/cw/tone_helpers.rb
CHANGED
@@ -1,33 +1,25 @@
|
|
1
1
|
# Module ToneHelpers provides helper methods for ToneGenerator
|
2
2
|
|
3
|
-
module
|
3
|
+
module CWG
|
4
4
|
|
5
|
-
|
6
|
-
HERE = File.dirname(__FILE__) + '/../../'
|
7
|
-
DOT_FILENAME = HERE + "audio/dot.wav"
|
8
|
-
DASH_FILENAME = HERE + "audio/dash.wav"
|
9
|
-
SPACE_FILENAME = HERE + "audio/space.wav"
|
10
|
-
E_SPACE_FILENAME = HERE + "audio/e_space.wav"
|
5
|
+
module ToneHelpers
|
11
6
|
|
12
|
-
|
13
|
-
def play_filename
|
14
|
-
HERE + "audio/#{Params.audio_filename}"
|
15
|
-
end
|
7
|
+
TWO_PI = 2 * Math::PI
|
16
8
|
|
17
|
-
|
18
|
-
|
19
|
-
|
9
|
+
def convert_words wrds
|
10
|
+
wrds.to_array.collect{ |wrd| wrd.delete("\n")}
|
11
|
+
end
|
20
12
|
|
21
|
-
|
22
|
-
|
23
|
-
|
13
|
+
def generate_space number_of_samples
|
14
|
+
[].fill(0.0, 0, number_of_samples)
|
15
|
+
end
|
24
16
|
|
25
|
-
|
26
|
-
|
27
|
-
|
17
|
+
def space_sample? ele
|
18
|
+
ele == :space || ele == :e_space
|
19
|
+
end
|
28
20
|
|
29
|
-
|
30
|
-
|
21
|
+
def last_element? idx, chr
|
22
|
+
idx == chr.size - 1
|
23
|
+
end
|
31
24
|
end
|
32
|
-
|
33
25
|
end
|
data/lib/cw/voice.rb
CHANGED
@@ -1,16 +1,20 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
module CWG
|
4
4
|
|
5
|
-
class
|
5
|
+
#class Speak speaks with a voice
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
class Voice
|
8
|
+
|
9
|
+
def initialize(options = {})
|
10
|
+
@options = options
|
11
|
+
end
|
12
|
+
|
13
|
+
def say words, rate = 300, voice = 'bruce'
|
14
|
+
system("say #{words} -ospoken.wave -r#{rate} -v#{voice}")
|
15
|
+
system("afplay spoken.wave")
|
16
|
+
end
|
10
17
|
|
11
|
-
def say words, rate = 300, voice = 'bruce'
|
12
|
-
system("say #{words} -ospoken.wave -r#{rate} -v#{voice}")
|
13
|
-
system("afplay spoken.wave")
|
14
18
|
end
|
15
19
|
|
16
20
|
end
|
data/lib/cw/words.rb
CHANGED
@@ -1,149 +1,179 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
module CWG
|
4
4
|
|
5
|
-
class Words
|
5
|
+
#class Words deals with words
|
6
6
|
|
7
|
-
|
7
|
+
class Words
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
include TextHelpers
|
10
|
+
|
11
|
+
def load args
|
12
|
+
@words = CommonWords.new.read(args)
|
12
13
|
end
|
13
|
-
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
def load_text(filename)
|
16
|
+
File.open(filename, 'r') do |file|
|
17
|
+
@words = file.read.split
|
18
|
+
end
|
19
19
|
end
|
20
|
-
@words = temp
|
21
|
-
end
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
def double_words
|
22
|
+
@words.collect! {|wrd| [wrd] * 2}
|
23
|
+
@words.flatten!
|
24
|
+
end
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
def repeat multiplier
|
27
|
+
@words *= multiplier + 1
|
28
|
+
end
|
30
29
|
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
def shuffle
|
31
|
+
@words.shuffle!
|
32
|
+
end
|
34
33
|
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
def to_array
|
35
|
+
@words
|
36
|
+
end
|
38
37
|
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
def all
|
39
|
+
@words
|
40
|
+
end
|
42
41
|
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
def to_s
|
43
|
+
@words.join(' ')
|
44
|
+
end
|
46
45
|
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
def add words
|
47
|
+
@words = words
|
48
|
+
end
|
50
49
|
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
def exist?
|
51
|
+
@words
|
52
|
+
end
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
def word_size(size)
|
55
|
+
@words = @words.select{|wrd| wrd.size == size}
|
56
|
+
end
|
58
57
|
|
59
|
-
|
60
|
-
|
61
|
-
|
58
|
+
def beginning_with_letter(letr)
|
59
|
+
@words.select{|wrd| wrd.start_with?(letr)}
|
60
|
+
end
|
62
61
|
|
63
|
-
|
64
|
-
|
65
|
-
|
62
|
+
def ending_with_letter(letr)
|
63
|
+
@words.select{|wrd| wrd.end_with?(letr)}
|
64
|
+
end
|
66
65
|
|
67
|
-
|
68
|
-
|
69
|
-
|
66
|
+
def beginning_with
|
67
|
+
letter_filter(:beginning_with, Cfg.config["begin"])
|
68
|
+
end
|
70
69
|
|
71
|
-
|
72
|
-
|
73
|
-
|
70
|
+
def ending_with
|
71
|
+
letter_filter(:ending_with, Cfg.config["end"])
|
72
|
+
end
|
74
73
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
74
|
+
def including
|
75
|
+
letter_filter(:including, Cfg.config["including"])
|
76
|
+
end
|
77
|
+
|
78
|
+
def letter_filter(option,letters)
|
79
|
+
method_name = option.to_s + "_letter"
|
80
|
+
@words = letters.flatten.collect do |letr|
|
81
|
+
if letr.class == Range
|
82
|
+
letr.collect do |let|
|
83
|
+
self.send(method_name, let)
|
84
|
+
end
|
83
85
|
else
|
84
|
-
|
85
|
-
|
86
|
+
self.send(method_name, letr)
|
87
|
+
end
|
88
|
+
end.flatten
|
89
|
+
end
|
90
|
+
|
91
|
+
def count word_count
|
92
|
+
@words = @words.take(word_count)
|
93
|
+
end
|
94
|
+
|
95
|
+
def including_letter(letr)
|
96
|
+
@words.select{|wrd| wrd.include?(letr)}
|
97
|
+
end
|
98
|
+
|
99
|
+
def containing
|
100
|
+
letters = Cfg.config["containing"]
|
101
|
+
letters.flatten.collect do |letr|
|
102
|
+
if letr.class == Range
|
103
|
+
letters = letr.collect { |let| let }
|
86
104
|
end
|
87
105
|
end
|
88
|
-
|
89
|
-
|
106
|
+
|
107
|
+
lets = letters.flatten.join('').split("")
|
108
|
+
found, temp, @words = false, @words, []
|
109
|
+
temp.each do |wrd|
|
110
|
+
wrd_lets = wrd.split("")
|
111
|
+
wrd_lets.each do |wrd_let|
|
112
|
+
if lets.include?(wrd_let)
|
113
|
+
found = true
|
114
|
+
else
|
115
|
+
found = false
|
116
|
+
break
|
117
|
+
end
|
118
|
+
end
|
119
|
+
if found
|
120
|
+
@words.push wrd
|
121
|
+
end
|
90
122
|
end
|
123
|
+
@words
|
91
124
|
end
|
92
|
-
@words
|
93
|
-
end
|
94
125
|
|
95
|
-
|
96
|
-
|
97
|
-
|
126
|
+
def no_longer_than(max)
|
127
|
+
@words = @words.select{|wrd| wrd.size <= max}
|
128
|
+
end
|
98
129
|
|
99
|
-
|
100
|
-
|
101
|
-
|
130
|
+
def no_shorter_than(min)
|
131
|
+
@words = @words.select{|wrd| wrd.size >= min}
|
132
|
+
end
|
102
133
|
|
103
|
-
|
104
|
-
|
105
|
-
|
134
|
+
def assign(words)
|
135
|
+
words.kind_of?(String) ?
|
136
|
+
@words = words.split(/\s+/) :
|
137
|
+
@words = words
|
138
|
+
end
|
106
139
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
end
|
140
|
+
def collect_words
|
141
|
+
@words.each{ |word| ' ' + word }.
|
142
|
+
collect{|wrd| wrd}.join(' ')
|
143
|
+
end
|
112
144
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
end
|
145
|
+
def reverse
|
146
|
+
@words.reverse!
|
147
|
+
end
|
117
148
|
|
118
|
-
|
119
|
-
|
120
|
-
|
149
|
+
def letters_numbers
|
150
|
+
letter_group.push( * number_group)
|
151
|
+
end
|
121
152
|
|
122
|
-
|
123
|
-
|
124
|
-
|
153
|
+
def random_letters(options = {})
|
154
|
+
@words = Randomize.new(options, letter_group).generate
|
155
|
+
end
|
125
156
|
|
126
|
-
|
127
|
-
|
128
|
-
|
157
|
+
def random_numbers(options = {})
|
158
|
+
@words = Randomize.new(options, number_group).generate
|
159
|
+
end
|
129
160
|
|
130
|
-
|
131
|
-
|
132
|
-
|
161
|
+
def random_letters_numbers(options = {})
|
162
|
+
@words = Randomize.new(options, letters_numbers.shuffle).generate
|
163
|
+
end
|
133
164
|
|
134
|
-
|
135
|
-
|
136
|
-
|
165
|
+
def alphabet(options = {reverse: nil})
|
166
|
+
@words = [Alphabet.new(options).generate]
|
167
|
+
end
|
137
168
|
|
138
|
-
|
139
|
-
|
140
|
-
|
169
|
+
def numbers(options = {reverse: nil})
|
170
|
+
@words = [Numbers.new(options).generate]
|
171
|
+
end
|
141
172
|
|
142
|
-
|
143
|
-
@words = [Numbers.new(options).generate]
|
144
|
-
end
|
173
|
+
def numbers_spoken()
|
145
174
|
|
146
|
-
|
175
|
+
end
|
147
176
|
|
148
177
|
end
|
178
|
+
|
149
179
|
end
|
data/run_script_tests.rb
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
require 'sequel'
|
2
|
+
|
3
|
+
DEBUG = false
|
4
|
+
|
5
|
+
class RunScriptTests
|
6
|
+
NO_RUN = DEBUG ? false : false
|
7
|
+
TEST_ON_MEMORY_DATABASE = DEBUG ? true : false
|
8
|
+
NO_RSS_FEED = DEBUG ? true : false
|
9
|
+
PATH_TO_CW_SCRIPTS = '/Users/martyn/jekyll/documentation-theme-jekyll/cw_scripts'
|
10
|
+
ROOT = '/Users/martyn/cw/cw_clone'
|
11
|
+
PROGRESS_FILE = "data/text/progress.txt"
|
12
|
+
DB = Sequel.sqlite(File.join(ROOT, 'test.sqlite')) unless(TEST_ON_MEMORY_DATABASE)
|
13
|
+
DB = Sequel.sqlite if(TEST_ON_MEMORY_DATABASE)
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
create_tables if(TEST_ON_MEMORY_DATABASE)
|
17
|
+
populate_cw_scripts if(TEST_ON_MEMORY_DATABASE)
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_tables
|
21
|
+
DB.create_table :scripts do
|
22
|
+
primary_key :id
|
23
|
+
String :script, :null => false
|
24
|
+
String :path, :null => false
|
25
|
+
end
|
26
|
+
|
27
|
+
DB.create_table :test_runs do
|
28
|
+
primary_key :id
|
29
|
+
DateTime :date_time
|
30
|
+
Fixnum :total_secs
|
31
|
+
String :result
|
32
|
+
end
|
33
|
+
|
34
|
+
DB.create_table :tests do
|
35
|
+
primary_key :id
|
36
|
+
Fixnum :test_run_id, :null => false
|
37
|
+
Fixnum :script_id, :null => false
|
38
|
+
Fixnum :wpm, :null => false
|
39
|
+
Fixnum :ewpm, :null => false
|
40
|
+
String :duration
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def populate_cw_scripts
|
45
|
+
scripts = (Dir.glob(PATH_TO_CW_SCRIPTS + '/*.rb'))
|
46
|
+
scripts.each do |script|
|
47
|
+
script_name = File.basename(script,'.rb')
|
48
|
+
# populate the table
|
49
|
+
DB[:scripts].insert(:script => "#{script_name}",
|
50
|
+
:path => PATH_TO_CW_SCRIPTS)
|
51
|
+
end
|
52
|
+
DB[:scripts].insert(:script => "example",
|
53
|
+
:path => ROOT)
|
54
|
+
end
|
55
|
+
|
56
|
+
def reset_sentence_count
|
57
|
+
File.open(PROGRESS_FILE,'w') do |f|
|
58
|
+
f.puts "0"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_current_test_runs(test_run_id)
|
63
|
+
DB[:test_runs].where(:id => test_run_id)
|
64
|
+
end
|
65
|
+
|
66
|
+
def update_current_test_run(test_run_id,total_secs)
|
67
|
+
current = get_current_test_runs(test_run_id)
|
68
|
+
current.update(:total_secs=> total_secs, :result=>"pass")
|
69
|
+
end
|
70
|
+
|
71
|
+
def exec_command line
|
72
|
+
system(line)
|
73
|
+
end
|
74
|
+
|
75
|
+
def set_test_environment
|
76
|
+
"CW_ENV=test "
|
77
|
+
end
|
78
|
+
|
79
|
+
def run_test filename, environment = nil
|
80
|
+
environment == :test ?
|
81
|
+
env = set_test_environment : env = ''
|
82
|
+
exec_command(env + "bundle exec ruby #{filename}")
|
83
|
+
end
|
84
|
+
|
85
|
+
def execute_test_env filename
|
86
|
+
if NO_RUN
|
87
|
+
sleep 0.05
|
88
|
+
else
|
89
|
+
run_test(filename, :test)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class Timer
|
94
|
+
def initialize
|
95
|
+
@finish_time = @total_start_time = Time.now
|
96
|
+
end
|
97
|
+
|
98
|
+
def start
|
99
|
+
@start_time = Time.now
|
100
|
+
end
|
101
|
+
def finish
|
102
|
+
@finish_time = Time.now
|
103
|
+
end
|
104
|
+
def duration
|
105
|
+
@finish_time - @start_time
|
106
|
+
end
|
107
|
+
def total_secs
|
108
|
+
@finish_time - @total_start_time
|
109
|
+
end
|
110
|
+
def running_time
|
111
|
+
Time.now - @total_start_time
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_runs_insert_dateTime
|
116
|
+
DB[:test_runs].insert(:date_time => Time.now,
|
117
|
+
:total_secs => 0,
|
118
|
+
:result => "fail")
|
119
|
+
end
|
120
|
+
|
121
|
+
def reset_sentence_count_maybe script_name
|
122
|
+
if script_name.include?("book_reading")
|
123
|
+
reset_sentence_count
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def print_last_five_results
|
128
|
+
DB[:test_runs].each do |test_run|
|
129
|
+
if(test_run[:id] > (@test_run_id - 5))
|
130
|
+
puts test_run[:date_time].to_s + ': ' +
|
131
|
+
"Total secs: " + test_run[:total_secs].to_s
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def run
|
137
|
+
timer = Timer.new
|
138
|
+
@test_run_id = test_runs_insert_dateTime
|
139
|
+
DB[:scripts].each do |test|
|
140
|
+
filename = File.join test[:path], test[:script] + '.rb'
|
141
|
+
puts "[#{timer.running_time.to_i}] Running: #{test[:script]}"
|
142
|
+
reset_sentence_count_maybe test[:script]
|
143
|
+
timer.start
|
144
|
+
# next unless test[:script].include? ("example")
|
145
|
+
execute_test_env filename
|
146
|
+
timer.finish
|
147
|
+
reset_sentence_count_maybe test[:script]
|
148
|
+
DB[:tests].insert(:script_id => test[:id],
|
149
|
+
:test_run_id => @test_run_id,
|
150
|
+
:wpm => 60,
|
151
|
+
:ewpm => 60,
|
152
|
+
:duration => "#{timer.duration}")
|
153
|
+
DB[:tests].all
|
154
|
+
end
|
155
|
+
update_current_test_run(@test_run_id,timer.total_secs)
|
156
|
+
run_test(PATH_TO_CW_SCRIPTS + '/rss_feed.rb') unless(NO_RSS_FEED)
|
157
|
+
print_last_five_results
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
test_scripts = RunScriptTests.new
|
162
|
+
1.times do |loop_count|
|
163
|
+
test_scripts.run
|
164
|
+
break unless(DEBUG)
|
165
|
+
end
|