Class: MkSummary
- Inherits:
-
Object
- Object
- MkSummary
- Defined in:
- lib/shunkuntype/mk_summary.rb
Instance Method Summary collapse
-
#initialize(tmp_dir) ⇒ MkSummary
constructor
A new instance of MkSummary.
- #mk_hiki_table ⇒ Object
- #mk_html_table ⇒ Object
- #mk_member(files) ⇒ Object
- #take_scores(files, member) ⇒ Object
Constructor Details
#initialize(tmp_dir) ⇒ MkSummary
Returns a new instance of MkSummary.
2 3 4 5 6 7 |
# File 'lib/shunkuntype/mk_summary.rb', line 2 def initialize(tmp_dir) $mem_dir=File.join(tmp_dir,"mem_data") files = Dir::entries($mem_dir) member = mk_member(files) @scores = take_scores(files,member) end |
Instance Method Details
#mk_hiki_table ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/shunkuntype/mk_summary.rb', line 63 def mk_hiki_table() t= Time.now cont = "!!Shunkun typer #{t.localtime}\n" cont << "|| ||>speed[sec]||>training\n" cont << "||||init||current||total time[min]||step\n" @scores.each_pair{|key,score| cont << "||#{key}" score.each{|val| cont << sprintf("||%5.2f",val)} cont << "\n" } cont << "\n" return cont end |
#mk_html_table ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/shunkuntype/mk_summary.rb', line 48 def mk_html_table() cont = "" title = "Shunkun typer" cont << "<table border=\"1\">\n<caption>#{title}<caption>\n" cont << "<tr><th></th><th colspan=2>speed[sec]</th><th colspan=2>training</th></tr>\n" cont << "<tr><th></th><th>init</th><th>current</th><th>total time[min]</th><th>step</th></tr>\n" @scores.each_pair{|key,score| cont << "<tr><th>#{key}</th>" score.each{|val| cont << sprintf("<td>%5.2f</td>",val)} cont << "</tr>\n" } cont << "</table>\n" return cont end |
#mk_member(files) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/shunkuntype/mk_summary.rb', line 9 def mk_member(files) member = [] files.each{|file| if file.include?('training') then name=file.split('_')[0] member << name end } return member end |
#take_scores(files, member) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/shunkuntype/mk_summary.rb', line 20 def take_scores(files,member) scores = {} member.each{|name| p name speed_file="#{name}_speed_data.txt" if files.include?(speed_file) p speed_file file = File.readlines(File.join($mem_dir,speed_file)) init= (file[0]!=nil ? file[0].split(",")[2].to_f : 0.0 ) cur = (file[-1]!=nil ? file[-1].split(",")[2].to_f : 0.0 ) scores[name]=[init,cur] end training_file="#{name}_training_data.txt" if files.include?(training_file) p training_file file = File.readlines(File.join($mem_dir,training_file)) work_time = file.inject(0){|sum,line| sec=line.split(',')[3].to_i sec= (sec!=0)? sec : 60 sum + sec } step = (file[-1]!=nil ? file[-1].match(/STEP-(\d*)/)[1].to_i : 0 ) scores[name] << work_time/60 << step end } return scores end |