Class: Shunkuntype::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/shunkuntype.rb,
lib/shunkuntype/options.rb

Defined Under Namespace

Modules: Options

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv = []) ⇒ Command

Returns a new instance of Command.



20
21
22
# File 'lib/shunkuntype.rb', line 20

def initialize(argv=[])
  @argv = argv
end

Class Method Details

.run(argv = []) ⇒ Object



15
16
17
18
# File 'lib/shunkuntype.rb', line 15

def self.run(argv=[])
  print "Shunkuntype says 'Hello world'.\n"
  new(argv).execute
end

Instance Method Details

#data_viewing(form) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/shunkuntype.rb', line 52

def data_viewing(form)
  server_info=File.readlines(Shunkuntype::SERVER_FILE)
  p server_directory=server_info[0].chomp
  Dir.mktmpdir('shunkun'){|tmp_dir|
    FileUtils.mkdir_p(File.join(tmp_dir,'mem_data'))
    system "scp -r #{server_directory}/* #{tmp_dir}/mem_data"
    # write data to file
    table = MkSummary.new(tmp_dir)
    MkPlots.new(tmp_dir)
    p form ||= :html
    case form
    when :html then
      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")
      }
    when :hiki then
      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")
      }
    else

    end
  }
end

#executeObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/shunkuntype.rb', line 24

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('--review [TAG]',[:html,:hiki],'Review training, TAGs=html or hiki'){|v| data_viewing(v)}
  end
  command_parser.parse!(@argv)
  exit
end

#report_submitObject



44
45
46
47
48
49
50
# File 'lib/shunkuntype.rb', line 44

def report_submit
  server_info=File.readlines(Shunkuntype::SERVER_FILE)
  p server_directory=server_info[0].chomp
  p user_name=server_info[0].split('@')[0]
  system "scp #{Shunkuntype::TRAIN_FILE} #{server_directory}/#{user_name}_training_data.txt"
  system "scp #{Shunkuntype::SPEED_FILE} #{server_directory}/#{user_name}_speed_data.txt"
end