OmegaChartのソースコードの保守
リビジョン | 4a19d2e38eceb83051bcd3431dce63ce3c28d7cd (tree) |
---|---|
日時 | 2014-04-29 16:45:05 |
作者 | panacoran <panacoran@user...> |
コミッター | panacoran |
日付の制約を取り除く
https://sourceforge.jp/users/panacoran/pastebin/910
の指摘に基づいてDatePickerの最大最小の設定を外した。
週足のロジックを変更して日付の制約がないものにした。
@@ -264,7 +264,6 @@ namespace Zanetti.Forms { | ||
264 | 264 | // |
265 | 265 | this._startDatePicker.Checked = false; |
266 | 266 | this._startDatePicker.Location = new System.Drawing.Point(80, 16); |
267 | - this._startDatePicker.MinDate = new System.DateTime(1996, 1, 1, 0, 0, 0, 0); | |
268 | 267 | this._startDatePicker.Name = "_startDatePicker"; |
269 | 268 | this._startDatePicker.Size = new System.Drawing.Size(200, 19); |
270 | 269 | this._startDatePicker.TabIndex = 1; |
@@ -282,8 +281,6 @@ namespace Zanetti.Forms { | ||
282 | 281 | // _endDatePicker |
283 | 282 | // |
284 | 283 | this._endDatePicker.Location = new System.Drawing.Point(80, 40); |
285 | - this._endDatePicker.MaxDate = new System.DateTime(2010, 12, 31, 0, 0, 0, 0); | |
286 | - this._endDatePicker.MinDate = new System.DateTime(1996, 1, 1, 0, 0, 0, 0); | |
287 | 284 | this._endDatePicker.Name = "_endDatePicker"; |
288 | 285 | this._endDatePicker.Size = new System.Drawing.Size(200, 19); |
289 | 286 | this._endDatePicker.TabIndex = 3; |
@@ -3,6 +3,10 @@ | ||
3 | 3 | * |
4 | 4 | * $Id$ |
5 | 5 | */ |
6 | +// Copyright (c) 2014 panacoran <panacoran@users.sourceforge.jp> | |
7 | +// This program is part of OmegaChart. | |
8 | +// OmegaChart is licensed under the Apache License, Version 2.0. | |
9 | + | |
6 | 10 | using System; |
7 | 11 | using System.IO; |
8 | 12 | using System.Collections; |
@@ -353,26 +357,28 @@ namespace Zanetti.Data | ||
353 | 357 | _isEmpty = false; |
354 | 358 | _firstDate= GetInt(daily, 0); |
355 | 359 | _lastDate = GetInt(daily, daily.Length-RECORD_LENGTH); |
356 | - WeeklyIndex weekly_begin = Env.WeekFormat.FindByDate(GetInt(daily, 0)); | |
357 | - WeeklyIndex weekly_end = Env.WeekFormat.FindByDate(GetInt(daily, daily.Length-RECORD_LENGTH)); | |
358 | - _filledLength = weekly_end.Index+1 - weekly_begin.Index; | |
360 | + var daily_begin = Util.IntToDate(GetInt(daily, 0)); | |
361 | + var weekly_begin = daily_begin.AddDays(-(int)daily_begin.DayOfWeek); | |
362 | + var daily_end = Util.IntToDate(GetInt(daily, daily.Length - RECORD_LENGTH)); | |
363 | + var weekly_end = daily_end.AddDays(-(int)daily_end.DayOfWeek); | |
364 | + _filledLength = (int)(weekly_end - weekly_begin).TotalDays / 7 + 1; | |
359 | 365 | _data = new TradeData[_filledLength + Env.CurrentIndicators.GetAddedFutureLength(ChartFormat.Weekly)]; |
360 | 366 | |
361 | 367 | //byte[]部分のデータ読み |
362 | 368 | _farm = new byte[_data.Length * RECORD_LENGTH]; |
363 | 369 | _byteLength = _farm.Length; |
364 | 370 | int offset = 0; |
365 | - for(int i=weekly_begin.Index; i<=weekly_end.Index; i++) { | |
366 | - WeeklyIndex wi = Env.WeekFormat.GetAt(i); | |
367 | - offset = FillWeeklyData((i-weekly_begin.Index)*RECORD_LENGTH, daily, offset, wi); | |
371 | + var weekly = weekly_begin; | |
372 | + for(int i=0; i < _filledLength; i++, weekly = weekly.AddDays(7)) { | |
373 | + offset = FillWeeklyData(i*RECORD_LENGTH, daily, offset, Util.DateToInt(weekly)); | |
368 | 374 | if(offset>=daily.Length) break; |
369 | 375 | } |
370 | 376 | } |
371 | 377 | } |
372 | 378 | } |
373 | - private int FillWeeklyData(int farmoffset, byte[] daily, int offset, WeeklyIndex wi) { | |
379 | + private int FillWeeklyData(int farmoffset, byte[] daily, int offset, int firstdate) { | |
374 | 380 | |
375 | - int enddate = Env.WeekFormat.Length>wi.Index+1? Env.WeekFormat.GetAt(wi.Index+1).FirstDate : Util.DateToInt(Util.IntToDate(wi.FirstDate).AddDays(7)); | |
381 | + int enddate = Util.DateToInt(Util.IntToDate(firstdate).AddDays(7)); | |
376 | 382 | |
377 | 383 | int vol = 0, high = Int32.MinValue, low = Int32.MaxValue; |
378 | 384 | int open = 0, close = 0, cre_long = 0, cre_short = 0; |
@@ -384,7 +390,7 @@ namespace Zanetti.Data | ||
384 | 390 | // で、後に式を評価する際に用いられる基準日として日曜基準で 'wi.FirstDate' を使っているのだから、 |
385 | 391 | // ここでもこの値を使うべき。 2005/3/15 T. SARUKI |
386 | 392 | // |
387 | - double base_split = this.CalcSplitRatio(wi.FirstDate); //分割を考慮する場合は期間内の調整が要る | |
393 | + double base_split = this.CalcSplitRatio(firstdate); //分割を考慮する場合は期間内の調整が要る | |
388 | 394 | while(offset<=daily.Length-RECORD_LENGTH && today<enddate) { |
389 | 395 | //if(!is_index && today>20031201) Debugger.Break(); |
390 | 396 | double split = Env.Preference.AdjustSplit? this.CalcSplitRatio(today) / base_split : 1; |
@@ -403,7 +409,7 @@ namespace Zanetti.Data | ||
403 | 409 | if(offset<daily.Length) today = GetInt(daily, offset); |
404 | 410 | } |
405 | 411 | |
406 | - SetInt(_farm, farmoffset, wi.FirstDate); | |
412 | + SetInt(_farm, farmoffset, firstdate); | |
407 | 413 | SetInt(_farm, farmoffset+OPEN_OFFSET, open); |
408 | 414 | SetInt(_farm, farmoffset+HIGH_OFFSET, high); |
409 | 415 | SetInt(_farm, farmoffset+LOW_OFFSET, low); |
@@ -43,7 +43,6 @@ namespace Zanetti | ||
43 | 43 | private static CommandCollection _command; |
44 | 44 | private static BrandHistory _history; |
45 | 45 | private static StorageNode _rootStorageNode; |
46 | - private static WeekFormat _weekFormat; | |
47 | 46 | private static ImageList _imageList16; |
48 | 47 | |
49 | 48 | public static Preference Preference { |
@@ -118,12 +117,6 @@ namespace Zanetti | ||
118 | 117 | return _freeLines; |
119 | 118 | } |
120 | 119 | } |
121 | - public static WeekFormat WeekFormat { | |
122 | - get { | |
123 | - return _weekFormat; | |
124 | - } | |
125 | - } | |
126 | - | |
127 | 120 | //パース済み設定ファイルのルート ネーミングはちとおかしいが |
128 | 121 | public static StorageNode RootStorageNode { |
129 | 122 | get { |
@@ -167,7 +160,6 @@ namespace Zanetti | ||
167 | 160 | _options = new Options(); |
168 | 161 | _bookmark = new Bookmark(); |
169 | 162 | _freeLines = new FreeLineCollection(); |
170 | - _weekFormat = new WeekFormat(); | |
171 | 163 | _history = new BrandHistory(); |
172 | 164 | InitialAction act = new InitialAction(); |
173 | 165 |
@@ -276,7 +276,6 @@ namespace Zanetti.Forms | ||
276 | 276 | // |
277 | 277 | this._datePicker.Checked = false; |
278 | 278 | this._datePicker.Location = new System.Drawing.Point(16, 16); |
279 | - this._datePicker.MinDate = new System.DateTime(1996, 1, 1, 0, 0, 0, 0); | |
280 | 279 | this._datePicker.Name = "_datePicker"; |
281 | 280 | this._datePicker.Size = new System.Drawing.Size(200, 19); |
282 | 281 | this._datePicker.TabIndex = 12; |
@@ -1,95 +0,0 @@ | ||
1 | -/* | |
2 | - * Copyright (c) Daisuke OKAJIMA All rights reserved. | |
3 | - * | |
4 | - * $Id$ | |
5 | - */ | |
6 | -using System; | |
7 | -using System.Diagnostics; | |
8 | -using System.Collections; | |
9 | - | |
10 | -namespace Zanetti.Data | |
11 | -{ | |
12 | - //毎週月曜からの見出し項目 | |
13 | - internal class WeeklyIndex | |
14 | - { | |
15 | - private int _index; | |
16 | - private int _firstDate; | |
17 | - private bool _startOfQuarter; | |
18 | - | |
19 | - public int FirstDate { | |
20 | - get { | |
21 | - return _firstDate; | |
22 | - } | |
23 | - } | |
24 | - public int Index { | |
25 | - get { | |
26 | - return _index; | |
27 | - } | |
28 | - } | |
29 | - public bool StartOfQuarter { | |
30 | - get { | |
31 | - return _startOfQuarter; | |
32 | - } | |
33 | - } | |
34 | - | |
35 | - public WeeklyIndex(int index, int firstdate, bool quarter) { | |
36 | - _index = index; | |
37 | - _firstDate = firstdate; | |
38 | - _startOfQuarter = quarter; | |
39 | - } | |
40 | - } | |
41 | - | |
42 | - //毎週月曜のコレクション | |
43 | - internal class WeekFormat { | |
44 | - private WeeklyIndex[] _data; | |
45 | - | |
46 | - private void Construct() { | |
47 | - DateTime dt = new DateTime(1987,12,27); //こいつは日曜日 | |
48 | - ArrayList t = new ArrayList(500); | |
49 | - DateTime now = DateTime.Now; | |
50 | - int i = 0; | |
51 | - while(dt < now) { | |
52 | - int dti = Util.DateToInt(dt); | |
53 | - int m = (dti % 10000) / 100; | |
54 | - int d = dti % 100; | |
55 | - t.Add(new WeeklyIndex(i++, dti, d<=7 && (m==1 || m==4 || m==7 || m==10))); | |
56 | - dt = dt.AddDays(7); | |
57 | - } | |
58 | - | |
59 | - _data = (WeeklyIndex[])t.ToArray(typeof(WeeklyIndex)); | |
60 | - } | |
61 | - | |
62 | - public WeeklyIndex FindByDate(int date) { | |
63 | - if(_data==null) Construct(); | |
64 | - if(date<_data[1].FirstDate) | |
65 | - return _data[0]; //両端はよくあるケースなので | |
66 | - else if(date>=_data[_data.Length-1].FirstDate) | |
67 | - return _data[_data.Length-1]; | |
68 | - else | |
69 | - return FindByDate(date, 0, _data.Length); | |
70 | - } | |
71 | - private WeeklyIndex FindByDate(int date, int start, int end) { | |
72 | - int m = (start+end)/2; | |
73 | - if(_data[m].FirstDate > date) | |
74 | - return FindByDate(date, start, m); | |
75 | - else if(_data[m+1].FirstDate <= date) | |
76 | - return FindByDate(date, m+1, end); | |
77 | - else | |
78 | - return _data[m]; | |
79 | - } | |
80 | - | |
81 | - public WeeklyIndex GetAt(int index) { | |
82 | - if(_data==null) Construct(); | |
83 | - Debug.Assert(index>=0 && index<_data.Length); | |
84 | - return _data[index]; | |
85 | - } | |
86 | - public int Length { | |
87 | - get { | |
88 | - if(_data==null) Construct(); | |
89 | - return _data.Length; | |
90 | - } | |
91 | - } | |
92 | - } | |
93 | - | |
94 | - | |
95 | -} |
@@ -364,7 +364,6 @@ | ||
364 | 364 | <SubType>Component</SubType> |
365 | 365 | </Compile> |
366 | 366 | <Compile Include="Visitor.cs" /> |
367 | - <Compile Include="Weekly.cs" /> | |
368 | 367 | <Compile Include="Win32.cs" /> |
369 | 368 | <Compile Include="XmlStorageRW.cs" /> |
370 | 369 | <Compile Include="XmlUtil.cs" /> |