Class: Shunkuntype::Command
- Inherits:
-
Object
- Object
- Shunkuntype::Command
- Defined in:
- lib/shunkuntype.rb,
lib/shunkuntype/options.rb
Defined Under Namespace
Modules: Options
Class Method Summary collapse
Instance Method Summary collapse
- #data_viewing(file) ⇒ Object
- #execute ⇒ Object
- #file_merge(ext_name) ⇒ Object
-
#initialize(argv = []) ⇒ Command
constructor
A new instance of Command.
- #report_submit ⇒ Object
- #reset_data ⇒ Object
Constructor Details
#initialize(argv = []) ⇒ Command
Returns a new instance of Command.
21 22 23 |
# File 'lib/shunkuntype.rb', line 21 def initialize(argv=[]) @argv = argv end |
Class Method Details
.run(argv = []) ⇒ Object
16 17 18 19 |
# File 'lib/shunkuntype.rb', line 16 def self.run(argv=[]) print "Shunkuntype says 'Hello world'.\n" new(argv).execute end |
Instance Method Details
#data_viewing(file) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/shunkuntype.rb', line 97 def data_viewing(file) # opts for MkPlots could be described in file # Not coded yet at all!!! if file==nil then opts = {} end server_info=File.readlines(Shunkuntype::SERVER_FILE) p server_directory=server_info[0].chomp Dir.mktmpdir('shunkun'){|tmp_dir| # ['tmp_dir'].each{|tmp_dir| p tmp_dir FileUtils.mkdir_p(File.join(tmp_dir,'mem_data')) system "scp -r #{server_directory}/* #{tmp_dir}/mem_data" table = MkSummary.new(tmp_dir) # read data from files MkPlots.new(tmp_dir,opts) File.open('./tmp.html','a'){|f| f.write("<html>\n") f.write(table.mk_html_table()) f.write("<p><img src=\"./work.png\" /></p>") f.write("<p><img src=\"./speed.png\" /></p>") f.write("</html>\n") } File.open('./tmp.hiki','a'){|f| f.write(table.mk_hiki_table()) f.write('||{{attach_view(work.png)}}') f.write('||{{attach_view(speed.png)}}') f.write("\n") } } end |
#execute ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/shunkuntype.rb', line 25 def execute DataFiles.prepare @argv << '--help' if @argv.size==0 command_parser = OptionParser.new do |opt| opt.on('-v', '--version','show program Version.') { |v| opt.version = Shunkuntype::VERSION puts opt.ver } opt.on('-c', '--check','Check speed') {|v| SpeedCheck.new } opt.on('-d', '--drill [VAL]','one minute Drill [VAL]', Integer) {|v| Training.new(v) } opt.on('-h', '--history','view training History') {|v| FinishCheck.new } opt.on('-p', '--plot','Plot personal data') { |v| PlotPersonalData.new } opt.on('-s', '--submit','Submit data to dmz0') { |v| report_submit()} opt.on('--reset','reset training data') { |v| reset_data()} opt.on('--review [FILE]','Review training, TAGs=html or hiki'){|v| data_viewing(v)} end command_parser.parse!(@argv) exit end |
#file_merge(ext_name) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/shunkuntype.rb', line 79 def file_merge(ext_name) file_name=ext_name file_current = File.readlines(file_name) tmp_file = File.open("./tmp_data.txt",'w') sta, out, stderror = systemu "scp #{@server_directory}/#{@user_name}_#{ext_name} ." p stderror unless stderror.include?(" No such file or directory") then file_server = File.readlines("#{@user_name}_#{ext_name}") tmp_file.print data_merge(file_current,file_server) else p " No such file or directory in server.\n" tmp_file.print file_current.join end tmp_file.close system "cat tmp_data.txt" system "scp tmp_data.txt #{@server_directory}/#{@user_name}_#{ext_name}" end |
#report_submit ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/shunkuntype.rb', line 61 def report_submit p 'report submission' p data_dir = File.join(ENV['HOME'], '.shunkuntype') FileUtils.cd(data_dir) unless File.exists?(Shunkuntype::SERVER_FILE) print "Input server_directory?:" p tmp = gets File.open(Shunkuntype::SERVER_FILE,'w'){|f| f.print(tmp) } end server_info=File.readlines(Shunkuntype::SERVER_FILE) p @server_directory=server_info[0].chomp p @user_name=server_info[0].split('@')[0] ['training_data.txt','speed_data.txt'].each{|ext| file_merge(ext) system "scp tmp_data.txt #{ext}" } end |
#reset_data ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/shunkuntype.rb', line 46 def reset_data data_dir = File.join(ENV['HOME'], '.shunkuntype') FileUtils.cd(data_dir) begin FileUtils.mkdir('old_data',:verbose => true) rescue Errno::EEXIST print "Directory 'old_data' exists at #{data_dir}.\n\n" end time=Time.now.strftime("%Y%m%d%H%M%S") ['speed_data','training_data'].each{|file| target = File.join(data_dir,'old_data',"#{file}_#{time}.txt") FileUtils.mv(file+'.txt',target,:verbose=>true) } end |