Class: JIJI::Output

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/jiji/output.rb

Overview

データの出力先

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(agent_name, dir, scales = []) ⇒ Output

Returns a new instance of Output.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/jiji/output.rb', line 16

def initialize( agent_name, dir, scales=[] )
  @dir = "#{dir}/#{JIJI::Util.encode(agent_name).gsub(/\//, "_")}" # 「ベースディレクトリ/エージェント名/出力名」に保存する。
  FileUtils.mkdir_p @dir

  @outs = {}
  @scales = scales

  # 既存データの読み込み
  DirLock.new( @dir ).writelock {
    Dir.glob( "#{@dir}/*" ) {|d|
      next unless File.directory? d
      next unless File.exist? "#{d}/meta.yaml"
      props = YAML.load_file "#{d}/meta.yaml"
      @outs[props[:name]] =
        create_output( d, props[:name], props[:type].to_sym, props )
    }
  }
end

Instance Attribute Details

#scalesObject

スケール



79
80
81
# File 'lib/jiji/output.rb', line 79

def scales
  @scales
end

#timeObject

現在時刻



77
78
79
# File 'lib/jiji/output.rb', line 77

def time
  @time
end

Instance Method Details

#each(&block) ⇒ Object

出力先を列挙する



65
66
67
# File 'lib/jiji/output.rb', line 65

def each( &block )
  @outs.each( &block )
end

#get(name, type = :graph, options = {}) ⇒ Object

名前に対応する出力先を得る。対応する出力先がなければ新規に作成。

name

名前(UIでの表示名)

type

種別。:event,:graphのいずれかが指定可能

option

補足情報。以下が指定可能

-*グラフの場合* –[:column_count] .. グラフのカラム数を整数値で指定する。(*必須*) –「:graph_type」 .. グラフの種類を指定する。以下の値が指定可能。—“rate” .. レート情報に重ねて表示(移動平均線やボリンジャーバンド向け)。グラフは、ローソク足描画領域に描画される。—“zero_base” .. 0を中心線とした線グラフ(RCIやMACD向け)。グラフは、グラフ描画領域に描画される。—“line” .. 線グラフとして描画する。(デフォルト)。グラフは、グラフ描画領域に描画される。–「:colors」 .. グラフの色を「#FFFFFF」形式の文字列の配列で指定する。指定を省略した場合「0x557777」で描画される。

return

出力先



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/jiji/output.rb', line 49

def get( name, type=:graph, options={} )
  raise "illegal Name. name=#{name}" if name =~ /[\x00-\x1F\x7F\\\/\r\n\t]/
  return @outs[name] if @outs.key? name
  DirLock.new( @dir ).writelock {
    sub_dir = "#{@dir}/#{JIJI::Util.encode(name).gsub(/\//, "_")}"
    FileUtils.mkdir_p sub_dir
    options[:type] = type.to_s
    options[:name] = name
    @outs[name] = create_output( sub_dir, name, type, options )
    @outs[name].time = time
    @outs[name].save
  }
  @outs[name]
end