shunkuntype 1.1.1 → 1.1.2
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/.hyper_card/history/plot_modes.md +791 -0
- data/.hyper_card/history/plot_modes_251118.md +836 -0
- data/lib/shunkuntype/version.rb +1 -1
- data/lib/shunkuntype.rb +97 -2
- metadata +3 -1
data/lib/shunkuntype/version.rb
CHANGED
data/lib/shunkuntype.rb
CHANGED
|
@@ -24,7 +24,6 @@ end
|
|
|
24
24
|
class Command
|
|
25
25
|
|
|
26
26
|
def self.run(argv=[])
|
|
27
|
-
print "Shunkuntype says 'Hello world'.\n"
|
|
28
27
|
new(argv).execute
|
|
29
28
|
end
|
|
30
29
|
|
|
@@ -35,7 +34,8 @@ class Command
|
|
|
35
34
|
def execute
|
|
36
35
|
DataFiles.prepare
|
|
37
36
|
|
|
38
|
-
@
|
|
37
|
+
@mode = nil
|
|
38
|
+
|
|
39
39
|
command_parser = OptionParser.new do |opt|
|
|
40
40
|
opt.on('-v', '--version','show program Version.') { |v|
|
|
41
41
|
opt.version = Shunkuntype::VERSION
|
|
@@ -45,8 +45,103 @@ class Command
|
|
|
45
45
|
opt.on('-d', '--drill [VAL]','one minute Drill [VAL]', Integer) {|v| Training.new(v) }
|
|
46
46
|
opt.on('-h', '--help','show help message') { puts opt; exit }
|
|
47
47
|
opt.on('-l','--log','view training log') {|v| FinishCheck.new }
|
|
48
|
+
opt.on('-r MODE', '--record MODE',
|
|
49
|
+
"Show record data in readable format.\n" \
|
|
50
|
+
" MODE can be:\n" \
|
|
51
|
+
" all Show both speed and training data (default)\n" \
|
|
52
|
+
" plot Output matplotlib code for plotting\n" \
|
|
53
|
+
" speed_data Show only speed data\n" \
|
|
54
|
+
" training_data Show only training data"
|
|
55
|
+
) {|mode| @mode = mode }
|
|
56
|
+
# opt.on('-r', '--record', 'Show both speed and training data (same as -r all)') { @mode = 'all' }
|
|
48
57
|
end
|
|
49
58
|
command_parser.parse!(@argv)
|
|
59
|
+
# データ表示
|
|
60
|
+
case @mode
|
|
61
|
+
when 'plot', 'python'
|
|
62
|
+
print_python_plot_code
|
|
63
|
+
exit
|
|
64
|
+
when 'speed_data'
|
|
65
|
+
print_csv_pretty(Shunkuntype::SPEED_FILE, %w[Time Words TimeSec Score])
|
|
66
|
+
exit
|
|
67
|
+
when 'training_data'
|
|
68
|
+
print_csv_pretty(Shunkuntype::TRAINING_FILE, %w[Time Words TimeSec Score])
|
|
69
|
+
exit
|
|
70
|
+
when 'all'
|
|
71
|
+
print_pretty_data
|
|
72
|
+
exit
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
@argv << '--help' if @argv.size==0
|
|
76
|
+
command_parser.parse!(@argv)
|
|
50
77
|
exit
|
|
51
78
|
end
|
|
79
|
+
|
|
80
|
+
private
|
|
81
|
+
|
|
82
|
+
def print_pretty_data
|
|
83
|
+
print_csv_pretty(Shunkuntype::SPEED_FILE, %w[Time Words TimeSec Score])
|
|
84
|
+
print_csv_pretty(Shunkuntype::TRAINING_FILE, %w[Time Words TimeSec Score])
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def print_csv_pretty(path, headers)
|
|
88
|
+
if File.exist?(path)
|
|
89
|
+
puts "== #{File.basename(path)} =="
|
|
90
|
+
puts headers.join("\t")
|
|
91
|
+
File.foreach(path) do |line|
|
|
92
|
+
puts line.chomp.split(',').join("\t")
|
|
93
|
+
end
|
|
94
|
+
puts
|
|
95
|
+
else
|
|
96
|
+
puts "#{path} not found."
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def print_python_plot_code
|
|
101
|
+
speed_path = Shunkuntype::SPEED_FILE
|
|
102
|
+
training_path = Shunkuntype::TRAINING_FILE
|
|
103
|
+
puts "# Python (matplotlib) code for plotting your typing data"
|
|
104
|
+
puts "# Save this as plot_typing.py and run: python plot_typing.py"
|
|
105
|
+
puts <<~PYTHON
|
|
106
|
+
import matplotlib.pyplot as plt
|
|
107
|
+
import csv
|
|
108
|
+
from datetime import datetime
|
|
109
|
+
|
|
110
|
+
def load_data(path):
|
|
111
|
+
times, scores = [], []
|
|
112
|
+
try:
|
|
113
|
+
with open(path) as f:
|
|
114
|
+
reader = csv.reader(f)
|
|
115
|
+
for row in reader:
|
|
116
|
+
if len(row) < 4:
|
|
117
|
+
continue
|
|
118
|
+
# row[0]: time, row[2]: score
|
|
119
|
+
try:
|
|
120
|
+
t = datetime.strptime(row[0].split('.')[0], '%Y-%m-%d %H:%M:%S %z')
|
|
121
|
+
s = float(row[2])
|
|
122
|
+
times.append(t)
|
|
123
|
+
scores.append(s)
|
|
124
|
+
except Exception:
|
|
125
|
+
continue
|
|
126
|
+
except FileNotFoundError:
|
|
127
|
+
pass
|
|
128
|
+
return times, scores
|
|
129
|
+
|
|
130
|
+
speed_times, speed_scores = load_data("#{speed_path}")
|
|
131
|
+
train_times, train_scores = load_data("#{training_path}")
|
|
132
|
+
|
|
133
|
+
plt.figure(figsize=(10,5))
|
|
134
|
+
if speed_times:
|
|
135
|
+
plt.plot(speed_times, speed_scores, 'o-', label='Speed')
|
|
136
|
+
if train_times:
|
|
137
|
+
plt.plot(train_times, train_scores, 's-', label='Training')
|
|
138
|
+
plt.xlabel('Date')
|
|
139
|
+
plt.ylabel('Score')
|
|
140
|
+
plt.title('Typing Progress')
|
|
141
|
+
plt.legend()
|
|
142
|
+
plt.grid(True)
|
|
143
|
+
plt.tight_layout()
|
|
144
|
+
plt.show()
|
|
145
|
+
PYTHON
|
|
146
|
+
end
|
|
52
147
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: shunkuntype
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1.
|
|
4
|
+
version: 1.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Shigeto R. Nishitani
|
|
@@ -121,6 +121,8 @@ files:
|
|
|
121
121
|
- ".hyper_card/docs/shunkun_report.pdf"
|
|
122
122
|
- ".hyper_card/docs/speed.png"
|
|
123
123
|
- ".hyper_card/docs/work.png"
|
|
124
|
+
- ".hyper_card/history/plot_modes.md"
|
|
125
|
+
- ".hyper_card/history/plot_modes_251118.md"
|
|
124
126
|
- ".hyper_card/history/test_cli_bdd.md"
|
|
125
127
|
- ".hyper_card/history/test_cli_bdd_251114.md"
|
|
126
128
|
- ".hyper_card/history/tidy.md"
|