Ran formatting through code

This commit is contained in:
Daniel Wathen
2023-01-12 13:19:05 -07:00
parent ba6d7b19e7
commit 8d65b82af6
37 changed files with 2006 additions and 1823 deletions

View File

@ -1,56 +1,53 @@
using System.Web;
namespace ReportingServices.Shared.HelperClasses;
namespace ReportingServices.Shared.HelperClasses
public static class APIHelperFunctions
{
public static class APIHelperFunctions
public static string GetBeginningOfWeekAsAPIString()
{
public static string GetBeginningOfWeekAsAPIString()
DateTime date = DateTime.Now;
int dayOfWeek = (int)date.DayOfWeek;
date = dayOfWeek switch
{
DateTime date = DateTime.Now;
0 => date.AddDays(-6),
1 => date,
_ => date.AddDays(1 - dayOfWeek)
};
int dayOfWeek = (int)date.DayOfWeek;
date = dayOfWeek switch
{
0 => date.AddDays(-6),
1 => date,
_ => date.AddDays(1 - dayOfWeek)
};
return GetDateTimeAsAPIString(date.ToString(), false);
}
public static string GetDateWithOffsetAsAPIString(string dateString, float offset)
{
DateTime date = DateTime.Parse(dateString);
date = date.AddHours(offset);
return GetDateTimeAsAPIString(date.ToString(), true);
}
public static string GetDateTimeAsAPIString(string dateString, bool fullDateTime)
{
DateTime date = DateTime.Parse(dateString);
if (fullDateTime)
dateString = date.ToString("yyyy-M-d HH:mm:ss");
else
dateString = date.Year + "-" + date.Month + "-" + date.Day + " 0:0:0";
return dateString;
}
public static List<T> ReverseList<T>(List<T> inputList)
{
List<T> temp = new();
for (int i = inputList.Count - 1; i >= 0; i--)
{
temp.Add(inputList[i]);
}
return temp;
}
return GetDateTimeAsAPIString(date.ToString(), false);
}
}
public static string GetDateWithOffsetAsAPIString(string dateString, float offset)
{
DateTime date = DateTime.Parse(dateString);
date = date.AddHours(offset);
return GetDateTimeAsAPIString(date.ToString(), true);
}
public static string GetDateTimeAsAPIString(string dateString, bool fullDateTime)
{
DateTime date = DateTime.Parse(dateString);
if (fullDateTime)
dateString = date.ToString("yyyy-M-d HH:mm:ss");
else
dateString = date.Year + "-" + date.Month + "-" + date.Day + " 0:0:0";
return dateString;
}
public static List<T> ReverseList<T>(List<T> inputList)
{
List<T> temp = new();
for (int i = inputList.Count - 1; i >= 0; i--)
{
temp.Add(inputList[i]);
}
return temp;
}
}

View File

@ -1,22 +1,19 @@
using ReportingServices.Shared.Models.ProductionReport;
using System.Net.Http.Json;
using System.Text.Json;
using System.Text.Json;
namespace ReportingServices.Shared.HelperClasses
namespace ReportingServices.Shared.HelperClasses;
public static class ApiCaller
{
public static class ApiCaller
public static async Task<T> GetApi<T>(string url)
{
public static async Task<T> GetApi<T>(string url)
T deserializedJson = default;
using (HttpClient client = new())
{
T deserializedJson = default(T);
using (HttpClient client = new())
{
string apiResponse = await client.GetStringAsync(url);
deserializedJson = JsonSerializer.Deserialize<T>(apiResponse);
}
return deserializedJson;
string apiResponse = await client.GetStringAsync(url);
deserializedJson = JsonSerializer.Deserialize<T>(apiResponse);
}
return deserializedJson;
}
}
}

View File

@ -2,181 +2,180 @@
using ReportingServices.Shared.Models.ProductionReport;
using ReportingServices.Shared.ViewModels.ProductionReport;
namespace ReportingServices.Shared.HelperClasses
namespace ReportingServices.Shared.HelperClasses;
public static class DailyReportHelper
{
public static class DailyReportHelper
private static readonly string _dailyRptFilePath = "wwwroot/Assets/DailyReportInfo.json";
private static readonly string _SLLFilePath = "wwwroot/Assets/SLLTools.json";
public static DailyReport SetUpDailyReport(ILogger logger, string baseUrlScrapeDb)
{
private static readonly string _dailyRptFilePath = "wwwroot/Assets/DailyReportInfo.json";
private static readonly string _SLLFilePath = "wwwroot/Assets/SLLTools.json";
DailyReport report = new();
public static DailyReport SetUpDailyReport(ILogger logger, string baseUrlScrapeDb)
try
{
DailyReport report = new();
report.SLLTools = JsonFileHandler.LoadJSONFile<List<SLLTool>>(_SLLFilePath);
report.ManualReportEntries = JsonFileHandler.LoadJSONFile<ManualReportEntries>(_dailyRptFilePath);
try
{
report.SLLTools = JsonFileHandler.LoadJSONFile<List<SLLTool>>(_SLLFilePath);
report.ManualReportEntries = JsonFileHandler.LoadJSONFile<ManualReportEntries>(_dailyRptFilePath);
}
catch (Exception ex)
{
logger.LogError(ex, "Failed to load JsonFiles.");
logger.LogInformation("SLL File Path: {path}", _SLLFilePath);
logger.LogInformation("Manual Report Entries File Path: {path}", _dailyRptFilePath);
}
List<string> cleanTools = new()
{
"AHPS",
"AKRION1",
"CB3",
"MES",
"SRD 1",
"SRD 2"
};
List<string> metrologyTools = new()
{
"ASET",
"BIORAD2",
"BIORAD3",
"BIORAD4",
"BIORAD5",
"CDE2",
"CDE3",
"CDE5",
"FLEXUS",
"HGCV1",
"HGCV2",
"HGCV3",
"SRP"
};
List<Reactor> reactors = new();
Dictionary<string, Task<int>> lastUpTransactions = new();
List<Task<List<ReactorEvent>>> toolEvents = new();
List<Task<ToolEvent>> cleanEvents = new();
List<Task<ToolEvent>> metrologyEvents = new();
Task<YieldInformation> task1 = null;
Task<YieldInformation> task2 = null;
Task<QuarterlyTargets> targets = null;
Task<List<RDS>> rds = null;
Task<DateTime> task3 = null;
Task<OutsAndScrapTotal> task4 = null;
try
{
reactors = ApiCaller.GetApi<List<Reactor>>(baseUrlScrapeDb + "Reactors").Result;
foreach (Reactor reactor in reactors)
{
toolEvents.Add(ApiCaller.GetApi<List<ReactorEvent>>(baseUrlScrapeDb + "ReactorEvents?startDate=" + report.StartDate.ToString() +
"&endDate=" + DateTime.Now.ToString() + "&reactorNumber=" + reactor.ReactorNumber + "&reactorType=" + reactor.Type));
lastUpTransactions.Add(reactor.ReactorNumber.ToString(),
ApiCaller.GetApi<int>(baseUrlScrapeDb + "GetLastUpTransaction?reactorNumber=" + reactor.ReactorNumber));
}
foreach (string tool in cleanTools)
{
cleanEvents.Add(ApiCaller.GetApi<ToolEvent>(baseUrlScrapeDb + "ToolEvents?toolID=" + tool));
}
foreach (string tool in metrologyTools)
{
metrologyEvents.Add(ApiCaller.GetApi<ToolEvent>(baseUrlScrapeDb + "ToolEvents?toolID=" + tool));
}
task1 = ApiCaller.GetApi<YieldInformation>(baseUrlScrapeDb + "ReactorOuts?startDate=" + report.StartDate.ToString() + "&endDate=" + DateTime.Now.ToString());
task2 = ApiCaller.GetApi<YieldInformation>(baseUrlScrapeDb + "ReactorOuts?startDate=" + report.StartDate.AddDays(-7).ToString() + "&endDate=" + report.StartDate.ToString());
task3 = ApiCaller.GetApi<DateTime>(baseUrlScrapeDb + "GetQuarterStartDate");
targets = ApiCaller.GetApi<QuarterlyTargets>(baseUrlScrapeDb + "Targets");
rds = ApiCaller.GetApi<List<RDS>>(baseUrlScrapeDb + "RDS?date=" + report.StartDate.ToString());
task4 = ApiCaller.GetApi<OutsAndScrapTotal>(baseUrlScrapeDb + "GetOutsAndScrapTotals?startDate=" + task3.Result + "&endDate=" + DateTime.Now.ToString());
}
catch (Exception ex)
{
logger.LogCritical(ex, "Failed to send get requests to scrapedb endpoints.");
}
try
{
report.QuarterlyTargets = targets.Result;
report.SetRDSInfo(rds.Result);
report.SetReactorInfo(reactors, GetUnscheduledReactors(report));
foreach (var task in toolEvents)
{
ToolEventView toolEvent = new(task.Result,
report.StartDate.ToString(), DateTime.Now.ToString(), task.Result[0].REACT_NO,
reactors.FirstOrDefault(x => x.ReactorNumber == int.Parse(task.Result[0].REACT_NO)).Type);
toolEvent.SetDowntime(lastUpTransactions[toolEvent.Reactor].Result);
report.ToolEvents.Add(toolEvent);
}
report.ToolEvents = report.ToolEvents
.Where(x => x.Reactor != "100" && x.Reactor != "101" && x.Reactor != "47")
.OrderBy(x => x.Reactor)
.ToList();
foreach (Task<ToolEvent> task in cleanEvents)
report.CleanEvents.Add(task.Result);
foreach (Task<ToolEvent> task in metrologyEvents)
report.MetrologyEvents.Add(task.Result);
report.CleanEvents = report.CleanEvents.Where(x => (x.TOOL_MODE != "PROD" || x.TOOL_MODE_DESC != "Production") && x.TOOL_MODE != "OUT").ToList();
report.MetrologyEvents = report.MetrologyEvents.Where(x => (x.TOOL_MODE != "PROD" || x.TOOL_MODE_DESC != "Production") && x.TOOL_MODE != "OUT").ToList();
report.CurrentWeek.SetYieldInformation(task1.Result, report.QuarterlyTargets);
report.PreviousWeek.SetYieldInformation(task2.Result, report.QuarterlyTargets);
report.QuarterStartDate = task3.Result;
report.CurrentWeek.QTDOutsAndScrap = task4.Result;
report.PreviousWeek.QTDOutsAndScrap = task4.Result;
}
catch (Exception ex)
{
logger.LogCritical(ex, "Failed to retrieve data back from Scrape DB endpoints.");
}
report.ReverseLists();
ManualReportEntries entries = report.ManualReportEntries;
List<SLLTool> sll = report.SLLTools;
try
{
JsonFileHandler.SaveJSONFile(entries, _dailyRptFilePath);
JsonFileHandler.SaveJSONFile(sll, _SLLFilePath);
}
catch (Exception ex)
{
logger.LogCritical(ex, "Failed to save data back to JSON files.");
}
return report;
}
catch (Exception ex)
{
logger.LogError(ex, "Failed to load JsonFiles.");
logger.LogInformation("SLL File Path: {path}", _SLLFilePath);
logger.LogInformation("Manual Report Entries File Path: {path}", _dailyRptFilePath);
}
public static List<int> GetUnscheduledReactors(DailyReport report)
List<string> cleanTools = new()
{
List<int> reactors = new();
"AHPS",
"AKRION1",
"CB3",
"MES",
"SRD 1",
"SRD 2"
};
foreach (ToolEventView tool in report.ToolEvents)
List<string> metrologyTools = new()
{
"ASET",
"BIORAD2",
"BIORAD3",
"BIORAD4",
"BIORAD5",
"CDE2",
"CDE3",
"CDE5",
"FLEXUS",
"HGCV1",
"HGCV2",
"HGCV3",
"SRP"
};
List<Reactor> reactors = new();
Dictionary<string, Task<int>> lastUpTransactions = new();
List<Task<List<ReactorEvent>>> toolEvents = new();
List<Task<ToolEvent>> cleanEvents = new();
List<Task<ToolEvent>> metrologyEvents = new();
Task<YieldInformation> task1 = null;
Task<YieldInformation> task2 = null;
Task<QuarterlyTargets> targets = null;
Task<List<RDS>> rds = null;
Task<DateTime> task3 = null;
Task<OutsAndScrapTotal> task4 = null;
try
{
reactors = ApiCaller.GetApi<List<Reactor>>(baseUrlScrapeDb + "Reactors").Result;
foreach (Reactor reactor in reactors)
{
if (!tool.IsInProduction)
{
reactors.Add(int.Parse(tool.Reactor));
}
toolEvents.Add(ApiCaller.GetApi<List<ReactorEvent>>(baseUrlScrapeDb + "ReactorEvents?startDate=" + report.StartDate.ToString() +
"&endDate=" + DateTime.Now.ToString() + "&reactorNumber=" + reactor.ReactorNumber + "&reactorType=" + reactor.Type));
lastUpTransactions.Add(reactor.ReactorNumber.ToString(),
ApiCaller.GetApi<int>(baseUrlScrapeDb + "GetLastUpTransaction?reactorNumber=" + reactor.ReactorNumber));
}
return reactors;
foreach (string tool in cleanTools)
{
cleanEvents.Add(ApiCaller.GetApi<ToolEvent>(baseUrlScrapeDb + "ToolEvents?toolID=" + tool));
}
foreach (string tool in metrologyTools)
{
metrologyEvents.Add(ApiCaller.GetApi<ToolEvent>(baseUrlScrapeDb + "ToolEvents?toolID=" + tool));
}
task1 = ApiCaller.GetApi<YieldInformation>(baseUrlScrapeDb + "ReactorOuts?startDate=" + report.StartDate.ToString() + "&endDate=" + DateTime.Now.ToString());
task2 = ApiCaller.GetApi<YieldInformation>(baseUrlScrapeDb + "ReactorOuts?startDate=" + report.StartDate.AddDays(-7).ToString() + "&endDate=" + report.StartDate.ToString());
task3 = ApiCaller.GetApi<DateTime>(baseUrlScrapeDb + "GetQuarterStartDate");
targets = ApiCaller.GetApi<QuarterlyTargets>(baseUrlScrapeDb + "Targets");
rds = ApiCaller.GetApi<List<RDS>>(baseUrlScrapeDb + "RDS?date=" + report.StartDate.ToString());
task4 = ApiCaller.GetApi<OutsAndScrapTotal>(baseUrlScrapeDb + "GetOutsAndScrapTotals?startDate=" + task3.Result + "&endDate=" + DateTime.Now.ToString());
}
catch (Exception ex)
{
logger.LogCritical(ex, "Failed to send get requests to scrapedb endpoints.");
}
try
{
report.QuarterlyTargets = targets.Result;
report.SetRDSInfo(rds.Result);
report.SetReactorInfo(reactors, GetUnscheduledReactors(report));
foreach (Task<List<ReactorEvent>> task in toolEvents)
{
ToolEventView toolEvent = new(task.Result,
report.StartDate.ToString(), DateTime.Now.ToString(), task.Result[0].REACT_NO,
reactors.FirstOrDefault(x => x.ReactorNumber == int.Parse(task.Result[0].REACT_NO)).Type);
toolEvent.SetDowntime(lastUpTransactions[toolEvent.Reactor].Result);
report.ToolEvents.Add(toolEvent);
}
report.ToolEvents = report.ToolEvents
.Where(x => x.Reactor is not "100" and not "101" and not "47")
.OrderBy(x => x.Reactor)
.ToList();
foreach (Task<ToolEvent> task in cleanEvents)
report.CleanEvents.Add(task.Result);
foreach (Task<ToolEvent> task in metrologyEvents)
report.MetrologyEvents.Add(task.Result);
report.CleanEvents = report.CleanEvents.Where(x => (x.TOOL_MODE != "PROD" || x.TOOL_MODE_DESC != "Production") && x.TOOL_MODE != "OUT").ToList();
report.MetrologyEvents = report.MetrologyEvents.Where(x => (x.TOOL_MODE != "PROD" || x.TOOL_MODE_DESC != "Production") && x.TOOL_MODE != "OUT").ToList();
report.CurrentWeek.SetYieldInformation(task1.Result, report.QuarterlyTargets);
report.PreviousWeek.SetYieldInformation(task2.Result, report.QuarterlyTargets);
report.QuarterStartDate = task3.Result;
report.CurrentWeek.QTDOutsAndScrap = task4.Result;
report.PreviousWeek.QTDOutsAndScrap = task4.Result;
}
catch (Exception ex)
{
logger.LogCritical(ex, "Failed to retrieve data back from Scrape DB endpoints.");
}
report.ReverseLists();
ManualReportEntries entries = report.ManualReportEntries;
List<SLLTool> sll = report.SLLTools;
try
{
JsonFileHandler.SaveJSONFile(entries, _dailyRptFilePath);
JsonFileHandler.SaveJSONFile(sll, _SLLFilePath);
}
catch (Exception ex)
{
logger.LogCritical(ex, "Failed to save data back to JSON files.");
}
return report;
}
}
public static List<int> GetUnscheduledReactors(DailyReport report)
{
List<int> reactors = new();
foreach (ToolEventView tool in report.ToolEvents)
{
if (!tool.IsInProduction)
{
reactors.Add(int.Parse(tool.Reactor));
}
}
return reactors;
}
}

View File

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