Moved API and DB methods to interfaces in order to leverage Dependency Injection, disolved APICaller class, including functionality in several other functions, included Single Load Lock information into Production Passdown report, changed persistant data file to json instead of xml, and adjusted persistant data file to include a week's worth of data instead of a single day.
This commit is contained in:
111
ReportingServices/HelperClasses/APIHelperFunctions.cs
Normal file
111
ReportingServices/HelperClasses/APIHelperFunctions.cs
Normal file
@ -0,0 +1,111 @@
|
||||
using ReportingServices.Dependency_Injections;
|
||||
using ReportingServices.ReportingObjects;
|
||||
using System.Web;
|
||||
|
||||
namespace ReportingServices.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.Year + "-" + date.Month + "-" + date.Day + " " + date.Hour + ":" + date.Minute + ":" + date.Second;
|
||||
else
|
||||
dateString = date.Year + "-" + date.Month + "-" + date.Day + " 0:0:0";
|
||||
|
||||
return dateString;
|
||||
}
|
||||
|
||||
public static Dictionary<string, string> SetParameters(string startDate = "", string chart = "", string periodLen = "",
|
||||
string areasLike = "", string toolsLike = "", string operationsLike = "", string capacityTypesLike = "")
|
||||
{
|
||||
Dictionary<string, string> parameters = new();
|
||||
|
||||
startDate = startDate == "" ? HttpUtility.UrlEncode(GetBeginningOfWeekAsAPIString()) : startDate;
|
||||
string endDate = HttpUtility.UrlEncode(GetDateTimeAsAPIString(DateTime.Now.ToString(), true));
|
||||
|
||||
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 chart = "", string periodLen = "",
|
||||
string areasLike = "", string toolsLike = "", string operationsLike = "", string capacityTypesLike = "")
|
||||
{
|
||||
Dictionary<string, string> parameters = SetParameters(startDate, 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,241 +0,0 @@
|
||||
using ReportingServices.ReportingObjects;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ReportingServices.HelperClasses
|
||||
{
|
||||
public class APICaller
|
||||
{
|
||||
public List<ReactorOutsByDay> OutsByDay { get; set; }
|
||||
public List<ScrapByDay> ScrapByDay { get; set; }
|
||||
public Dictionary<string, ToolAvailibilityByType> ToolAvailibilityByTypes { get; set; }
|
||||
public Dictionary<string, ToolStateByType> ToolStateByTypes { get; set; }
|
||||
|
||||
private readonly string fabTimeServer = "http://messa004.infineon.com/fabtime717service/GetChartData.aspx?";
|
||||
private Dictionary<string, string> Parameters = new();
|
||||
private readonly string toolFilter = "~R76%2C%20~R78%2C%20~R25%2C%20~R67%2C%20~R69%2C%20~R71%2C%20~R47%2C%20~R51%2C%20~R28";
|
||||
|
||||
public APICaller()
|
||||
{
|
||||
Parameters.Add("chart", "");
|
||||
Parameters.Add("starttime", DetermineStartDate());
|
||||
Parameters.Add("endtime", DetermineEndDate());
|
||||
Parameters.Add("periodlen", "");
|
||||
Parameters.Add("areaslike", "");
|
||||
Parameters.Add("toolsslike", "");
|
||||
Parameters.Add("operationslike", "");
|
||||
Parameters.Add("capacitytypeslike", "");
|
||||
Parameters.Add("login", "administrator");
|
||||
Parameters.Add("password", "admin");
|
||||
Parameters.Add("fabtimeauthentication", "1");
|
||||
|
||||
ToolAvailibilityByTypes = new();
|
||||
ToolStateByTypes = new();
|
||||
}
|
||||
|
||||
public void CallAllAPIs()
|
||||
{
|
||||
Task[] tasks = new Task[7];
|
||||
|
||||
tasks[0] = MovesTrendCaller();
|
||||
tasks[1] = ToolStateTrendCaller("ASM");
|
||||
tasks[2] = ToolStateTrendCaller("EPP");
|
||||
tasks[3] = ToolStateTrendCaller("HTR");
|
||||
tasks[4] = ToolStatesCaller("ASM");
|
||||
tasks[5] = ToolStatesCaller("EPP");
|
||||
tasks[6] = ToolStatesCaller("HTR");
|
||||
|
||||
Task.WaitAll(tasks);
|
||||
|
||||
ReverseLists();
|
||||
}
|
||||
|
||||
public async Task MovesTrendCaller()
|
||||
{
|
||||
Dictionary<string, string> parameters = Parameters;
|
||||
parameters["chart"] = "MOVESLOTLIST";
|
||||
parameters["areaslike"] = "CLEANROOM";
|
||||
parameters["operationslike"] = "1UNLOAD";
|
||||
|
||||
List<ReactorOutsByRDS> outsByDay = await GetJsonData<ReactorOutsByRDS>(GetAPIURL(parameters));
|
||||
|
||||
GetReactorOutsByDay(outsByDay);
|
||||
|
||||
DBCaller db = new();
|
||||
|
||||
ScrapByDay = db.GetScrap(outsByDay);
|
||||
}
|
||||
|
||||
public async Task ToolStateTrendCaller(string toolType)
|
||||
{
|
||||
Dictionary<string, string> parameters = Parameters;
|
||||
parameters["chart"] = "TOOLSTATE";
|
||||
parameters["periodlen"] = "24";
|
||||
parameters["capacitytypeslike"] = toolType;
|
||||
parameters["toolslike"] = toolFilter;
|
||||
|
||||
List<EquipmentStateByDay> toolAvailability = await GetJsonData<EquipmentStateByDay>(GetAPIURL(parameters));
|
||||
|
||||
ToolAvailibilityByTypes.Add(toolType, new ToolAvailibilityByType(toolAvailability));
|
||||
}
|
||||
|
||||
public async Task ToolStatesCaller(string toolType)
|
||||
{
|
||||
Dictionary<string, string> parameters = Parameters;
|
||||
parameters["starttime"] = DetermineStartDate(DateTime.Now.ToString(), 12.5f);
|
||||
parameters["chart"] = "ToolStateGantt";
|
||||
parameters["periodlen"] = "24";
|
||||
parameters["capacitytypeslike"] = toolType == "ASM" ? toolType + "%2CASM%2B" : toolType;
|
||||
parameters["toolslike"] = toolFilter;
|
||||
|
||||
List<ToolStateCurrent> toolStates = await GetJsonData<ToolStateCurrent>(GetAPIURL(parameters));
|
||||
|
||||
ToolStateByTypes.Add(toolType, new ToolStateByType(toolStates));
|
||||
}
|
||||
|
||||
private async Task<List<T>> GetJsonData<T>(string url)
|
||||
{
|
||||
List<T> deserializedJson;
|
||||
|
||||
using (var httpClient = new HttpClient())
|
||||
{
|
||||
using (var response = await httpClient.GetAsync(url))
|
||||
{
|
||||
string apiResponse = await response.Content.ReadAsStringAsync();
|
||||
deserializedJson = JsonSerializer.Deserialize<List<T>>(apiResponse);
|
||||
}
|
||||
}
|
||||
|
||||
return deserializedJson;
|
||||
}
|
||||
|
||||
public string DetermineStartDate(string date = null)
|
||||
{
|
||||
if (!DateTime.TryParse(date, out DateTime startDate))
|
||||
startDate = DateTime.Now.Date;
|
||||
|
||||
int dayOfWeek = (int)startDate.DayOfWeek;
|
||||
|
||||
switch (dayOfWeek)
|
||||
{
|
||||
case 0:
|
||||
startDate = startDate.AddDays(-6);
|
||||
break;
|
||||
case 1:
|
||||
startDate = startDate.AddDays(-7);
|
||||
break;
|
||||
case 2:
|
||||
startDate = startDate.AddDays(-1);
|
||||
break;
|
||||
case 3:
|
||||
startDate = startDate.AddDays(-2);
|
||||
break;
|
||||
case 4:
|
||||
startDate = startDate.AddDays(-3);
|
||||
break;
|
||||
case 5:
|
||||
startDate = startDate.AddDays(-4);
|
||||
break;
|
||||
case 6:
|
||||
startDate = startDate.AddDays(-5);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return startDate.Year + "-" + startDate.Month + "-" + startDate.Day + "%200%3A0%3A0";
|
||||
}
|
||||
|
||||
public string DetermineStartDate(string date, float numberOfHours)
|
||||
{
|
||||
DateTime startDate = DateTime.Parse(date);
|
||||
|
||||
startDate = startDate.AddHours(-numberOfHours);
|
||||
|
||||
return startDate.Year + "-" + startDate.Month + "-" + startDate.Day + "%20" + startDate.Hour + "%3A" + startDate.Minute + "%3A" + startDate.Second;
|
||||
}
|
||||
|
||||
public string DetermineEndDate(string date = null)
|
||||
{
|
||||
if (!DateTime.TryParse(date, out DateTime endDate))
|
||||
endDate = DateTime.Now;
|
||||
|
||||
return endDate.Year + "-" + endDate.Month + "-" + endDate.Day + "%20" + endDate.Hour + "%3A" + endDate.Minute + "%3A" + endDate.Second;
|
||||
}
|
||||
|
||||
public string GetAPIURL(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 = url + "&";
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
public void GetReactorOutsByDay(List<ReactorOutsByRDS> outs)
|
||||
{
|
||||
List<ReactorOutsByDay> outsByDay = new();
|
||||
|
||||
List<string> dates = GetDistinctDates(outs);
|
||||
|
||||
foreach (string date in dates)
|
||||
{
|
||||
int waferCount = 0;
|
||||
|
||||
foreach (ReactorOutsByRDS rout in outs)
|
||||
{
|
||||
if (DateTime.Parse(rout.EndProcessTime).Date.ToString() == date)
|
||||
waferCount += (int)float.Parse(rout.Units);
|
||||
}
|
||||
|
||||
outsByDay.Add(new ReactorOutsByDay(date, waferCount));
|
||||
}
|
||||
|
||||
OutsByDay = outsByDay;
|
||||
}
|
||||
|
||||
public List<string> GetDistinctDates(List<ReactorOutsByRDS> outs)
|
||||
{
|
||||
List<string> dates = new();
|
||||
|
||||
foreach (ReactorOutsByRDS rout in outs)
|
||||
{
|
||||
if (!dates.Contains(DateTime.Parse(rout.EndProcessTime).Date.ToString()))
|
||||
dates.Add(DateTime.Parse(rout.EndProcessTime).Date.ToString());
|
||||
}
|
||||
|
||||
return dates;
|
||||
}
|
||||
|
||||
public void ReverseLists()
|
||||
{
|
||||
List<ScrapByDay> temp2 = new();
|
||||
|
||||
for (int i = ScrapByDay.Count - 1; i >= 0; i--)
|
||||
{
|
||||
temp2.Add(ScrapByDay[i]);
|
||||
}
|
||||
|
||||
ScrapByDay = temp2;
|
||||
|
||||
foreach (KeyValuePair<string, ToolAvailibilityByType> keyValuePair in ToolAvailibilityByTypes)
|
||||
{
|
||||
List<EquipmentStateByDay> temp3 = new();
|
||||
|
||||
for (int i = keyValuePair.Value.EquipmentStates.Count - 1; i >= 0; i--)
|
||||
{
|
||||
temp3.Add(keyValuePair.Value.EquipmentStates[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,134 +0,0 @@
|
||||
using System.Data;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using ReportingServices.Models.PlanningReport;
|
||||
using ReportingServices.ReportingObjects;
|
||||
|
||||
namespace ReportingServices.HelperClasses
|
||||
{
|
||||
public class DBCaller
|
||||
{
|
||||
private SqlConnection _connection;
|
||||
|
||||
public void OpenConnection()
|
||||
{
|
||||
if (_connection == null || _connection.State == ConnectionState.Closed)
|
||||
{
|
||||
_connection = new SqlConnection("Server=Messv01ec.ec.local\\PROD1,53959;Database=LSL2SQL;User Id=srpadmin;Password=0okm9ijn;TrustServerCertificate=true");
|
||||
_connection.Open();
|
||||
}
|
||||
}
|
||||
|
||||
public void CloseConnection()
|
||||
{
|
||||
if (_connection.State != ConnectionState.Closed)
|
||||
_connection.Close();
|
||||
}
|
||||
|
||||
public List<ScrapByDay> GetScrap(List<ReactorOutsByRDS> outs)
|
||||
{
|
||||
List<ScrapByDay> scrap = new();
|
||||
string rdsNumbers = "";
|
||||
|
||||
foreach (ReactorOutsByRDS rout in outs)
|
||||
rdsNumbers = rdsNumbers + "'" + rout.RDS_NO + "', ";
|
||||
|
||||
rdsNumbers = rdsNumbers.Substring(0, rdsNumbers.Length - 2);
|
||||
|
||||
OpenConnection();
|
||||
|
||||
SqlCommand cmd = _connection.CreateCommand();
|
||||
|
||||
try
|
||||
{
|
||||
string query = "SELECT " +
|
||||
" DATE_OUT," +
|
||||
" SUM(CUST_TOT_REJ) AS TOT_REJ_CUST," +
|
||||
" SUM(LSL_TOT_REJ) AS TOT_REJ_MANU," +
|
||||
" SUM(TW_PROD) AS TW_PROD " +
|
||||
"FROM RDS " +
|
||||
"WHERE SEQ IN (" + rdsNumbers + ") " +
|
||||
"GROUP BY DATE_OUT " +
|
||||
"ORDER BY 1 DESC";
|
||||
|
||||
cmd.CommandText = query;
|
||||
|
||||
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
while (reader.Read() && reader[0].ToString() != "1/1/1900 12:00:00 AM")
|
||||
scrap.Add(new ScrapByDay(reader[0].ToString(), reader[3].ToString(), reader[1].ToString(), reader[2].ToString()));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
cmd.Dispose();
|
||||
|
||||
CloseConnection();
|
||||
|
||||
return scrap;
|
||||
}
|
||||
|
||||
public List<WeeklyPartChanges> GetWeeklyPartChanges(string startDate, string endDate)
|
||||
{
|
||||
List<WeeklyPartChanges> weeklyPartChanges = new();
|
||||
|
||||
OpenConnection();
|
||||
|
||||
SqlCommand cmd = _connection.CreateCommand();
|
||||
|
||||
string query = "SELECT REACTOR, PROD_SPEC_ID, COUNT(WO) FROM RDS " +
|
||||
"WHERE DATE_OUT BETWEEN @startDate AND @endDate " +
|
||||
"GROUP BY REACTOR, PROD_SPEC_ID " +
|
||||
"ORDER BY 1";
|
||||
|
||||
cmd.CommandText = query;
|
||||
cmd.Parameters.AddWithValue("@startDate", startDate);
|
||||
cmd.Parameters.AddWithValue("@endDate", endDate);
|
||||
|
||||
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
weeklyPartChanges.Add(new WeeklyPartChanges(reader[0].ToString(), reader[1].ToString(), int.Parse(reader[2].ToString())));
|
||||
}
|
||||
|
||||
cmd.Dispose();
|
||||
|
||||
CloseConnection();
|
||||
|
||||
return weeklyPartChanges;
|
||||
}
|
||||
|
||||
public int GetNumberOfPartChanges(string startDate, string endDate)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
OpenConnection();
|
||||
|
||||
SqlCommand cmd = _connection.CreateCommand();
|
||||
|
||||
string query = "SELECT COUNT(*) FROM " +
|
||||
"(SELECT REACTOR, COUNT(PROD_SPEC_ID) - 1 AS PCHANGE FROM " +
|
||||
"(SELECT REACTOR, PROD_SPEC_ID, COUNT(WO) AS PSN_COUNT FROM RDS WHERE DATE_OUT BETWEEN @startDate AND @endDate GROUP BY REACTOR, PROD_SPEC_ID) AS t " +
|
||||
"GROUP BY REACTOR) AS l WHERE PCHANGE > 0";
|
||||
|
||||
cmd.CommandText = query;
|
||||
cmd.Parameters.AddWithValue("@startDate", startDate);
|
||||
cmd.Parameters.AddWithValue("@endDate", endDate);
|
||||
|
||||
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
reader.Read();
|
||||
|
||||
result = int.Parse(reader[0].ToString());
|
||||
}
|
||||
|
||||
cmd.Dispose();
|
||||
|
||||
CloseConnection();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
using ReportingServices.ReportingObjects;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ReportingServices.HelperClasses
|
||||
{
|
||||
public class XMLReader
|
||||
{
|
||||
public void SaveJSONFile(DailyReportingSummary rpt)
|
||||
{
|
||||
string json = JsonSerializer.Serialize(rpt);
|
||||
File.WriteAllText("wwwroot/Assets/DailyReportInfo.json", json);
|
||||
}
|
||||
|
||||
public DailyReportingSummary LoadJSONFile()
|
||||
{
|
||||
string json = File.ReadAllText("wwwroot/Assets/DailyReportInfo.json");
|
||||
return JsonSerializer.Deserialize<DailyReportingSummary>(json);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user