コミットメタ情報

リビジョン734ce82d355005c2b63181834ecd34c7527746d9 (tree)
日時2017-07-22 00:05:55
作者Kazuhiro Fujieda <fujieda@user...>
コミッターKazuhiro Fujieda

ログメッセージ

ログが壊れているときにグラフが表示されなくなったりするのを直す

変更サマリ

差分

--- a/KancolleSniffer/LogServer.cs
+++ b/KancolleSniffer/LogServer.cs
@@ -136,45 +136,83 @@ namespace KancolleSniffer
136136 var csv = path.Replace(".json", ".csv");
137137 var encoding = Encoding.GetEncoding("Shift_JIS");
138138 client.Send(encoding.GetBytes("{ \"data\": [\n"));
139+ var battle = false;
140+ var material = false;
139141 try
140142 {
141- if (File.Exists(csv))
143+ if (!File.Exists(csv))
144+ return;
145+ var records = 0;
146+ if (path.EndsWith("遠征報告書.json"))
142147 {
143- var delimiter = "";
144- var material = path.EndsWith("資材ログ.json"); // 末尾の空データを削除する必要がある
145- var battle = path.EndsWith("海戦・ドロップ報告書.json"); // データを40個にそろえる必要がある
146- foreach (var line in File.ReadLines(csv, encoding).Skip(1))
148+ records = 10;
149+ }
150+ else if (path.EndsWith("改修報告書.json"))
151+ {
152+ records = 15;
153+ }
154+ else if (path.EndsWith("海戦・ドロップ報告書.json"))
155+ {
156+ records = 38;
157+ battle = true;
158+ }
159+ else if (path.EndsWith("開発報告書.json"))
160+ {
161+ records = 9;
162+ }
163+ else if (path.EndsWith("建造報告書.json"))
164+ {
165+ records = 12;
166+ }
167+ else if (path.EndsWith("資材ログ.json"))
168+ {
169+ records = 9;
170+ material = true;
171+ }
172+ else if (path.EndsWith("戦果.json"))
173+ {
174+ records = 3;
175+ }
176+ var delimiter = "";
177+ foreach (var line in File.ReadLines(csv, encoding).Skip(1))
178+ {
179+ var data = line.Split(',');
180+ if (!DateTime.TryParseExact(data[0], Logger.DateTimeFormat, CultureInfo.InvariantCulture,
181+ DateTimeStyles.AssumeLocal, out DateTime date))
147182 {
148- var data = line.Split(',');
149- DateTime date;
150- if (!DateTime.TryParseExact(data[0], Logger.DateTimeFormat, CultureInfo.InvariantCulture,
151- DateTimeStyles.AssumeLocal, out date) &&
152- DateTime.TryParse(data[0], CultureInfo.CurrentCulture, DateTimeStyles.AssumeLocal, out date))
183+ if (DateTime.TryParse(data[0], CultureInfo.CurrentCulture,
184+ DateTimeStyles.AssumeLocal, out date))
153185 {
154186 data[0] = date.ToString(Logger.DateTimeFormat);
155187 }
156- if (date < from || to < date)
157- continue;
158- IEnumerable<string> entries = data;
159- if (material)
160- entries = data.Take(9);
161- if (battle)
162- entries = data.Concat(Enumerable.Repeat("", 3)).Take(38);
163- if (number)
164- {
165- var stamp = ((date.ToUniversalTime().Ticks -
166- new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks) /
167- TimeSpan.TicksPerMillisecond).ToString();
168- client.Send(encoding.GetBytes(delimiter + "[" + stamp + "," +
169- string.Join(",", entries.Skip(1)) + "]"));
170- }
171188 else
172189 {
173- client.Send(encoding.GetBytes(delimiter + "[\"" +
174- string.Join("\",\"", entries) + "\"]"));
190+ continue;
175191 }
176- delimiter = ",\n";
177192 }
193+ if (date < from || to < date)
194+ continue;
195+ IEnumerable<string> entries = data;
196+ if (material)
197+ entries = data.Take(9);
198+ if (battle)
199+ entries = data.Concat(Enumerable.Repeat("", 3)).Take(38);
200+ if (entries.Count() != records)
201+ continue;
202+ if (number)
203+ {
204+ var stamp = ((date.ToUniversalTime().Ticks -
205+ new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks) /
206+ TimeSpan.TicksPerMillisecond).ToString();
207+ client.Send(encoding.GetBytes(delimiter + "[" + stamp + "," +
208+ string.Join(",", entries.Skip(1)) + "]"));
209+ }
210+ else
211+ {
212+ client.Send(encoding.GetBytes(delimiter + "[\"" +
213+ string.Join("\",\"", entries) + "\"]"));
214+ }
215+ delimiter = ",\n";
178216 }
179217 }
180218 finally
旧リポジトリブラウザで表示