Class: MkPlots
- Inherits:
-
Object
- Object
- MkPlots
- Defined in:
- lib/shunkuntype/plot_data.rb
Instance Method Summary collapse
-
#initialize(tmp_dir, opts = {}) ⇒ MkPlots
constructor
A new instance of MkPlots.
- #mk_mem_names ⇒ Object
- #plot(data, text0, opts = {}) ⇒ Object
- #speed_all ⇒ Object
- #speed_view(name) ⇒ Object
- #work_all ⇒ Object
- #work_view(name) ⇒ Object
Constructor Details
#initialize(tmp_dir, opts = {}) ⇒ MkPlots
Returns a new instance of MkPlots.
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/shunkuntype/plot_data.rb', line 79 def initialize(tmp_dir,opts={}) @source_dir=File.join(tmp_dir,'mem_data') @mem_names=[] @opts = opts mk_mem_names() work_all() # FileUtils.mv('res.png', './work.png') speed_all() # FileUtils.mv('res.png', './speed.png') end |
Instance Method Details
#mk_mem_names ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/shunkuntype/plot_data.rb', line 116 def mk_mem_names names = Dir.entries(@source_dir) names.each{|name| title = name.split('_')[0] @mem_names << title if (!@mem_names.include?(title) and title.match(/\w/)) } end |
#plot(data, text0, opts = {}) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/shunkuntype/plot_data.rb', line 138 def plot(data,text0,opts={}) Gnuplot.open do |gp| Gnuplot::Plot.new( gp ) do |plot| plot.title "Elapsed time vs #{text0}" plot.ylabel text0 plot.xlabel "Elapsed time[days]" plot.xtics "0 7" plot.xrange "[-49:1]" if true==opts.has_key?(:png) then plot.term "pngcairo enhanced size 480,360" plot.output "res.png" end plot.data = [] data.each{|ele| plot.data << Gnuplot::DataSet.new( ele.to_gnuplot ) do |ds| ds.with = "line" if ""==ele.title then ds.notitle else ds.title=ele.title end end } end end end |
#speed_all ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'lib/shunkuntype/plot_data.rb', line 97 def speed_all mk_mem_names all_data= @mem_names.inject([]){|all,name| all << speed_view(name) } text="Typing speed [sec/20 words]" plot(all_data,text) # plot(all_data,text,opts={:png=>true}) end |
#speed_view(name) ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'lib/shunkuntype/plot_data.rb', line 106 def speed_view(name) p name1 = "#{@source_dir}/#{name}_speed_data.txt" data0 = PlotData.new(name1, 0, 2, name) start=Time.parse(Time.now.to_s) x_func = proc{|x| ((Time.parse(x)-start)/3600/24) } y_func = proc{|y| y } data0.mk_plot_data(x_func,y_func) return data0 end |
#work_all ⇒ Object
90 91 92 93 94 95 |
# File 'lib/shunkuntype/plot_data.rb', line 90 def work_all all_data= @mem_names.inject([]){|all,name| all << work_view(name) } text="Work minutes [min]" plot(all_data,text) # plot(all_data,text,opts={:png=>true}) end |
#work_view(name) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/shunkuntype/plot_data.rb', line 124 def work_view(name) p name0 = "#{@source_dir}/#{name}_training_data.txt" p name1 = "#{@source_dir}/#{name}_speed_data.txt" data0 = PlotData.new(name0,0,3,name) data0.add_general_data(name1, 0, 2) start=Time.parse(Time.now.to_s) x_func = proc{|x| ((Time.parse(x)-start)/3600/24) } y_func = proc{|y| y.to_f/60.0 } data0.mk_plot_data(x_func,y_func) data0.sort data0.sum_data return data0 end |