diff --git a/ReportingServices.Test/UnitTest1.cs b/ReportingServices.Test/UnitTest1.cs index 4524ab4..493879d 100644 --- a/ReportingServices.Test/UnitTest1.cs +++ b/ReportingServices.Test/UnitTest1.cs @@ -6,55 +6,39 @@ namespace ReportingServices.Test public class UnitTest1 { [TestMethod] - public void CheckAPIIsNotNull() + public void CheckShortDateWithPassedInDate() { // Arrange - APICaller apiCaller = new APICaller(); + string date = DateTime.Now.ToString("yyyy-M-d") + " 0:0:0"; // Act - apiCaller.CallAllAPIs(); + string callerDate = APIHelperFunctions.GetDateTimeAsAPIString(DateTime.Now.ToString(), false); // Assert - Assert.IsNotNull(apiCaller); + Assert.AreEqual(date, callerDate); + } + + [TestMethod] + public void CheckFullDateWithPassedInDate() + { + // Arrange + string date = DateTime.Now.ToString("yyyy-M-d HH:mm:ss"); + + // Act + string callerDate = APIHelperFunctions.GetDateTimeAsAPIString(DateTime.Now.ToString(), true); + + // Assert + Assert.AreEqual(date, callerDate); } [TestMethod] public void CheckStartDateForWeekNow() { // Arrange - APICaller apiCaller = new APICaller(); string date = DetermineDate(); // Act - string callerDate = apiCaller.DetermineStartDate(); - - // Assert - Assert.AreEqual(date, callerDate); - } - - [TestMethod] - public void CheckStartDateForWeekWednesday() - { - // Arrange - APICaller apiCaller = new APICaller(); - string date = "2022-11-21%200%3A0%3A0"; - - // Act - string callerDate = apiCaller.DetermineStartDate("11/23/2022"); - - // Assert - Assert.AreEqual(date, callerDate); - } - - [TestMethod] - public void CheckStartDateForWeekMonday() - { - // Arrange - APICaller apiCaller = new APICaller(); - string date = "2022-11-14%200%3A0%3A0"; - - // Act - string callerDate = apiCaller.DetermineStartDate("11/21/2022"); + string callerDate = APIHelperFunctions.GetBeginningOfWeekAsAPIString(); // Assert Assert.AreEqual(date, callerDate); @@ -64,11 +48,10 @@ namespace ReportingServices.Test public void CheckStartDateForDayPassedInAndHoursAdded() { // Arrange - APICaller apiCaller = new APICaller(); - string date = "2022-11-23%200%3A0%3A0"; + string date = "2022-11-23 0:0:0"; // Act - string callerDate = apiCaller.DetermineStartDate("11/23/2022 12:30 PM", 12.5f); + string callerDate = APIHelperFunctions.GetDateWithOffsetAsAPIString("11/23/2022 12:30 PM", -12.5f); // Assert Assert.AreEqual(date, callerDate); @@ -79,27 +62,27 @@ namespace ReportingServices.Test DateTime date = DateTime.Now; if (date.DayOfWeek == DayOfWeek.Monday) - return date.Year + "-" + date.Month + "-" + (date.Day - 7) + "%200%3A0%3A0"; + date = date.AddDays(-7); if (date.DayOfWeek == DayOfWeek.Tuesday) - return date.Year + "-" + date.Month + "-" + (date.Day - 1) + "%200%3A0%3A0"; + date = date.AddDays(-1); if (date.DayOfWeek == DayOfWeek.Wednesday) - return date.Year + "-" + date.Month + "-" + (date.Day - 2) + "%200%3A0%3A0"; + date = date.AddDays(-2); if (date.DayOfWeek == DayOfWeek.Thursday) - return date.Year + "-" + date.Month + "-" + (date.Day - 3) + "%200%3A0%3A0"; + date = date.AddDays(-3); if (date.DayOfWeek == DayOfWeek.Friday) - return date.Year + "-" + date.Month + "-" + (date.Day - 4) + "%200%3A0%3A0"; + date = date.AddDays(-4); if (date.DayOfWeek == DayOfWeek.Saturday) - return date.Year + "-" + date.Month + "-" + (date.Day - 5) + "%200%3A0%3A0"; + date = date.AddDays(-5); if (date.DayOfWeek == DayOfWeek.Sunday) - return date.Year + "-" + date.Month + "-" + (date.Day - 6) + "%200%3A0%3A0"; + date = date.AddDays(-6); - return ""; + return date.Year + "-" + date.Month + "-" + date.Day + " 0:0:0"; ; } } } \ No newline at end of file diff --git a/ReportingServices/Controllers/PlanningReportController.cs b/ReportingServices/Controllers/PlanningReportController.cs index 3abbf53..769152b 100644 --- a/ReportingServices/Controllers/PlanningReportController.cs +++ b/ReportingServices/Controllers/PlanningReportController.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Mvc; +using ReportingServices.Dependency_Injections; using ReportingServices.HelperClasses; using ReportingServices.Models.PlanningReport; @@ -6,19 +7,25 @@ namespace ReportingServices.Controllers { public class PlanningReportController : Controller { + private readonly IScrapeDatabaseRepository _scrapeDatabaseRepository; + + public PlanningReportController(IScrapeDatabaseRepository scrapeDatabaseRepository) + { + _scrapeDatabaseRepository = scrapeDatabaseRepository; + } + public IActionResult Index() { return View(); } - public IActionResult WeeklyPartChangesReport(DateTime StartDate, DateTime EndDate) + public IActionResult WeeklyPartChangesReport(DateTime startDate, DateTime endDate) { - DBCaller caller = new(); + int numberOfPartChanges = _scrapeDatabaseRepository.GetNumberOfPartChanges(startDate.ToString(), endDate.ToString()); + List reactorPSNWORuns = _scrapeDatabaseRepository.GetReactorPSNWORuns(startDate.ToString(), endDate.ToString()); - List weeklyPartChanges = caller.GetWeeklyPartChanges(StartDate.ToString(), EndDate.ToString()); - ViewBag.NumberOfPartChanges = caller.GetNumberOfPartChanges(StartDate.ToString(), EndDate.ToString()); - ViewBag.StartDate = StartDate.ToShortDateString(); - ViewBag.EndDate = EndDate.ToShortDateString(); + WeeklyPartChanges weeklyPartChanges = new WeeklyPartChanges(numberOfPartChanges, startDate.ToShortDateString(), + endDate.ToShortDateString(), reactorPSNWORuns); return View(weeklyPartChanges); } diff --git a/ReportingServices/Controllers/ProductionReportController.cs b/ReportingServices/Controllers/ProductionReportController.cs index 0b09ced..bdae75a 100644 --- a/ReportingServices/Controllers/ProductionReportController.cs +++ b/ReportingServices/Controllers/ProductionReportController.cs @@ -1,12 +1,29 @@ using Microsoft.AspNetCore.Mvc; +using ReportingServices.Dependency_Injections; using ReportingServices.HelperClasses; using ReportingServices.Models.ProductionReport; using ReportingServices.ReportingObjects; +using System.Text.Json; +using System.Text.Json.Nodes; +using System.Web; namespace ReportingServices.Controllers { public class ProductionReportController : Controller { + private readonly IJsonFileHandler _jsonFileHandler; + private readonly IScrapeDatabaseRepository _scrapeDatabaseRepository; + private readonly IFabTimeReportingRepository _fabTimeReportingRepository; + private readonly int _reportIndex = (int)DateTime.Now.DayOfWeek; + private readonly string _dailyRptFileName = "wwwroot/Assets/DailyReportInfo.json"; + 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 ProductionReportController(IJsonFileHandler jsonFileHandler, IScrapeDatabaseRepository scrapeDatabaseRepository, IFabTimeReportingRepository fabTimeReportingRepository) + { + _jsonFileHandler = jsonFileHandler; + _scrapeDatabaseRepository = scrapeDatabaseRepository; + _fabTimeReportingRepository = fabTimeReportingRepository; + } public IActionResult Index() @@ -16,37 +33,98 @@ namespace ReportingServices.Controllers public IActionResult DailyReport() { - APICaller caller = new APICaller(); - caller.CallAllAPIs(); - - DailyReport dailyReport = new DailyReport(caller.OutsByDay, caller.ScrapByDay, caller.ToolAvailibilityByTypes, caller.ToolStateByTypes); + DailyReport dailyReport = SetUpDailyReport(); return View(dailyReport); } public IActionResult EditDailyReport() { - XMLReader xmlReader = new XMLReader(); + JsonNode node = _jsonFileHandler.LoadJSONFile(_dailyRptFileName); - DailyReportingSummary rpt = xmlReader.LoadJSONFile(); + ManualReportEntries rpt = JsonSerializer.Deserialize(node[(int)DateTime.Now.DayOfWeek]["Entries"]); return View(rpt); } [HttpPost] - public IActionResult EditDailyReport(DailyReportingSummary rpt) + public IActionResult EditDailyReport(ManualReportEntries rpt) { - XMLReader xmlReader = new XMLReader(); + List report = _jsonFileHandler.LoadJSONFile>(_dailyRptFileName); - //xmlReader.SaveXMLFile(rpt); - xmlReader.SaveJSONFile(rpt); + report[_reportIndex].Entries = rpt; + + _jsonFileHandler.SaveJSONFile(report, _dailyRptFileName); return RedirectToAction("DailyReport"); } - public IActionResult Headcount() + public async Task> MovesTrendCaller() { - return View(); + string url = APIHelperFunctions.GenerateURLWithParameters(chart: "MOVESLOTLIST", areasLike: "CLEANROOM", operationsLike: "1UNLOAD"); + + List outsByRDS = await _fabTimeReportingRepository.GetMovesTrendData(url); + + return outsByRDS; + } + + public async Task> ToolStateTrendCaller(string toolType) + { + string url = APIHelperFunctions.GenerateURLWithParameters(chart: "TOOLSTATE", periodLen: "24", capacityTypesLike: toolType, toolsLike: _toolFilter); + + List toolAvailability = await _fabTimeReportingRepository.GetToolStateTrendData(url); + + return toolAvailability; + } + + public async Task> ToolStatesCaller(string toolType) + { + string capacityFilter = toolType == "ASM" ? toolType + "%2CASM%2B" : toolType; + string startDate = HttpUtility.UrlEncode(APIHelperFunctions.GetDateWithOffsetAsAPIString(DateTime.Now.ToString(), 12.5f)); + + string url = APIHelperFunctions.GenerateURLWithParameters(chart: "ToolStateGantt", periodLen: "24", + capacityTypesLike: capacityFilter, toolsLike: _toolFilter, startDate: startDate); + + List toolStates = await _fabTimeReportingRepository.GetToolStateData(url); + + return toolStates; + } + + public DailyReport SetUpDailyReport() + { + DailyReport report = new(); + + Task> task1 = MovesTrendCaller(); + Task> task2 = ToolStateTrendCaller("ASM"); + Task> task3 = ToolStateTrendCaller("EPP"); + Task> task4 = ToolStateTrendCaller("HTR"); + Task> task5 = ToolStatesCaller("ASM"); + Task> task6 = ToolStatesCaller("EPP"); + Task> task7 = ToolStatesCaller("HTR"); + + report.SetOutsByDay(task1.Result); + + List scrap = _scrapeDatabaseRepository.GetScrapByDay(task1.Result); + + report.SetScrapByDay(scrap); + report.AddToolAvailibilityByType("ASM", task2.Result); + report.AddToolAvailibilityByType("EPP", task3.Result); + report.AddToolAvailibilityByType("HTR", task4.Result); + report.AddToolStateByType("ASM", task5.Result); + report.AddToolStateByType("EPP", task6.Result); + report.AddToolStateByType("HTR", task7.Result); + report.ReverseLists(); + + List entries = _jsonFileHandler.LoadJSONFile>(_dailyRptFileName); + + report.Entries = entries; + + int[] singleLoadLocks = _scrapeDatabaseRepository.GetNumberOfSingleLoadLocks(); + + report.Entries[_reportIndex].Entries.SingleLoadLockASM = singleLoadLocks[0]; + report.Entries[_reportIndex].Entries.SingleLoadLockHTR = singleLoadLocks[1]; + + return report; } } } diff --git a/ReportingServices/Dependency Injections/Implementations/FabTimeReportingRepository.cs b/ReportingServices/Dependency Injections/Implementations/FabTimeReportingRepository.cs new file mode 100644 index 0000000..69027e9 --- /dev/null +++ b/ReportingServices/Dependency Injections/Implementations/FabTimeReportingRepository.cs @@ -0,0 +1,41 @@ +using ReportingServices.ReportingObjects; +using System.Text.Json; + +namespace ReportingServices.Dependency_Injections +{ + public class FabTimeReportingRepository : IFabTimeReportingRepository + { + public async Task> GetMovesTrendData(string url) + { + return await GetJsonData>(url); + } + + public async Task> GetToolStateTrendData(string url) + { + return await GetJsonData>(url); + } + + public async Task> GetToolStateData(string url) + { + return await GetJsonData>(url); + } + + public async Task GetJsonData(string url) + { + T deserializedJson; + + using (var client = new HttpClient()) + { + using (HttpResponseMessage response = await client.GetAsync(url)) + { + string apiResponse = await response.Content.ReadAsStringAsync(); + deserializedJson = JsonSerializer.Deserialize(apiResponse); + } + } + + return deserializedJson; + } + + + } +} diff --git a/ReportingServices/Dependency Injections/Implementations/JsonFileHandler.cs b/ReportingServices/Dependency Injections/Implementations/JsonFileHandler.cs new file mode 100644 index 0000000..fc8c977 --- /dev/null +++ b/ReportingServices/Dependency Injections/Implementations/JsonFileHandler.cs @@ -0,0 +1,19 @@ +using System.Text.Json; + +namespace ReportingServices.Dependency_Injections +{ + public class JsonFileHandler : IJsonFileHandler + { + public T LoadJSONFile(string file) + { + string json = File.ReadAllText(file); + return JsonSerializer.Deserialize(json); + } + + public void SaveJSONFile(T obj, string file) + { + string json = JsonSerializer.Serialize(obj); + File.WriteAllText(file, json); + } + } +} diff --git a/ReportingServices/Dependency Injections/Implementations/ScrapeDatabaseRepository.cs b/ReportingServices/Dependency Injections/Implementations/ScrapeDatabaseRepository.cs new file mode 100644 index 0000000..26eda05 --- /dev/null +++ b/ReportingServices/Dependency Injections/Implementations/ScrapeDatabaseRepository.cs @@ -0,0 +1,164 @@ +using Microsoft.Data.SqlClient; +using ReportingServices.Models.PlanningReport; +using ReportingServices.ReportingObjects; +using System.Data; + +namespace ReportingServices.Dependency_Injections +{ + public class ScrapeDatabaseRepository : IScrapeDatabaseRepository + { + private SqlConnection _connection; + private string _connectionString = "Server=Messv01ec.ec.local\\PROD1,53959;Database=LSL2SQL;User Id=srpadmin;Password=0okm9ijn;TrustServerCertificate=true"; + + public void OpenConnection() + { + if (_connection == null) + _connection = new SqlConnection(_connectionString); + + if (_connection.State != ConnectionState.Open) + _connection.Open(); + } + + public void CloseConnection() + { + if (_connection.State != ConnectionState.Closed) + _connection.Close(); + } + + 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; + } + + public List GetScrapByDay(List outs) + { + List 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(); + + 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())); + } + + cmd.Dispose(); + + CloseConnection(); + + return scrap; + } + + public List GetReactorPSNWORuns(string startDate, string endDate) + { + List 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 ReactorPSNWORuns(reader[0].ToString(), reader[1].ToString(), int.Parse(reader[2].ToString()))); + } + + cmd.Dispose(); + + CloseConnection(); + + return weeklyPartChanges; + } + + public int[] GetNumberOfSingleLoadLocks() + { + int[] singleLoadLocks = new int[2]; + + OpenConnection(); + + SqlCommand cmd = _connection.CreateCommand(); + + string query = "SELECT REACT_TYPE, COUNT(ACTIVE_LL_DISABLED) AS SLL" + + " FROM REACTOR " + + " WHERE REACT_ASSIGNMENT IS NOT NULL " + + " AND REACT_ASSIGNMENT <> 'Out of Service' " + + " AND REACT_ASSIGNMENT<> '' " + + " AND REACT_TYPE IN('ASM', 'HTR') " + + "GROUP BY REACT_TYPE"; + + cmd.CommandText = query; + + using (SqlDataReader reader = cmd.ExecuteReader()) + { + reader.Read(); + + singleLoadLocks[0] = int.Parse(reader[1].ToString()); + + reader.Read(); + + singleLoadLocks[1] = int.Parse(reader[1].ToString()); + } + + cmd.Dispose(); + + CloseConnection(); + + return singleLoadLocks; + } + } +} diff --git a/ReportingServices/Dependency Injections/Interfaces/IFabTimeReportingRepository.cs b/ReportingServices/Dependency Injections/Interfaces/IFabTimeReportingRepository.cs new file mode 100644 index 0000000..b6b3594 --- /dev/null +++ b/ReportingServices/Dependency Injections/Interfaces/IFabTimeReportingRepository.cs @@ -0,0 +1,12 @@ +using ReportingServices.ReportingObjects; + +namespace ReportingServices.Dependency_Injections +{ + public interface IFabTimeReportingRepository + { + public Task> GetMovesTrendData(string url); + public Task> GetToolStateTrendData(string url); + public Task> GetToolStateData(string url); + public Task GetJsonData(string url); + } +} diff --git a/ReportingServices/Dependency Injections/Interfaces/IJsonFileHandler.cs b/ReportingServices/Dependency Injections/Interfaces/IJsonFileHandler.cs new file mode 100644 index 0000000..8506cf1 --- /dev/null +++ b/ReportingServices/Dependency Injections/Interfaces/IJsonFileHandler.cs @@ -0,0 +1,10 @@ +using ReportingServices.ReportingObjects; + +namespace ReportingServices.Dependency_Injections +{ + public interface IJsonFileHandler + { + public void SaveJSONFile(T obj, string file); + public T LoadJSONFile(string file); + } +} diff --git a/ReportingServices/Dependency Injections/Interfaces/IScrapeDatabaseRepository.cs b/ReportingServices/Dependency Injections/Interfaces/IScrapeDatabaseRepository.cs new file mode 100644 index 0000000..be3ae81 --- /dev/null +++ b/ReportingServices/Dependency Injections/Interfaces/IScrapeDatabaseRepository.cs @@ -0,0 +1,15 @@ +using ReportingServices.Models.PlanningReport; +using ReportingServices.ReportingObjects; + +namespace ReportingServices.Dependency_Injections +{ + public interface IScrapeDatabaseRepository + { + public void OpenConnection(); + public void CloseConnection(); + public List GetScrapByDay(List outs); + public List GetReactorPSNWORuns(string startDate, string endDate); + public int GetNumberOfPartChanges(string startDate, string endDate); + public int[] GetNumberOfSingleLoadLocks(); + } +} diff --git a/ReportingServices/HelperClasses/APIHelperFunctions.cs b/ReportingServices/HelperClasses/APIHelperFunctions.cs new file mode 100644 index 0000000..b1e588e --- /dev/null +++ b/ReportingServices/HelperClasses/APIHelperFunctions.cs @@ -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 SetParameters(string startDate = "", string chart = "", string periodLen = "", + string areasLike = "", string toolsLike = "", string operationsLike = "", string capacityTypesLike = "") + { + Dictionary 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 parameters) + { + int count = 0; + string url = fabTimeServer; + + foreach (KeyValuePair 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 parameters = SetParameters(startDate, chart, + periodLen, areasLike, toolsLike, operationsLike, capacityTypesLike); + + return GenerateURL(parameters); + } + + public static List ReverseList(List inputList) + { + List temp = new(); + + for (int i = inputList.Count - 1; i >= 0; i--) + { + temp.Add(inputList[i]); + } + + return temp; + } + } +} diff --git a/ReportingServices/HelperClasses/Data/APICaller.cs b/ReportingServices/HelperClasses/Data/APICaller.cs deleted file mode 100644 index aa3e0a5..0000000 --- a/ReportingServices/HelperClasses/Data/APICaller.cs +++ /dev/null @@ -1,241 +0,0 @@ -using ReportingServices.ReportingObjects; -using System.Text.Json; - -namespace ReportingServices.HelperClasses -{ - public class APICaller - { - public List OutsByDay { get; set; } - public List ScrapByDay { get; set; } - public Dictionary ToolAvailibilityByTypes { get; set; } - public Dictionary ToolStateByTypes { get; set; } - - private readonly string fabTimeServer = "http://messa004.infineon.com/fabtime717service/GetChartData.aspx?"; - private Dictionary 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 parameters = Parameters; - parameters["chart"] = "MOVESLOTLIST"; - parameters["areaslike"] = "CLEANROOM"; - parameters["operationslike"] = "1UNLOAD"; - - List outsByDay = await GetJsonData(GetAPIURL(parameters)); - - GetReactorOutsByDay(outsByDay); - - DBCaller db = new(); - - ScrapByDay = db.GetScrap(outsByDay); - } - - public async Task ToolStateTrendCaller(string toolType) - { - Dictionary parameters = Parameters; - parameters["chart"] = "TOOLSTATE"; - parameters["periodlen"] = "24"; - parameters["capacitytypeslike"] = toolType; - parameters["toolslike"] = toolFilter; - - List toolAvailability = await GetJsonData(GetAPIURL(parameters)); - - ToolAvailibilityByTypes.Add(toolType, new ToolAvailibilityByType(toolAvailability)); - } - - public async Task ToolStatesCaller(string toolType) - { - Dictionary 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 toolStates = await GetJsonData(GetAPIURL(parameters)); - - ToolStateByTypes.Add(toolType, new ToolStateByType(toolStates)); - } - - private async Task> GetJsonData(string url) - { - List deserializedJson; - - using (var httpClient = new HttpClient()) - { - using (var response = await httpClient.GetAsync(url)) - { - string apiResponse = await response.Content.ReadAsStringAsync(); - deserializedJson = JsonSerializer.Deserialize>(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 parameters) - { - int count = 0; - string url = fabTimeServer; - - foreach (KeyValuePair 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 outs) - { - List outsByDay = new(); - - List 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 GetDistinctDates(List outs) - { - List 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 temp2 = new(); - - for (int i = ScrapByDay.Count - 1; i >= 0; i--) - { - temp2.Add(ScrapByDay[i]); - } - - ScrapByDay = temp2; - - foreach (KeyValuePair keyValuePair in ToolAvailibilityByTypes) - { - List temp3 = new(); - - for (int i = keyValuePair.Value.EquipmentStates.Count - 1; i >= 0; i--) - { - temp3.Add(keyValuePair.Value.EquipmentStates[i]); - } - } - } - } -} diff --git a/ReportingServices/HelperClasses/Data/DBCaller.cs b/ReportingServices/HelperClasses/Data/DBCaller.cs deleted file mode 100644 index b6a8a2d..0000000 --- a/ReportingServices/HelperClasses/Data/DBCaller.cs +++ /dev/null @@ -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 GetScrap(List outs) - { - List 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 GetWeeklyPartChanges(string startDate, string endDate) - { - List 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; - } - } -} \ No newline at end of file diff --git a/ReportingServices/HelperClasses/Data/XMLReader.cs b/ReportingServices/HelperClasses/Data/XMLReader.cs deleted file mode 100644 index 921774e..0000000 --- a/ReportingServices/HelperClasses/Data/XMLReader.cs +++ /dev/null @@ -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(json); - } - } -} diff --git a/ReportingServices/Models/ErrorViewModel.cs b/ReportingServices/Models/ErrorViewModel.cs index ac39579..1965310 100644 --- a/ReportingServices/Models/ErrorViewModel.cs +++ b/ReportingServices/Models/ErrorViewModel.cs @@ -2,7 +2,7 @@ namespace ReportingServices.Models { public class ErrorViewModel { - public string? RequestId { get; set; } + public string RequestId { get; set; } public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); } diff --git a/ReportingServices/Models/PlanningReport/ReactorPSNWORuns.cs b/ReportingServices/Models/PlanningReport/ReactorPSNWORuns.cs new file mode 100644 index 0000000..2fe1b14 --- /dev/null +++ b/ReportingServices/Models/PlanningReport/ReactorPSNWORuns.cs @@ -0,0 +1,16 @@ +namespace ReportingServices.Models.PlanningReport +{ + public class ReactorPSNWORuns + { + public string REACTOR { get; set; } + public string PSN { get; set; } + public int WO_COUNT { get; set; } + + public ReactorPSNWORuns(string reactor, string psn, int wo_count) + { + REACTOR = reactor; + PSN = psn; + WO_COUNT = wo_count; + } + } +} diff --git a/ReportingServices/Models/PlanningReport/WeeklyPartChanges.cs b/ReportingServices/Models/PlanningReport/WeeklyPartChanges.cs index fe4f7a7..88e08db 100644 --- a/ReportingServices/Models/PlanningReport/WeeklyPartChanges.cs +++ b/ReportingServices/Models/PlanningReport/WeeklyPartChanges.cs @@ -2,15 +2,17 @@ { public class WeeklyPartChanges { - public string REACTOR { get; set; } - public string PSN { get; set; } - public int WO_COUNT { get; set; } + public int TotalPartChanges { get; set; } + public string StartDate { get; set; } + public string EndDate { get; set; } + public List ReactorPSNWORuns { get; set; } - public WeeklyPartChanges(string reactor, string psn, int wo_count) + public WeeklyPartChanges(int totalPartChanges, string startDate, string endDate, List reactorPSNWORuns) { - REACTOR = reactor; - PSN = psn; - WO_COUNT = wo_count; + TotalPartChanges = totalPartChanges; + StartDate = startDate; + EndDate = endDate; + ReactorPSNWORuns = reactorPSNWORuns; } } } diff --git a/ReportingServices/Models/ProductionReport/DailyReport.cs b/ReportingServices/Models/ProductionReport/DailyReport.cs index e8b42dc..16e93a9 100644 --- a/ReportingServices/Models/ProductionReport/DailyReport.cs +++ b/ReportingServices/Models/ProductionReport/DailyReport.cs @@ -1,4 +1,5 @@ -using ReportingServices.ReportingObjects; +using ReportingServices.HelperClasses; +using ReportingServices.ReportingObjects; namespace ReportingServices.Models.ProductionReport { @@ -6,17 +7,80 @@ namespace ReportingServices.Models.ProductionReport { public List OutsByDay { get; set; } public List ScrapByDay { get; set; } - public Dictionary ToolAvailibilityByType { get; set; } + public Dictionary> ToolAvailibilityByType { get; set; } public Dictionary ToolStateByType { get; set; } + public List Entries { get; set; } - public DailyReport(List outsByDay, List scrapByDay, Dictionary toolAvailibilityByType, Dictionary toolStateByType) + public DailyReport() { - OutsByDay = outsByDay; - ScrapByDay = scrapByDay; - ToolAvailibilityByType = toolAvailibilityByType; - ToolStateByType = toolStateByType; + ToolAvailibilityByType = new(); + ToolStateByType = new(); } + public void SetOutsByDay(List outs) + { + OutsByDay = GetReactorOutsByDay(outs); + } + public void SetScrapByDay(List scrap) + { + ScrapByDay = scrap; + } + + public void AddToolAvailibilityByType(string key, List states) + { + ToolAvailibilityByType.Add(key, states); + } + + public void AddToolStateByType(string key, List states) + { + ToolStateByType state = new ToolStateByType(states); + + ToolStateByType.Add(key, state); + } + + public static List GetDistinctDatesFromReactorOuts(List outs) + { + List 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 static List GetReactorOutsByDay(List outs) + { + List outsByDay = new(); + + List dates = GetDistinctDatesFromReactorOuts(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)); + } + + return outsByDay; + } + + public void ReverseLists() + { + ScrapByDay = APIHelperFunctions.ReverseList(ScrapByDay); + + ToolAvailibilityByType["ASM"] = APIHelperFunctions.ReverseList(ToolAvailibilityByType["ASM"]); + ToolAvailibilityByType["EPP"] = APIHelperFunctions.ReverseList(ToolAvailibilityByType["EPP"]); + ToolAvailibilityByType["HTR"] = APIHelperFunctions.ReverseList(ToolAvailibilityByType["HTR"]); + } } } diff --git a/ReportingServices/Program.cs b/ReportingServices/Program.cs index 0727468..e6a5305 100644 --- a/ReportingServices/Program.cs +++ b/ReportingServices/Program.cs @@ -1,7 +1,12 @@ +using ReportingServices.Dependency_Injections; + var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllersWithViews(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); var app = builder.Build(); diff --git a/ReportingServices/ReportingObjects/DailyReportingSummary.cs b/ReportingServices/ReportingObjects/ManualReportEntries.cs similarity index 86% rename from ReportingServices/ReportingObjects/DailyReportingSummary.cs rename to ReportingServices/ReportingObjects/ManualReportEntries.cs index 03114d2..1baed4f 100644 --- a/ReportingServices/ReportingObjects/DailyReportingSummary.cs +++ b/ReportingServices/ReportingObjects/ManualReportEntries.cs @@ -1,6 +1,6 @@ namespace ReportingServices.ReportingObjects { - public class DailyReportingSummary + public class ManualReportEntries { public int OperatorHeadcountDays { get; set; } public int OperatorHeadcountNights { get; set; } @@ -17,5 +17,7 @@ public string BottleChanges { get; set; } public string DailyPartChanges { get; set; } public string WeeklyPartChanges { get; set; } + public int SingleLoadLockASM { get; set; } + public int SingleLoadLockHTR { get; set; } } } diff --git a/ReportingServices/ReportingObjects/ManualReportEntriesByDay.cs b/ReportingServices/ReportingObjects/ManualReportEntriesByDay.cs new file mode 100644 index 0000000..44b24cf --- /dev/null +++ b/ReportingServices/ReportingObjects/ManualReportEntriesByDay.cs @@ -0,0 +1,14 @@ +namespace ReportingServices.ReportingObjects +{ + public class ManualReportEntriesByDay + { + public DayOfWeek Day { get; set; } + public ManualReportEntries Entries { get; set; } + + public ManualReportEntriesByDay(DayOfWeek day, ManualReportEntries entries) + { + Day = day; + Entries = entries; + } + } +} diff --git a/ReportingServices/ReportingObjects/ToolAvailibilityByType.cs b/ReportingServices/ReportingObjects/ToolAvailibilityByType.cs deleted file mode 100644 index 65c2499..0000000 --- a/ReportingServices/ReportingObjects/ToolAvailibilityByType.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace ReportingServices.ReportingObjects -{ - public class ToolAvailibilityByType - { - public List EquipmentStates { get; set; } - - public ToolAvailibilityByType(List equipmentStates) - { - EquipmentStates = equipmentStates; - } - } -} diff --git a/ReportingServices/Views/PlanningReport/Index.cshtml b/ReportingServices/Views/PlanningReport/Index.cshtml index 4020403..a905434 100644 --- a/ReportingServices/Views/PlanningReport/Index.cshtml +++ b/ReportingServices/Views/PlanningReport/Index.cshtml @@ -27,11 +27,11 @@