GlobalService.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using ProductionLineMonitor.Core.Dtos;
  2. using ProductionLineMonitor.Core.Models;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. namespace ProductionLineMonitor.Core.Services
  8. {
  9. public class GlobalService
  10. {
  11. public static List<string> GetModuleTypes(List<MachineOutPutPerHour> machineOutPutPerHours)
  12. {
  13. List<string> ModuleTypes = new List<string>();
  14. foreach (MachineOutPutPerHour machineOutPutPerHour in machineOutPutPerHours)
  15. {
  16. if (!ModuleTypes.Any(x => x == machineOutPutPerHour.ModuleType))
  17. {
  18. ModuleTypes.Add(machineOutPutPerHour.ModuleType);
  19. }
  20. }
  21. return ModuleTypes;
  22. }
  23. public static List<MachineStatisticsDto> CalculationStatistics(
  24. List<MachineOutPutPerHour> machineOutPutPerHours, List<Recipe> recipes, List<string> moduleTypes)
  25. {
  26. List<MachineStatisticsDto> machineStatisticsDtos = new List<MachineStatisticsDto>();
  27. if (recipes.Count == 0)
  28. {
  29. foreach (var item in moduleTypes)
  30. {
  31. MachineStatisticsDto machineStatisticsDto = new MachineStatisticsDto();
  32. machineStatisticsDto.ModuleType = item;
  33. machineStatisticsDto.Capacity = machineOutPutPerHours.Where(x => x.ModuleType == item).Sum(x => x.OutPut);
  34. machineStatisticsDtos.Add(machineStatisticsDto);
  35. }
  36. //MachineStatisticsDto machineStatisticsDto = new MachineStatisticsDto();
  37. //machineStatisticsDto.ModuleType = "";
  38. //machineStatisticsDto.Capacity = machineOutPutPerHours.Sum(x => x.OutPut);
  39. //machineStatisticsDtos.Add(machineStatisticsDto);
  40. return machineStatisticsDtos;
  41. }
  42. foreach (var recipe in recipes)
  43. {
  44. MachineStatisticsDto machineStatisticsDto = new MachineStatisticsDto();
  45. //List<MachineOutPutPerHour> outPutPerHours = machineOutPutPerHours.Where(
  46. // x => (x.ModuleType == recipe.ModuleType)
  47. // && (x.AutoRunTime != 0 || x.IdleTime != 0 || x.AlarmTime != 0)).ToList();
  48. List<MachineOutPutPerHour> outPutPerHours = machineOutPutPerHours.Where(
  49. x => (x.ModuleType == recipe.ModuleType)
  50. && x.AutoRunTime != 0 && x.OutPut != 0).ToList();
  51. machineStatisticsDto.ModuleType = recipe.ModuleType;
  52. double runTime = outPutPerHours.Sum(x => x.AutoRunTime).Value / 60;
  53. double allTime = outPutPerHours.Count * 60;
  54. //double runTime = outPutPerHours.Sum(x => x.AutoRunTime).Value / 60;
  55. //double allTime = outPutPerHours.Count * 60;
  56. //if (outPutPerHours != null && outPutPerHours.Count >= 2)
  57. //{
  58. // var out1 = outPutPerHours.First();
  59. // var out2 = outPutPerHours.Last();
  60. // //allTime = (outPutPerHours.Count - 1) * 60 + (lastOut.AutoRunTime.Value / 60) - 15;
  61. // //if (outPutPerHours.Count >= 13)
  62. // // allTime -= 15;
  63. // allTime = (outPutPerHours.Count - 2) * 60
  64. // + (out1.AutoRunTime.Value / 60)
  65. // + (out2.AutoRunTime.Value / 60);
  66. //}
  67. machineStatisticsDto.Capacity = outPutPerHours.Sum(x => x.OutPut);
  68. machineStatisticsDto.Quality = 1;
  69. if (allTime == 0 || runTime == 0)
  70. {
  71. machineStatisticsDto.Availability = 0;
  72. machineStatisticsDto.Performance = 0;
  73. }
  74. else
  75. {
  76. machineStatisticsDto.Availability = Math.Round(runTime / allTime, 3);
  77. //if (machineStatisticsDto.Availability > 1)
  78. // machineStatisticsDto.Availability = 1;
  79. machineStatisticsDto.Performance = Math.Round(machineStatisticsDto.Capacity.Value * recipe.TheoryTT.Value / 60 / runTime, 3);
  80. //if (machineStatisticsDto.Performance > 1)
  81. // machineStatisticsDto.Performance = 1;
  82. }
  83. machineStatisticsDto.OEE = Math.Round(
  84. machineStatisticsDto.Availability.Value *
  85. machineStatisticsDto.Performance.Value *
  86. machineStatisticsDto.Quality.Value, 3);
  87. machineStatisticsDtos.Add(machineStatisticsDto);
  88. }
  89. return machineStatisticsDtos;
  90. }
  91. }
  92. }