class MkPlots

Public Class Methods

new(tmp_dir,opts={}) click to toggle source
# File lib/shunkuntype/plot_data.rb, line 82
def initialize(tmp_dir,opts={})
  @source_dir=File.join(tmp_dir,'mem_data')
  @mem_names=[]
  @opts = opts
  mk_mem_names()
  work_all()
  speed_all()
end

Public Instance Methods

mk_mem_names() click to toggle source
# File lib/shunkuntype/plot_data.rb, line 117
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={}) click to toggle source
# File lib/shunkuntype/plot_data.rb, line 139
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 "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() click to toggle source
# File lib/shunkuntype/plot_data.rb, line 99
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)
end
speed_view(name) click to toggle source
# File lib/shunkuntype/plot_data.rb, line 107
def speed_view(name)
  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() click to toggle source
# File lib/shunkuntype/plot_data.rb, line 91
def work_all
  all_data= @mem_names.inject([]){|all,name|
    all << work_view(name)
  }
  text="Work minutes [min]"
  plot(all_data,text)
end
work_view(name) click to toggle source
# File lib/shunkuntype/plot_data.rb, line 125
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