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:
109
ReportingServices.Shared/HelperClasses/APIHelperFunctions.cs
Normal file
109
ReportingServices.Shared/HelperClasses/APIHelperFunctions.cs
Normal file
@ -0,0 +1,109 @@
|
||||
using System.Web;
|
||||
|
||||
namespace ReportingServices.Shared.HelperClasses
|
||||
{
|
||||
public static class APIHelperFunctions
|
||||
{
|
||||
private readonly static string fabTimeServer = "http://messa004.infineon.com/fabtime717service/GetChartData.aspx?";
|
||||
|
||||
public static string GetBeginningOfWeekAsAPIString()
|
||||
{
|
||||
DateTime date = DateTime.Now;
|
||||
|
||||
int dayOfWeek = (int)date.DayOfWeek;
|
||||
|
||||
date = dayOfWeek switch
|
||||
{
|
||||
0 => date.AddDays(-6),
|
||||
1 => date.AddDays(-7),
|
||||
_ => 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 Dictionary<string, string> SetParameters(string startDate = "", string endDate = "", string chart = "", string periodLen = "",
|
||||
string areasLike = "", string toolsLike = "", string operationsLike = "", string capacityTypesLike = "")
|
||||
{
|
||||
Dictionary<string, string> parameters = new();
|
||||
|
||||
startDate = startDate == "" ? HttpUtility.UrlEncode(GetBeginningOfWeekAsAPIString()) : startDate;
|
||||
endDate = endDate == "" ? HttpUtility.UrlEncode(GetDateTimeAsAPIString(DateTime.Now.ToString(), true)) : endDate;
|
||||
|
||||
parameters.Add("chart", chart);
|
||||
parameters.Add("starttime", startDate);
|
||||
parameters.Add("endtime", endDate);
|
||||
parameters.Add("periodlen", periodLen);
|
||||
parameters.Add("areaslike", areasLike);
|
||||
parameters.Add("toolslike", toolsLike);
|
||||
parameters.Add("operationslike", operationsLike);
|
||||
parameters.Add("capacitytypeslike", capacityTypesLike);
|
||||
parameters.Add("login", "administrator");
|
||||
parameters.Add("password", "admin");
|
||||
parameters.Add("fabtimeauthentication", "1");
|
||||
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public static string GenerateURL(Dictionary<string, string> parameters)
|
||||
{
|
||||
int count = 0;
|
||||
string url = fabTimeServer;
|
||||
|
||||
foreach (KeyValuePair<string, string> pair in parameters)
|
||||
{
|
||||
if (pair.Value != "")
|
||||
url = url + pair.Key + "=" + pair.Value;
|
||||
|
||||
if (count != parameters.Count - 1 && !string.IsNullOrEmpty(pair.Value))
|
||||
url += "&";
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
public static string GenerateURLWithParameters(string startDate = "", string endDate = "", string chart = "", string periodLen = "",
|
||||
string areasLike = "", string toolsLike = "", string operationsLike = "", string capacityTypesLike = "")
|
||||
{
|
||||
Dictionary<string, string> parameters = SetParameters(startDate, endDate, chart,
|
||||
periodLen, areasLike, toolsLike, operationsLike, capacityTypesLike);
|
||||
|
||||
return GenerateURL(parameters);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
22
ReportingServices.Shared/HelperClasses/ApiCaller.cs
Normal file
22
ReportingServices.Shared/HelperClasses/ApiCaller.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using ReportingServices.Shared.Models.ProductionReport;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ReportingServices.Shared.HelperClasses
|
||||
{
|
||||
public static class ApiCaller
|
||||
{
|
||||
public static async Task<T> GetApi<T>(string url)
|
||||
{
|
||||
T deserializedJson;
|
||||
|
||||
using (HttpClient client = new())
|
||||
{
|
||||
string apiResponse = await client.GetStringAsync(url);
|
||||
deserializedJson = JsonSerializer.Deserialize<T>(apiResponse);
|
||||
}
|
||||
|
||||
return deserializedJson;
|
||||
}
|
||||
}
|
||||
}
|
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;
|
||||
}
|
||||
}
|
||||
}
|
19
ReportingServices.Shared/HelperClasses/JsonFileHandler.cs
Normal file
19
ReportingServices.Shared/HelperClasses/JsonFileHandler.cs
Normal file
@ -0,0 +1,19 @@
|
||||
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);
|
||||
}
|
||||
|
||||
public static void SaveJSONFile<T>(T obj, string file)
|
||||
{
|
||||
string json = JsonSerializer.Serialize(obj);
|
||||
File.WriteAllText(file, json);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user