using ProductionLineMonitor.Core.Dtos; using ProductionLineMonitor.Core.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ProductionLineMonitor.Core.Services { public class GlobalService { public static List GetModuleTypes(List machineOutPutPerHours) { List ModuleTypes = new List(); foreach (MachineOutPutPerHour machineOutPutPerHour in machineOutPutPerHours) { if (!ModuleTypes.Any(x => x == machineOutPutPerHour.ModuleType)) { ModuleTypes.Add(machineOutPutPerHour.ModuleType); } } return ModuleTypes; } public static List CalculationStatistics( List machineOutPutPerHours, List recipes, List moduleTypes) { List machineStatisticsDtos = new List(); if (recipes.Count == 0) { foreach (var item in moduleTypes) { MachineStatisticsDto machineStatisticsDto = new MachineStatisticsDto(); machineStatisticsDto.ModuleType = item; machineStatisticsDto.Capacity = machineOutPutPerHours.Where(x => x.ModuleType == item).Sum(x => x.OutPut); machineStatisticsDtos.Add(machineStatisticsDto); } //MachineStatisticsDto machineStatisticsDto = new MachineStatisticsDto(); //machineStatisticsDto.ModuleType = ""; //machineStatisticsDto.Capacity = machineOutPutPerHours.Sum(x => x.OutPut); //machineStatisticsDtos.Add(machineStatisticsDto); return machineStatisticsDtos; } foreach (var recipe in recipes) { MachineStatisticsDto machineStatisticsDto = new MachineStatisticsDto(); //List outPutPerHours = machineOutPutPerHours.Where( // x => (x.ModuleType == recipe.ModuleType) // && (x.AutoRunTime != 0 || x.IdleTime != 0 || x.AlarmTime != 0)).ToList(); List outPutPerHours = machineOutPutPerHours.Where( x => (x.ModuleType == recipe.ModuleType) && x.AutoRunTime != 0 && x.OutPut != 0).ToList(); machineStatisticsDto.ModuleType = recipe.ModuleType; double runTime = outPutPerHours.Sum(x => x.AutoRunTime).Value / 60; double allTime = outPutPerHours.Count * 60; //double runTime = outPutPerHours.Sum(x => x.AutoRunTime).Value / 60; //double allTime = outPutPerHours.Count * 60; //if (outPutPerHours != null && outPutPerHours.Count >= 2) //{ // var out1 = outPutPerHours.First(); // var out2 = outPutPerHours.Last(); // //allTime = (outPutPerHours.Count - 1) * 60 + (lastOut.AutoRunTime.Value / 60) - 15; // //if (outPutPerHours.Count >= 13) // // allTime -= 15; // allTime = (outPutPerHours.Count - 2) * 60 // + (out1.AutoRunTime.Value / 60) // + (out2.AutoRunTime.Value / 60); //} machineStatisticsDto.Capacity = outPutPerHours.Sum(x => x.OutPut); machineStatisticsDto.Quality = 1; if (allTime == 0 || runTime == 0) { machineStatisticsDto.Availability = 0; machineStatisticsDto.Performance = 0; } else { machineStatisticsDto.Availability = Math.Round(runTime / allTime, 3); //if (machineStatisticsDto.Availability > 1) // machineStatisticsDto.Availability = 1; machineStatisticsDto.Performance = Math.Round(machineStatisticsDto.Capacity.Value * recipe.TheoryTT.Value / 60 / runTime, 3); //if (machineStatisticsDto.Performance > 1) // machineStatisticsDto.Performance = 1; } machineStatisticsDto.OEE = Math.Round( machineStatisticsDto.Availability.Value * machineStatisticsDto.Performance.Value * machineStatisticsDto.Quality.Value, 3); machineStatisticsDtos.Add(machineStatisticsDto); } return machineStatisticsDtos; } } }