• R/O
  • SSH
  • HTTPS

protra: Commit


Commit MetaInfo

Revision517 (tree)
Time2014-04-14 20:51:46
Authorpanacoran

Log Message

PriceDataUpdatorのサブクラスに継承で日付を渡すのをやめる

* Protra.Lib/Update/KabukaJohoUpdator.cs (KabukaJohoUpdator.DownloadUrl): 日付を引数に取る。
(KabukaJohoUpdator.ParseLine): 同上。
* Protra.Lib/Update/KdbComUpdator.cs: 同上。
* Protra.Lib/Update/MujinzouUpdator.cs: 同上。
* Protra.Lib/Update/PriceDataUpdator.cs (PriceDataUpdator.Date): 削除。
(PriceDataUpdator.EndDate): 削除。
(PriceDataUpdator.NextDate): 日付を引数に取る。
(PriceDataUpdator.DownloadUrl): 同上。
(PriceDataUpdator.ParseLine): 同上。
(PriceDataUpdator.UpdatePrice): DateとEndDateの削除に対応する。
* Protra.Lib/Update/YahooFinanceUpdator.cs: (YahooFinanceUpdator.UpdatePrice): DateとEndDateの削除に対応する。
(YahooFinanceUpdator.DoFetchPrice): Dateの削除に対応する。
(YahooFinanceUpdator.GetPage): 同上。

Change Summary

Incremental Difference

--- protra/trunk/ChangeLog.txt (revision 516)
+++ protra/trunk/ChangeLog.txt (revision 517)
@@ -1,3 +1,21 @@
1+2014-04-13 panacoran <panacoran@users.sourceforge.jp>
2+
3+ PriceDataUpdatorのサブクラスに継承で日付を渡すのをやめる
4+
5+ * Protra.Lib/Update/KabukaJohoUpdator.cs (KabukaJohoUpdator.DownloadUrl): 日付を引数に取る。
6+ (KabukaJohoUpdator.ParseLine): 同上。
7+ * Protra.Lib/Update/KdbComUpdator.cs: 同上。
8+ * Protra.Lib/Update/MujinzouUpdator.cs: 同上。
9+ * Protra.Lib/Update/PriceDataUpdator.cs (PriceDataUpdator.Date): 削除。
10+ (PriceDataUpdator.EndDate): 削除。
11+ (PriceDataUpdator.NextDate): 日付を引数に取る。
12+ (PriceDataUpdator.DownloadUrl): 同上。
13+ (PriceDataUpdator.ParseLine): 同上。
14+ (PriceDataUpdator.UpdatePrice): DateとEndDateの削除に対応する。
15+ * Protra.Lib/Update/YahooFinanceUpdator.cs: (YahooFinanceUpdator.UpdatePrice): DateとEndDateの削除に対応する。
16+ (YahooFinanceUpdator.DoFetchPrice): Dateの削除に対応する。
17+ (YahooFinanceUpdator.GetPage): 同上。
18+
119 2014-04-10 panacoran <panacoran@users.sourceforge.jp>
220
321 株価データ更新の進捗の計算をProgressクラスに分離する
--- protra/trunk/Protra.Lib/Update/PriceDataUpdator.cs (revision 516)
+++ protra/trunk/Protra.Lib/Update/PriceDataUpdator.cs (revision 517)
@@ -289,20 +289,10 @@
289289 private readonly Progress _progress = new Progress();
290290
291291 /// <summary>
292- /// 処理中の日付を取得または設定する。
293- /// </summary>
294- protected DateTime Date { get; set; }
295-
296- /// <summary>
297- /// 処理すべき最後の日付を取得または設定する。
298- /// </summary>
299- protected DateTime EndDate { get; set; }
300-
301- /// <summary>
302292 /// データのURLを取得する。
303293 /// </summary>
304294 /// <returns>URL</returns>
305- protected abstract string DownloadUrl { get; }
295+ protected abstract string DownloadUrl(DateTime date);
306296
307297 /// <summary>
308298 /// 処理を開始終了する日付を営業日に調節し、その間の営業日数を数える。
@@ -337,12 +327,13 @@
337327 /// <summary>
338328 /// 日付を次の市場が開いている日に進める。
339329 /// </summary>
340- protected void NextDate()
330+ protected DateTime NextDate(DateTime date)
341331 {
342332 do
343333 {
344- Date = Date.AddDays(1);
345- } while (!Calendar.IsMarketOpen(Date) && Date < EndDate);
334+ date = date.AddDays(1);
335+ } while (!Calendar.IsMarketOpen(date));
336+ return date;
346337 }
347338
348339 /// <summary>
@@ -449,10 +440,10 @@
449440 end = end.AddDays(-1);
450441 _progress.NumDays = AdjustedDate(ref begin, ref end);
451442 _progress.Start();
452- for (Date = begin, EndDate = end; Date <= EndDate; NextDate())
443+ for (var date = begin; date <= end; date = NextDate(date))
453444 {
454- _progress.Show(worker, Date);
455- var dl = new DownloadUtil(DownloadUrl);
445+ _progress.Show(worker, date);
446+ var dl = new DownloadUtil(DownloadUrl(date));
456447 _progress.StartDownload();
457448 var prices = new List<Price>();
458449 using (var stream = dl.DownloadAndExtract())
@@ -475,7 +466,7 @@
475466 Price prev = null;
476467 while ((line = reader.ReadLine()) != null)
477468 {
478- var tmp = ParseLine(line);
469+ var tmp = ParseLine(line, date);
479470 if (tmp == null)
480471 continue;
481472 if (prev == null)
@@ -506,11 +497,11 @@
506497 PriceData.CloseAll();
507498 return;
508499 }
509- PriceData.Add(price, Date == EndDate);
500+ PriceData.Add(price, date == end);
510501 _progress.IncrementRecords();
511- _progress.Show(worker, Date);
502+ _progress.Show(worker, date);
512503 }
513- PriceData.MaxDate = Date;
504+ PriceData.MaxDate = date;
514505 _progress.IncrementDays();
515506 }
516507 PriceData.CloseAll();
@@ -527,7 +518,8 @@
527518 /// 文字列を解析して価格データを返す。
528519 /// </summary>
529520 /// <param name="line">文字列</param>
521+ /// <param name="date">日付</param>
530522 /// <returns>価格データ</returns>
531- protected abstract Price ParseLine(string line);
523+ protected abstract Price ParseLine(string line, DateTime date);
532524 }
533525 }
\ No newline at end of file
--- protra/trunk/Protra.Lib/Update/KabukaJohoUpdator.cs (revision 516)
+++ protra/trunk/Protra.Lib/Update/KabukaJohoUpdator.cs (revision 517)
@@ -49,15 +49,12 @@
4949 /// データのURLを取得する。
5050 /// </summary>
5151 /// <returns>URL</returns>
52- protected override string DownloadUrl
52+ protected override string DownloadUrl(DateTime date)
5353 {
54- get
55- {
5654 return "http://www.edatalab.net/kabu/data" +
57- Date.ToString((Date.Year < 2006)
55+ date.ToString((date.Year < 2006)
5856 ? "yyyy/yyyyMMdd"
5957 : "yyyy/DyyMMdd") + ".LZH";
60- }
6158 }
6259
6360 /// <summary>
@@ -64,8 +61,9 @@
6461 /// 文字列を解析して価格データを返す。
6562 /// </summary>
6663 /// <param name="line">文字列</param>
64+ /// <param name="date">日付</param>
6765 /// <returns>価格データ</returns>
68- protected override Price ParseLine(string line)
66+ protected override Price ParseLine(string line, DateTime date)
6967 {
7068 var tokens = line.Split(',');
7169 var r = new Price();
--- protra/trunk/Protra.Lib/Update/KdbComUpdator.cs (revision 516)
+++ protra/trunk/Protra.Lib/Update/KdbComUpdator.cs (revision 517)
@@ -76,9 +76,9 @@
7676 /// データのURLを取得する。
7777 /// </summary>
7878 /// <returns>URL</returns>
79- protected override string DownloadUrl
79+ protected override string DownloadUrl(DateTime date)
8080 {
81- get { return "http://k-db.com/site/download.aspx?p=all&download=csv&date=" + Date.ToString("yyyy-MM-dd"); }
81+ return "http://k-db.com/site/download.aspx?p=all&download=csv&date=" + date.ToString("yyyy-MM-dd");
8282 }
8383
8484 private Dictionary<DateTime, double> _indexVolume;
@@ -113,8 +113,9 @@
113113 /// 文字列に含まれるデータを格納したオブジェクトを返す。
114114 /// </summary>
115115 /// <param name="line">文字列を指定する。</param>
116+ /// <param name="date">日付</param>
116117 /// <returns>オブジェクト</returns>
117- protected override Price ParseLine(string line)
118+ protected override Price ParseLine(string line, DateTime date)
118119 {
119120 var tokens = line.Split(',');
120121 var r = new Price();
@@ -124,7 +125,7 @@
124125 {
125126 r.Code = tokens[0] == "67" ? "1001" : "1002";
126127 r.Market = "T1";
127- r.Volume = _indexVolume[Date];
128+ r.Volume = _indexVolume[date];
128129 }
129130 else if (tokens[0].Length == 6)
130131 {
@@ -182,7 +183,7 @@
182183 }
183184 else
184185 return null;
185- r.Date = Date;
186+ r.Date = date;
186187 r.Open = (int)ParseField(tokens[4]);
187188 r.High = (int)ParseField(tokens[5]);
188189 r.Low = (int)ParseField(tokens[6]);
--- protra/trunk/Protra.Lib/Update/MujinzouUpdator.cs (revision 516)
+++ protra/trunk/Protra.Lib/Update/MujinzouUpdator.cs (revision 517)
@@ -49,9 +49,9 @@
4949 /// データのURLを取得する。
5050 /// </summary>
5151 /// <returns>URL</returns>
52- protected override string DownloadUrl
52+ protected override string DownloadUrl(DateTime date)
5353 {
54- get { return "http://souba-data.com/k_data/" + Date.ToString("yyyy/yy_MM/TyyMMdd") + ".lzh"; }
54+ return "http://souba-data.com/k_data/" + date.ToString("yyyy/yy_MM/TyyMMdd") + ".lzh";
5555 }
5656
5757 /// <summary>
@@ -58,8 +58,9 @@
5858 /// 文字列を解析して価格データを返す。
5959 /// </summary>
6060 /// <param name="line">文字列</param>
61+ /// <param name="date">日付</param>
6162 /// <returns>価格データ</returns>
62- protected override Price ParseLine(string line)
63+ protected override Price ParseLine(string line, DateTime date)
6364 {
6465 var tokens = line.Split(new[] {'\t', ','});
6566 if (tokens.Length < 9)
--- protra/trunk/Protra.Lib/Update/YahooFinanceUpdator.cs (revision 516)
+++ protra/trunk/Protra.Lib/Update/YahooFinanceUpdator.cs (revision 517)
@@ -36,6 +36,7 @@
3636 {
3737 private readonly Object _syncObject = new object();
3838 private Queue<Brand> _brandQueue;
39+ private DateTime _date;
3940 private readonly Queue<Price> _priceQueue = new Queue<Price>();
4041 private bool _terminate;
4142 private Exception _exception;
@@ -71,14 +72,15 @@
7172 _progress.NumDays = AdjustedDate(ref begin, ref end);
7273 _progress.RecordsPerDay = GlobalEnv.BrandData.Count;
7374 _progress.Start();
74- for (Date = begin, EndDate = end; Date <= EndDate; NextDate())
75+ for (var date = begin; date <= end; date = NextDate(date))
7576 {
7677 lock (_syncObject)
7778 {
79+ _date = date;
7880 _brandQueue = new Queue<Brand>(GlobalEnv.BrandData);
7981 Monitor.PulseAll(_syncObject);
8082 }
81- _progress.Show(worker, Date);
83+ _progress.Show(worker, date);
8284 var i = 0;
8385 for (; i < _progress.RecordsPerDay; i++)
8486 {
@@ -100,11 +102,11 @@
100102 continue;
101103 if (price.Code == "1001" && price.Open == 0) // まだ株価が用意されていない。
102104 return;
103- PriceData.Add(price, Date == EndDate);
105+ PriceData.Add(price, date == end);
104106 _progress.IncrementRecords();
105- _progress.Show(worker, Date);
107+ _progress.Show(worker, date);
106108 }
107- PriceData.MaxDate = Date;
109+ PriceData.MaxDate = date;
108110 _progress.IncrementDays();
109111 }
110112 }
@@ -150,7 +152,7 @@
150152 {
151153 lock (_priceQueue)
152154 {
153- _exception = new Exception(string.Format("{0}: {1} {2:d}", e.Message, code, Date), e);
155+ _exception = new Exception(string.Format("{0}: {1} {2:d}", e.Message, code, _date), e);
154156 Monitor.Pulse(_priceQueue);
155157 }
156158 }
@@ -164,7 +166,7 @@
164166 code = "998405";
165167 var dl = new DownloadUtil(string.Format(
166168 "http://info.finance.yahoo.co.jp/history/?code={0}&sy={1}&sm={2}&sd={3}&ey={4}&em={5}&ed={6}&tm=d",
167- code, Date.Year, Date.Month, Date.Day, Date.Year, Date.Month, Date.Day));
169+ code, _date.Year, _date.Month, _date.Day, _date.Year, _date.Month, _date.Day));
168170 for (var i = 0; i < 10; i++)
169171 {
170172 try
@@ -217,7 +219,7 @@
217219 if (obs.Match(buf).Success || empty.Match(buf).Success) // 上場廃止(銘柄データが空のこともある)
218220 return null;
219221 if (invalid.Match(buf).Success) // 出来高がないか株価が用意されていない。
220- return new Price {Date = Date, Open = 0, High = 0, Low = 0, Close = 0, Volume = 0.0};
222+ return new Price {Date = _date, Open = 0, High = 0, Low = 0, Close = 0, Volume = 0.0};
221223 throw new Exception("ページから株価を取得できません。");
222224 }
223225 try
@@ -255,9 +257,9 @@
255257 /// 使わない
256258 /// </summary>
257259 /// <returns>使わない</returns>
258- protected override string DownloadUrl
260+ protected override string DownloadUrl(DateTime date)
259261 {
260- get { throw new NotImplementedException(); }
262+ throw new NotImplementedException();
261263 }
262264
263265 /// <summary>
@@ -264,8 +266,9 @@
264266 /// 使わない
265267 /// </summary>
266268 /// <param name="line">使わない</param>
269+ /// <param name="date">使わない</param>
267270 /// <returns>使わない</returns>
268- protected override Price ParseLine(string line)
271+ protected override Price ParseLine(string line, DateTime date)
269272 {
270273 throw new NotImplementedException();
271274 }
Show on old repository browser