Added backend API project to segregate responsibilites - Data is now handled in API project and business is all handled in UI project.
This commit is contained in:
92
ReportingServices.Shared/HelperClasses/DailyReportHelper.cs
Normal file
92
ReportingServices.Shared/HelperClasses/DailyReportHelper.cs
Normal file
@ -0,0 +1,92 @@
|
||||
using ReportingServices.Shared.Repositories;
|
||||
using ReportingServices.Shared.Models.ProductionReport;
|
||||
using ReportingServices.Shared.ViewModels.ProductionReport;
|
||||
|
||||
namespace ReportingServices.Shared.HelperClasses
|
||||
{
|
||||
public static class DailyReportHelper
|
||||
{
|
||||
private static IFabTimeReportingRepository _fabTimeReportingRepository;
|
||||
private static IScrapeDatabaseRepository _scrapeDatabaseRepository;
|
||||
private static readonly string _dailyRptFilePath = "wwwroot/Assets/DailyReportInfo.json";
|
||||
private static readonly string _baseUrlFabtime = "https://localhost:7196/api/FabTime/";
|
||||
|
||||
public static void SetRepositories(IFabTimeReportingRepository fabTimeReportingRepository, IScrapeDatabaseRepository scrapeDatabaseRepository)
|
||||
{
|
||||
_fabTimeReportingRepository = fabTimeReportingRepository;
|
||||
_scrapeDatabaseRepository = scrapeDatabaseRepository;
|
||||
}
|
||||
|
||||
public async static Task<DailyReport> SetUpDailyReport()
|
||||
{
|
||||
List<Task<List<EquipmentStateByDay>>> tasksEQState = new();
|
||||
List<Task<List<ToolStateCurrent>>> tasksState = new();
|
||||
DailyReport report = new();
|
||||
|
||||
Task<YieldInformation> task1 = ApiCaller.GetApi<YieldInformation>(_baseUrlFabtime + "ReactorOuts?startDate=" + report.StartDate.ToString() + "&endDate=" + DateTime.Now.ToString());
|
||||
Task<YieldInformation> task2 = ApiCaller.GetApi<YieldInformation>(_baseUrlFabtime + "ReactorOuts?startDate=" + report.StartDate.AddDays(-7).ToString() + "&endDate=" + report.StartDate.ToString());
|
||||
|
||||
tasksEQState.Add(ApiCaller.GetApi<List<EquipmentStateByDay>>(_baseUrlFabtime + "ToolStateTrend?toolType=ASM"));
|
||||
tasksEQState.Add(ApiCaller.GetApi<List<EquipmentStateByDay>>(_baseUrlFabtime + "ToolStateTrend?toolType=EPP"));
|
||||
tasksEQState.Add(ApiCaller.GetApi<List<EquipmentStateByDay>>(_baseUrlFabtime + "ToolStateTrend?toolType=HTR"));
|
||||
tasksState.Add(ApiCaller.GetApi<List<ToolStateCurrent>>(_baseUrlFabtime + "ToolState?toolType=ASM"));
|
||||
tasksState.Add(ApiCaller.GetApi<List<ToolStateCurrent>>(_baseUrlFabtime + "ToolState?toolType=EPP"));
|
||||
tasksState.Add(ApiCaller.GetApi<List<ToolStateCurrent>>(_baseUrlFabtime + "ToolState?toolType=HTR"));
|
||||
tasksState.Add(ApiCaller.GetApi<List<ToolStateCurrent>>(_baseUrlFabtime + "ToolState?toolType=Metrology"));
|
||||
tasksState.Add(ApiCaller.GetApi<List<ToolStateCurrent>>(_baseUrlFabtime + "ToolState?toolType=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());
|
||||
|
||||
report.AddToolAvailibilityByType("ASM", tasksEQState[0].Result);
|
||||
report.AddToolAvailibilityByType("EPP", tasksEQState[1].Result);
|
||||
report.AddToolAvailibilityByType("HTR", tasksEQState[2].Result);
|
||||
|
||||
report.AddToolStateByType("ASM", tasksState[0].Result);
|
||||
report.AddToolStateByType("EPP", tasksState[1].Result);
|
||||
report.AddToolStateByType("HTR", tasksState[2].Result);
|
||||
report.AddToolStateByType("Metrology", tasksState[3].Result);
|
||||
report.AddToolStateByType("Cleans", tasksState[4].Result);
|
||||
|
||||
report.SetReactorInfo(_scrapeDatabaseRepository.GetReactors(), GetUnscheduledReactors(report));
|
||||
|
||||
report.CurrentWeek.SetYieldInformation(task1.Result);
|
||||
report.PreviousWeek.SetYieldInformation(task2.Result);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user