Class: MkPlots

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

Instance Method Summary collapse

Constructor Details

#initialize(tmp_dir, opts = {}) ⇒ MkPlots

Returns a new instance of MkPlots.



83
84
85
86
87
88
89
90
# File 'lib/shunkuntype/plot_data.rb', line 83

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

Instance Method Details

#mk_mem_namesObject



118
119
120
121
122
123
124
# File 'lib/shunkuntype/plot_data.rb', line 118

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



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
165
166
# File 'lib/shunkuntype/plot_data.rb', line 140

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_allObject



100
101
102
103
104
105
106
# File 'lib/shunkuntype/plot_data.rb', line 100

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) ⇒ Object



108
109
110
111
112
113
114
115
116
# File 'lib/shunkuntype/plot_data.rb', line 108

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_allObject



92
93
94
95
96
97
98
# File 'lib/shunkuntype/plot_data.rb', line 92

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) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/shunkuntype/plot_data.rb', line 126

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