Refactored code, restructured project organization, and added new unit tests.

This commit is contained in:
Daniel Wathen
2022-12-13 12:11:28 -07:00
parent 8f96e31121
commit b5def3da89
33 changed files with 670 additions and 418 deletions

View File

@ -0,0 +1,84 @@
using ReportingServices.Dependency_Injections;
using ReportingServices.Models.ProductionReport;
using ReportingServices.ViewModels.ProductionReport;
namespace ReportingServices.HelperClasses
{
public static class DailyReportHelper
{
private static IFabTimeReportingRepository _fabTimeReportingRepository;
private static IScrapeDatabaseRepository _scrapeDatabaseRepository;
private static readonly string _dailyRptFilePath = "wwwroot/Assets/DailyReportInfo.json";
public static void SetRepositories(IFabTimeReportingRepository fabTimeReportingRepository, IScrapeDatabaseRepository scrapeDatabaseRepository)
{
_fabTimeReportingRepository = fabTimeReportingRepository;
_scrapeDatabaseRepository = scrapeDatabaseRepository;
}
public static DailyReport SetUpDailyReport()
{
List<Task> tasks = new();
DailyReport report = new();
Task<List<ReactorOutsByRDS>> task1 = _fabTimeReportingRepository.GetMovesTrendData();
Task<List<ReactorOutsByRDS>> task2 = _fabTimeReportingRepository.GetMovesTrendData(startDate: report.StartDate.AddDays(-7).ToString(), endDate: report.StartDate.ToString());
tasks.Add(_fabTimeReportingRepository.GetToolStateTrendData(report, "ASM"));
tasks.Add(_fabTimeReportingRepository.GetToolStateTrendData(report, "EPP"));
tasks.Add(_fabTimeReportingRepository.GetToolStateTrendData(report, "HTR"));
tasks.Add(_fabTimeReportingRepository.GetToolStateData(report, "ASM"));
tasks.Add(_fabTimeReportingRepository.GetToolStateData(report, "EPP"));
tasks.Add(_fabTimeReportingRepository.GetToolStateData(report, "HTR"));
tasks.Add(_fabTimeReportingRepository.GetToolStateData(report, "Metrology"));
tasks.Add(_fabTimeReportingRepository.GetToolStateData(report, "Cleans"));
report.QuarterlyTargets = _scrapeDatabaseRepository.GetQuarterlyTargets();
Dictionary<string, List<ManualReportEntries>> entries = JsonFileHandler.LoadJSONFile<Dictionary<string, List<ManualReportEntries>>>(_dailyRptFilePath);
report.CurrentEntries = entries["Current Week"];
report.PreviousEntries = entries["Previous Week"];
report.SetRDSInfo(_scrapeDatabaseRepository.GetRDSForLastDay());
Task.WaitAll(tasks.ToArray());
report.SetReactorInfo(_scrapeDatabaseRepository.GetReactors(), GetUnscheduledReactors(report));
List<ScrapByDay> scrap = _scrapeDatabaseRepository.GetScrapByDay(task1.Result);
List<ScrapByDay> previousScrap = _scrapeDatabaseRepository.GetScrapByDay(task2.Result);
report.CurrentWeek.SetYieldInformation(task1.Result, scrap);
report.PreviousWeek.SetYieldInformation(task2.Result, previousScrap);
report.ReverseLists();
entries["Current Week"] = report.CurrentEntries;
JsonFileHandler.SaveJSONFile(entries, _dailyRptFilePath);
return report;
}
public static List<int> GetUnscheduledReactors(DailyReport report)
{
List<int> reactors = new();
foreach (KeyValuePair<string, ToolStateByType> keyValuePairs in report.ToolStateByType)
{
if (keyValuePairs.Key != "Metrology" && keyValuePairs.Key != "Cleans")
{
foreach (ToolStateCurrent tool in keyValuePairs.Value.ToolStateCurrents)
{
if (tool.BasicStateDescription != "Productive" && tool.ReactorStatus != "Out of Service")
{
reactors.Add(int.Parse(tool.Tool.Substring(1)));
}
}
}
}
return reactors;
}
}
}

View File

@ -0,0 +1,19 @@
using System.Text.Json;
namespace ReportingServices.HelperClasses
{
public static class JsonFileHandler
{
public static T LoadJSONFile<T>(string file)
{
string json = File.ReadAllText(file);
return JsonSerializer.Deserialize<T>(json);
}
public static void SaveJSONFile<T>(T obj, string file)
{
string json = JsonSerializer.Serialize(obj);
File.WriteAllText(file, json);
}
}
}