123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- 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<string> GetModuleTypes(List<MachineOutPutPerHour> machineOutPutPerHours)
- {
- List<string> ModuleTypes = new List<string>();
- foreach (MachineOutPutPerHour machineOutPutPerHour in machineOutPutPerHours)
- {
- if (!ModuleTypes.Any(x => x == machineOutPutPerHour.ModuleType))
- {
- ModuleTypes.Add(machineOutPutPerHour.ModuleType);
- }
- }
- return ModuleTypes;
- }
- public static List<MachineStatisticsDto> CalculationStatistics(
- List<MachineOutPutPerHour> machineOutPutPerHours, List<Recipe> recipes, List<string> moduleTypes)
- {
- List<MachineStatisticsDto> machineStatisticsDtos = new List<MachineStatisticsDto>();
- 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<MachineOutPutPerHour> outPutPerHours = machineOutPutPerHours.Where(
- // x => (x.ModuleType == recipe.ModuleType)
- // && (x.AutoRunTime != 0 || x.IdleTime != 0 || x.AlarmTime != 0)).ToList();
- List<MachineOutPutPerHour> 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;
- }
- }
- }
|