unageanu-jiji 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +9 -1
- data/html/js/result-page.js +2 -2
- data/lib/jiji/process.rb +26 -17
- data/lib/jiji/registry.rb +2 -3
- data/lib/jiji/server.rb +1 -2
- data/test/test_Process.rb +177 -18
- metadata +2 -2
data/ChangeLog
CHANGED
data/html/js/result-page.js
CHANGED
@@ -205,8 +205,8 @@ fx.ui.pages.TradeResultPage.prototype = {
|
|
205
205
|
endDate = now.getTime()/1000;
|
206
206
|
|
207
207
|
// フィールドにも設定しておく
|
208
|
-
document.getElementById("subpage-trade_range-year").value =
|
209
|
-
document.getElementById("subpage-trade_range-month").value =
|
208
|
+
document.getElementById("subpage-trade_range-year").value = start.getFullYear();
|
209
|
+
document.getElementById("subpage-trade_range-month").value = start.getMonth()+1;
|
210
210
|
document.getElementById("subpage-trade_range-day").value = start.getDate();
|
211
211
|
document.getElementById("subpage-trade_range-end-year").value = now.getFullYear();
|
212
212
|
document.getElementById("subpage-trade_range-end-month").value = now.getMonth()+1;
|
data/lib/jiji/process.rb
CHANGED
@@ -15,9 +15,10 @@ module JIJI
|
|
15
15
|
|
16
16
|
# コンストラクタ
|
17
17
|
# 再起動後の復元の場合、プロパティを指定しないこと。この場合設定ファイルからロードされる。
|
18
|
-
def initialize( id, process_dir, agent_manager, props=nil, registry=nil,
|
19
|
-
|
18
|
+
def initialize( id, process_dir, agent_manager, logger, props=nil, registry=nil, rmt=false )
|
19
|
+
|
20
20
|
is_recreate = props == nil
|
21
|
+
@logger = logger
|
21
22
|
@registry = registry
|
22
23
|
@id = id
|
23
24
|
@agent_manager = agent_manager
|
@@ -43,20 +44,20 @@ module JIJI
|
|
43
44
|
}
|
44
45
|
@props["agents"] = [] unless @props.key? "agents"
|
45
46
|
end
|
46
|
-
|
47
|
-
#
|
48
|
-
#
|
47
|
+
|
48
|
+
# RMTまたは新規作成の場合はエージェントをロード
|
49
|
+
# 再起動後の再作成時は、アウトプットのみ作成。
|
49
50
|
@outputs = {}
|
50
|
-
if !is_recreate
|
51
|
-
load_agent(
|
51
|
+
if rmt || !is_recreate
|
52
|
+
load_agent(rmt) # リアル取引の再起動時は発生したエラーを無視する
|
52
53
|
else
|
53
54
|
if @props && @props["agents"]
|
54
55
|
@props["agents"].each {|v|
|
55
|
-
@outputs[v["id"]] = @registry.output( @id, v["
|
56
|
+
@outputs[v["id"]] = @registry.output( @id, v["name"] )
|
56
57
|
}
|
57
58
|
end
|
58
59
|
end
|
59
|
-
|
60
|
+
|
60
61
|
# 取引の有効状態を更新
|
61
62
|
@agent_manager.operator.trade_enable =
|
62
63
|
@props["trade_enable"] ? true : false
|
@@ -113,7 +114,6 @@ module JIJI
|
|
113
114
|
end
|
114
115
|
|
115
116
|
def []=(k,v)
|
116
|
-
@props[k] = v
|
117
117
|
if ( k == "agents" )
|
118
118
|
# エージェントの設定が更新された
|
119
119
|
# 削除対象を特定するため、登録済みエージェントのIDのセットを作成
|
@@ -124,13 +124,16 @@ module JIJI
|
|
124
124
|
set.delete item["id"]
|
125
125
|
}
|
126
126
|
# Mapに含まれていないエージェントは削除
|
127
|
-
set.each { |id|
|
127
|
+
set.each { |id|
|
128
|
+
agent_manager.remove( id )
|
129
|
+
outputs.delete( id )
|
130
|
+
}
|
128
131
|
end
|
129
132
|
if ( k == "trade_enable" )
|
130
133
|
# 取引の有効状態を更新
|
131
|
-
@agent_manager.operator.trade_enable =
|
132
|
-
@props["trade_enable"] ? true : false
|
134
|
+
@agent_manager.operator.trade_enable = v ? true : false
|
133
135
|
end
|
136
|
+
@props[k] = v
|
134
137
|
save_props
|
135
138
|
end
|
136
139
|
def [](k)
|
@@ -151,8 +154,9 @@ module JIJI
|
|
151
154
|
attr :process_dir, true
|
152
155
|
attr :agent_manager, true
|
153
156
|
attr :outputs, true
|
157
|
+
attr :logger, true
|
154
158
|
attr :registry, true
|
155
|
-
|
159
|
+
|
156
160
|
private
|
157
161
|
|
158
162
|
# 任意のエージェントの設定を更新する。
|
@@ -163,7 +167,8 @@ module JIJI
|
|
163
167
|
a.agent.properties = props
|
164
168
|
else
|
165
169
|
agent = agent_manager.agent_registry.create( cl, props )
|
166
|
-
agent_manager.add( id, agent )
|
170
|
+
agent_manager.add( id, agent, props["name"] )
|
171
|
+
@outputs[id] = agent.output
|
167
172
|
end
|
168
173
|
end
|
169
174
|
|
@@ -192,10 +197,14 @@ module JIJI
|
|
192
197
|
agent_manager.add( v["id"], agent, v["name"] )
|
193
198
|
@outputs[v["id"]] = agent.output
|
194
199
|
rescue Exception
|
195
|
-
|
200
|
+
unless ignore_error
|
201
|
+
raise $!
|
202
|
+
else
|
203
|
+
@logger.error $!
|
204
|
+
end
|
196
205
|
# リアルトレードの場合、停止中にエージェントが破棄された場合を考慮し
|
197
206
|
# エージェントの初期化で失敗しても無視し、出力先だけ作成
|
198
|
-
@outputs[v["id"]] = @registry.output( @id, v["
|
207
|
+
@outputs[v["id"]] = @registry.output( @id, v["name"] )
|
199
208
|
end
|
200
209
|
}
|
201
210
|
end
|
data/lib/jiji/registry.rb
CHANGED
@@ -179,7 +179,7 @@ module JIJI
|
|
179
179
|
|
180
180
|
# RMTプロセス
|
181
181
|
r.register( :rmt_process ) {
|
182
|
-
c = JIJI::Process.new("rmt", r.process_dir, r.agent_manager("rmt",true), nil, r, true)
|
182
|
+
c = JIJI::Process.new("rmt", r.process_dir, r.agent_manager("rmt",true), r.process_logger("rmt"), nil, r, true)
|
183
183
|
c.observer_manager = r.rmt_observer_manager
|
184
184
|
c.collector = r.rmt_collector
|
185
185
|
c
|
@@ -187,8 +187,7 @@ module JIJI
|
|
187
187
|
# バックテストプロセス
|
188
188
|
r.register( :backtest_process, :model=>:multiton_initialize ) {|c,p,id, props|
|
189
189
|
# 既存のバックテストを読み込む場合、プロパティはnil
|
190
|
-
|
191
|
-
c = JIJI::Process.new(id, r.process_dir, r.agent_manager(id,false), props, r, props == nil)
|
190
|
+
c = JIJI::Process.new(id, r.process_dir, r.agent_manager(id,false), r.process_logger(id), props, r, false)
|
192
191
|
c.observer_manager = r.backtest_observer_manager(id)
|
193
192
|
c.collector = r.backtest_collector(id,
|
194
193
|
Time.at( c["start_date"]), Time.at( c["end_date"]))
|
data/lib/jiji/server.rb
CHANGED
@@ -22,8 +22,7 @@ module JIJI
|
|
22
22
|
|
23
23
|
param[:Logger] = registry[:server_logger]
|
24
24
|
param[:DocumentRoot] = File.expand_path( "#{__FILE__}/../../../html" )
|
25
|
-
|
26
|
-
param[:Logger].info( File.expand_path( "#{__FILE__}/../../../html" ) )
|
25
|
+
param[:Logger].info( "document root: #{ param[:DocumentRoot] }" )
|
27
26
|
|
28
27
|
start_callback_org = param[:StartCallback]
|
29
28
|
param[:StartCallback] = proc {
|
data/test/test_Process.rb
CHANGED
@@ -22,34 +22,34 @@ class ProcessTest < RUNIT::TestCase
|
|
22
22
|
def setup
|
23
23
|
@dir = File.dirname(__FILE__) + "/ProcessTest.tmp"
|
24
24
|
FileUtils.mkdir_p @dir
|
25
|
+
|
26
|
+
@logger = Logger.new STDOUT
|
27
|
+
|
28
|
+
# レジストリ
|
29
|
+
@registry_mock = Object.new
|
30
|
+
class << @registry_mock
|
31
|
+
def output( agent_name, dir )
|
32
|
+
return ["from_registry"]
|
33
|
+
end
|
34
|
+
end
|
25
35
|
end
|
26
36
|
|
27
37
|
def teardown
|
28
38
|
FileUtils.rm_rf @dir
|
29
39
|
end
|
30
40
|
|
41
|
+
# 基本動作のテスト
|
31
42
|
def test_basic
|
32
43
|
|
33
44
|
# 新規に作成
|
34
|
-
agent_mng =
|
35
|
-
agent_mng.operator = Struct.new(:trade_enable).new(true)
|
36
|
-
agent_mng.conf = CONF
|
37
|
-
agent_mng.conf.set( [:agent,:safe_level], 0)
|
45
|
+
agent_mng = new_agent_mang
|
38
46
|
|
39
|
-
|
40
|
-
class << registry_mock
|
41
|
-
def output( agent_name, dir )
|
42
|
-
output = JIJI::Output.new( agent_name, "#{dir}/out" )
|
43
|
-
return output
|
44
|
-
end
|
45
|
-
end
|
46
|
-
agent_mng.registry = registry_mock
|
47
|
-
|
48
|
-
p1 = JIJI::Process.new( "1", @dir, agent_mng, {} )
|
47
|
+
p1 = JIJI::Process.new( "1", @dir, agent_mng, @logger, {}, @registry_mock )
|
49
48
|
assert_equals p1.id, "1"
|
50
49
|
assert_equals p1.props, {"agents"=>[]}
|
51
50
|
assert_equals p1["x"], nil
|
52
51
|
assert_equals p1.agent_manager, agent_mng
|
52
|
+
assert_equals p1.outputs, {}
|
53
53
|
|
54
54
|
p1["x"] = "xxx"
|
55
55
|
assert_equals p1["x"], "xxx"
|
@@ -92,6 +92,7 @@ class ProcessTest < RUNIT::TestCase
|
|
92
92
|
assert_equals agent_mng.get("aaa").agent.properties, {"x"=>30, "y"=>40 }
|
93
93
|
assert_equals agent_mng.get("bbb").agent.cl, "testclass2@foo.rb"
|
94
94
|
assert_equals agent_mng.get("bbb").agent.properties, {"x"=>30, "y"=>41 }
|
95
|
+
assert_equals p1.outputs, { "aaa"=>["out1","out2"], "bbb"=>["out1","out2"] }
|
95
96
|
|
96
97
|
# 変更
|
97
98
|
agents = [
|
@@ -118,6 +119,7 @@ class ProcessTest < RUNIT::TestCase
|
|
118
119
|
assert_equals agent_mng.get("aaa").agent.properties, {"x"=>50, "y"=>40 }
|
119
120
|
assert_equals agent_mng.get("bbb").agent.cl, "testclass2@foo.rb"
|
120
121
|
assert_equals agent_mng.get("bbb").agent.properties, {"x"=>60, "y"=>41 }
|
122
|
+
assert_equals p1.outputs, { "aaa"=>["out1","out2"], "bbb"=>["out1","out2"] }
|
121
123
|
|
122
124
|
# 削除
|
123
125
|
agents = [
|
@@ -135,10 +137,12 @@ class ProcessTest < RUNIT::TestCase
|
|
135
137
|
assert_equals agent_mng.get("aaa").agent.cl, "testclass@foo.rb"
|
136
138
|
assert_equals agent_mng.get("aaa").agent.properties, {"x"=>50, "y"=>41 }
|
137
139
|
assert_equals agent_mng.get("bbb"), nil
|
140
|
+
assert_equals p1.outputs, { "aaa"=>["out1","out2"] }
|
138
141
|
|
139
|
-
|
140
|
-
#
|
141
|
-
|
142
|
+
# RMTモードで再読み込み
|
143
|
+
# ファイルに保存された設定値が読み込まれる。また、エージェントがインスタンス化される
|
144
|
+
agent_mng = new_agent_mang
|
145
|
+
p1 = JIJI::Process.new( "1", @dir, agent_mng, @logger, nil, @registry_mock, true )
|
142
146
|
assert_equals p1.id, "1"
|
143
147
|
assert_equals p1.agent_manager, agent_mng
|
144
148
|
assert_equals p1["x"], "xxx"
|
@@ -148,16 +152,168 @@ class ProcessTest < RUNIT::TestCase
|
|
148
152
|
assert_equals agent_mng.get("bbb"), nil
|
149
153
|
assert_equals p1["trade_enable"], false
|
150
154
|
assert_equals p1.agent_manager.operator.trade_enable, false
|
155
|
+
assert_equals p1.outputs, { "aaa"=>["out1","out2"] }
|
156
|
+
|
157
|
+
# バックテストモードで再読み込み
|
158
|
+
# ファイルに保存された設定値が読み込まれるが、エージェントはインスタンス化されない
|
159
|
+
agent_mng = new_agent_mang
|
160
|
+
p1 = JIJI::Process.new( "1", @dir, agent_mng, @logger, nil, @registry_mock, false )
|
161
|
+
assert_equals p1.id, "1"
|
162
|
+
assert_equals p1.agent_manager, agent_mng
|
163
|
+
assert_equals p1["x"], "xxx"
|
164
|
+
assert_equals p1["agents"], agents
|
165
|
+
assert_equals agent_mng.get("aaa"), nil
|
166
|
+
assert_equals agent_mng.get("bbb"), nil
|
167
|
+
assert_equals p1["trade_enable"], false
|
168
|
+
assert_equals p1.agent_manager.operator.trade_enable, false
|
169
|
+
assert_equals p1.outputs, { "aaa"=> ["from_registry"] }
|
151
170
|
|
152
171
|
# 別のプロセスを作成 / 設定値は別途保持される。
|
153
|
-
|
172
|
+
agent_mng = new_agent_mang
|
173
|
+
p2 = JIJI::Process.new( "2", @dir, agent_mng, @logger, {}, @registry_mock )
|
154
174
|
assert_equals p2.id, "2"
|
155
175
|
assert_equals p2.agent_manager, agent_mng
|
156
176
|
assert_equals p2["x"], nil
|
157
177
|
assert_equals p2["agents"], []
|
178
|
+
assert_equals p2.outputs, { }
|
179
|
+
|
180
|
+
# 作成の段階でエージェントを指定する
|
181
|
+
agent_mng = new_agent_mang
|
182
|
+
p3 = JIJI::Process.new( "3", @dir, agent_mng, @logger, {"agents"=>agents}, @registry_mock )
|
183
|
+
assert_equals p3.id, "3"
|
184
|
+
assert_equals p3.agent_manager, agent_mng
|
185
|
+
assert_equals p3["x"], nil
|
186
|
+
assert_equals p3["agents"], agents
|
187
|
+
assert_equals agent_mng.get("aaa").agent.cl, "testclass@foo.rb"
|
188
|
+
assert_equals agent_mng.get("aaa").agent.properties, {"x"=>50, "y"=>41 }
|
189
|
+
assert_equals agent_mng.get("bbb"), nil
|
190
|
+
assert_equals p3.outputs, { "aaa"=>["out1","out2"] }
|
158
191
|
|
159
192
|
end
|
160
193
|
|
194
|
+
# エージェントの作成でエラーになった場合のテスト
|
195
|
+
def test_error
|
196
|
+
agents = [
|
197
|
+
{"id"=>"aaa",
|
198
|
+
"name"=>"テストエージェント1",
|
199
|
+
"class"=>"testclass@foo.rb",
|
200
|
+
"class_name" => "testclass",
|
201
|
+
"file_name" => "foo.rb",
|
202
|
+
"description" => "説明",
|
203
|
+
"property_def" => {"id"=>"x", "default"=>85 },
|
204
|
+
"properties" => {"x"=>50, "y"=>41 }}
|
205
|
+
]
|
206
|
+
|
207
|
+
# RMTで生成時にエラー
|
208
|
+
# 再起動で失敗するのを防ぐため、エラーはログに出力された後、無視される。
|
209
|
+
agent_mng = new_agent_mang
|
210
|
+
p1 = JIJI::Process.new( "1", @dir, agent_mng, @logger, {"agents"=>agents}, @registry_mock, true )
|
211
|
+
|
212
|
+
error_registry = RegistryMock.new
|
213
|
+
class << error_registry
|
214
|
+
def create(*args); raise "test"; end
|
215
|
+
end
|
216
|
+
# 再作成
|
217
|
+
agent_mng = new_agent_mang(error_registry)
|
218
|
+
p1 = JIJI::Process.new( "1", @dir, agent_mng, @logger, nil, @registry_mock, true )
|
219
|
+
assert_equals p1.id, "1"
|
220
|
+
assert_equals p1.agent_manager, agent_mng
|
221
|
+
assert_equals p1["agents"], agents
|
222
|
+
assert_equals agent_mng.get("aaa"), nil
|
223
|
+
assert_equals agent_mng.get("bbb"), nil
|
224
|
+
assert_equals p1["trade_enable"], nil
|
225
|
+
assert_equals p1.agent_manager.operator.trade_enable, false
|
226
|
+
assert_equals p1.outputs, { "aaa"=>["from_registry"] }
|
227
|
+
|
228
|
+
# RMTでエージェントの追加時にエラー
|
229
|
+
agents << {"id"=>"bbb",
|
230
|
+
"name"=>"テストエージェント4",
|
231
|
+
"class"=>"testclass2@foo.rb",
|
232
|
+
"class_name" => "testclass",
|
233
|
+
"file_name" => "foo.rb",
|
234
|
+
"description" => "説明2aaaaaa",
|
235
|
+
"property_def" => {"id"=>"x", "default"=>85 },
|
236
|
+
"properties" => {"x"=>60, "y"=>41 }}
|
237
|
+
begin
|
238
|
+
p1["agents"] = agents
|
239
|
+
fail
|
240
|
+
rescue
|
241
|
+
end
|
242
|
+
|
243
|
+
# RMTでエージェントのプロパティ更新時にエラー
|
244
|
+
agents2 = [
|
245
|
+
{"id"=>"aaa",
|
246
|
+
"name"=>"テストエージェント1",
|
247
|
+
"class"=>"testclass@foo.rb",
|
248
|
+
"class_name" => "testclass",
|
249
|
+
"file_name" => "foo.rb",
|
250
|
+
"description" => "説明",
|
251
|
+
"property_def" => {"id"=>"x", "default"=>85 },
|
252
|
+
"properties" => {"x"=>50, "y"=>41 }}
|
253
|
+
]
|
254
|
+
error_registry = RegistryMock.new
|
255
|
+
class << error_registry
|
256
|
+
def create( cl, property )
|
257
|
+
a = Agent.new( cl, property )
|
258
|
+
class << a
|
259
|
+
def properties=(props)
|
260
|
+
raise "test"
|
261
|
+
end
|
262
|
+
end
|
263
|
+
return a
|
264
|
+
end
|
265
|
+
end
|
266
|
+
agent_mng = new_agent_mang(error_registry)
|
267
|
+
p1 = JIJI::Process.new( "2", @dir, agent_mng, @logger, {"agents"=>agents2}, @registry_mock, true )
|
268
|
+
assert_equals p1["agents"], agents2
|
269
|
+
assert_equals agent_mng.get("aaa").agent.cl, "testclass@foo.rb"
|
270
|
+
assert_equals agent_mng.get("aaa").agent.properties, {"x"=>50, "y"=>41 }
|
271
|
+
assert_equals agent_mng.get("bbb"), nil
|
272
|
+
assert_equals p1.outputs, { "aaa"=>["out1","out2"] }
|
273
|
+
|
274
|
+
begin
|
275
|
+
p1["agents"] = [
|
276
|
+
{"id"=>"aaa",
|
277
|
+
"name"=>"テストエージェント1",
|
278
|
+
"class"=>"testclass@foo.rb",
|
279
|
+
"class_name" => "testclass",
|
280
|
+
"file_name" => "foo.rb",
|
281
|
+
"description" => "説明",
|
282
|
+
"property_def" => {"id"=>"x", "default"=>85 },
|
283
|
+
"properties" => {"x"=>50, "y"=>31 }}
|
284
|
+
]
|
285
|
+
fail
|
286
|
+
rescue
|
287
|
+
end
|
288
|
+
assert_equals p1["agents"], agents2
|
289
|
+
assert_equals agent_mng.get("aaa").agent.cl, "testclass@foo.rb"
|
290
|
+
assert_equals agent_mng.get("aaa").agent.properties, {"x"=>50, "y"=>41 }
|
291
|
+
assert_equals agent_mng.get("bbb"), nil
|
292
|
+
assert_equals p1.outputs, { "aaa"=>["out1","out2"] }
|
293
|
+
|
294
|
+
# バックテストでエージェント生成時にエラー
|
295
|
+
error_registry = RegistryMock.new
|
296
|
+
class << error_registry
|
297
|
+
def create; raise "test"; end
|
298
|
+
end
|
299
|
+
agent_mng = new_agent_mang(error_registry)
|
300
|
+
begin
|
301
|
+
JIJI::Process.new( "1", @dir, agent_mng, @logger, {"agents"=>agents}, @registry_mock, false )
|
302
|
+
fail
|
303
|
+
rescue
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
# エージェントマネージャを再作成する
|
308
|
+
def new_agent_mang( agent_registory=RegistryMock.new )
|
309
|
+
agent_mng = JIJI::AgentManager.new( "aaa", agent_registory, Logger.new(STDOUT))
|
310
|
+
agent_mng.operator = Struct.new(:trade_enable).new(true)
|
311
|
+
agent_mng.conf = CONF
|
312
|
+
agent_mng.conf.set( [:agent,:safe_level], 0)
|
313
|
+
agent_mng.registry = @registry_mock
|
314
|
+
return agent_mng
|
315
|
+
end
|
316
|
+
|
161
317
|
class Agent
|
162
318
|
include JIJI::Agent
|
163
319
|
|
@@ -174,6 +330,9 @@ class ProcessTest < RUNIT::TestCase
|
|
174
330
|
def properties=( properties )
|
175
331
|
@properties = properties
|
176
332
|
end
|
333
|
+
def output
|
334
|
+
["out1","out2"]
|
335
|
+
end
|
177
336
|
attr :cl, true
|
178
337
|
end
|
179
338
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unageanu-jiji
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masaya Yamauchi
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-04-08 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|