You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
3.7 KiB
93 lines
3.7 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text.RegularExpressions;
|
|
using leak_test_project.Models;
|
|
|
|
namespace leak_test_project.Utils
|
|
{
|
|
public static class LogParser
|
|
{
|
|
private static readonly string LogDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs");
|
|
|
|
public static List<InspectData> ParseLogs(DateTime start, DateTime end, string judgmentFilter = "[전체]", string serialFilter = "")
|
|
{
|
|
var results = new List<InspectData>();
|
|
|
|
if (!Directory.Exists(LogDirectory))
|
|
{
|
|
// 디렉토리가 없으면 빈 리스트 반환
|
|
return results;
|
|
}
|
|
|
|
// 날짜 범위 내의 모든 로그 파일 찾기 (.csv)
|
|
var files = Directory.GetFiles(LogDirectory, "*.csv")
|
|
.Where(f => {
|
|
string fileName = Path.GetFileNameWithoutExtension(f);
|
|
if (DateTime.TryParse(fileName, out DateTime fileDate))
|
|
{
|
|
return fileDate.Date >= start.Date && fileDate.Date <= end.Date;
|
|
}
|
|
return false;
|
|
});
|
|
|
|
foreach (var file in files)
|
|
{
|
|
try
|
|
{
|
|
var lines = File.ReadAllLines(file);
|
|
if (lines.Length <= 1) continue; // Header only or empty
|
|
|
|
// CSV 헤더: Date,Time,Channel,ID,Value,Judgment,Mode,LineNo,ProductType,SpecUL,SpecLL,Retest
|
|
for (int i = 1; i < lines.Length; i++)
|
|
{
|
|
string line = lines[i];
|
|
if (string.IsNullOrWhiteSpace(line)) continue;
|
|
var parts = line.Split(',');
|
|
if (parts.Length < 12) continue;
|
|
|
|
string date = parts[0].Trim();
|
|
string time = parts[1].Trim();
|
|
string channel = parts[2].Trim();
|
|
string id = parts[3].Trim();
|
|
string val = parts[4].Trim();
|
|
string judg = parts[5].Trim();
|
|
string mode = parts[6].Trim();
|
|
string lineNo = parts[7].Trim();
|
|
string prodType = parts[8].Trim();
|
|
string specUl = parts[9].Trim();
|
|
string specLl = parts[10].Trim();
|
|
string retest = parts[11].Trim();
|
|
|
|
// 필터 적용
|
|
if (judgmentFilter != "[전체]" && judg != judgmentFilter) continue;
|
|
if (!string.IsNullOrEmpty(serialFilter) && !id.Contains(serialFilter)) continue;
|
|
|
|
results.Add(new InspectData
|
|
{
|
|
InspectDate = date,
|
|
InspectTime = time,
|
|
Channel = channel,
|
|
ProductId = id,
|
|
MeasuredValue = val,
|
|
Judgment = judg,
|
|
Mode = mode,
|
|
LineNo = lineNo,
|
|
ProductType = prodType,
|
|
SpecUL = specUl,
|
|
SpecLL = specLl,
|
|
Retest = retest
|
|
});
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"[LogParser] Error reading file {file}: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
return results.OrderByDescending(r => r.InspectDate).ThenByDescending(r => r.InspectTime).ToList();
|
|
}
|
|
}
|
|
}
|
|
|