Пример #1
0
        private ChartViewModel GetKpisOptions(MachineInfoModel machine, PeriodModel period)
        {
            var options = new ChartViewModel();
            var data    = _stateService.GetAggregationStates(machine, period, enDataType.Dashboard);


            var stateProd = data.FirstOrDefault(w => w.enState == enState.Production);

            var stateManual = data.FirstOrDefault(w => w.enState == enState.Manual);


            var totalValue = machine.MachineTypeId == (int)enMachineType.Troncatrice || machine.MachineTypeId == (int)enMachineType.CentroLavoro ?
                             stateProd?.ElapsedTime + stateManual?.ElapsedTime : stateProd?.ElapsedTime;
            var totalOn = data.Where(w => w.enState != enState.Offline).Select(s => s.ElapsedTime).Sum();

            decimal?percProd = Common.GetPercentage(totalValue, totalOn);

            options.series = new List <SerieViewModel>()
            {
                new SerieViewModel {
                    stateProductivityGreenThreshold  = machine.StateProductivityGreenThreshold ?? 0,
                    stateProductivityYellowThreshold = machine.StateProductivityYellowThreshold ?? 0,
                    y = CommonViewService.getKpiViewModel(percProd, machine.StateProductivityGreenThreshold, machine.StateProductivityYellowThreshold).value ?? (decimal)0
                }
            };
            return(options);
        }
        private ChartViewModel GetHistoricalOptions(MachineInfoModel machine, PeriodModel period)
        {
            var options = new ChartViewModel();

            var granularity    = Common.GetAggregationType(period.StartDate, period.EndDate);
            var startDateTrend = Common.GetStartDateTrend(period.EndDate, period.StartDate, granularity);

            var periodTrend = new PeriodModel();

            periodTrend.StartDate   = startDateTrend.ToUniversalTime().Date;
            periodTrend.EndDate     = period.EndDate.ToUniversalTime().Date.AddDays(1).AddTicks(-1);
            periodTrend.Aggregation = granularity;

            var data = _pieceService.GetAggregationPieces(machine, periodTrend, enDataType.Historical).OrderBy(o => o.Day).ToList();

            if (data.Count == 0)
            {
                return(null);
            }
            var days = data.Select(s => s.Day).Distinct().ToList();

            var valori = _stateService.GetDayActivity(machine, days);

            options.categories = CommonViewService.GetTimeCategories(days, granularity);
            options.yTitle     = $"{Resource.Efficiency} (%)";
            options.yTitle2    = $"{Resource.Productivity} (pz/h)";
            options.series     = GetSeriesChartProd(valori, false);

            return(options);
        }
Пример #3
0
        private MaintenceVueModel GetIgnoredVueModel(List <MessageMachineModel> data, MachineInfoModel machine)
        {
            var result   = new MaintenceVueModel();
            var messages = data.Select(a =>
                                       new ManteinanceDataModel
            {
                id          = a.Id,
                code        = a.Code,
                type        = ((enTypeAlarm)a.Type).GetDescription(),
                time        = CommonViewService.getTimeViewModel(a.ElapsedTime),
                timestamp   = DateTime.SpecifyKind(a.IgnoreDate ?? DateTime.MinValue, DateTimeKind.Utc),
                utc         = machine.UTC,
                expiredSpan = CommonViewService.getTimeViewModel(_messageService.GetExpiredSpan(a)),
                description = a.Description,
                user        = _userManagerViewService.GetUser(a.UserId)
            }).ToList();

            result.messages = messages.OrderByDescending(o => o.time.elapsed).ToList();
            var sorting = new SortingViewModel();

            sorting.duration  = enSorting.Descending.GetDescription();
            sorting.user      = enSorting.Descending.GetDescription();
            sorting.timestamp = enSorting.Descending.GetDescription();

            result.sorting = sorting;
            return(result);
        }
        private List <SerieViewModel> GetSeriesChartProd(IList <EfficiencyStateMachineModel> data, bool aggregateOthers)
        {
            var series    = new List <SerieViewModel>();
            var dataOther = new List <EfficiencyStateMachineModel>();

            if (aggregateOthers)
            {
                dataOther = data.Skip(4).ToList();
                data      = data.Take(4).ToList();
            }

            var serieEfficiency = new SerieViewModel();

            serieEfficiency.type  = (int)enSerieProd.Efficiency;
            serieEfficiency.name  = enSerieProd.Efficiency.ToLocalizedString(_contextService.GetContext().ActualLanguage.InitialsLanguage);
            serieEfficiency.color = CommonViewService.GetColorChart(enSerieProd.Efficiency);
            serieEfficiency.data  = data.Select(s => Common.GetPercentage(s.ProducingTime, s.TotalTime).RoundToInt()).ToList();
            if (dataOther.Any())
            {
                serieEfficiency.data.Add(Common.GetPercentage(dataOther.Sum(s => s.ProducingTime), dataOther.Sum(s => s.TotalTime)).RoundToInt());
            }
            series.Add(serieEfficiency);

            var serieGrossTime = new SerieViewModel();

            serieGrossTime.type  = (int)enSerieProd.GrossTime;
            serieGrossTime.name  = new System.Resources.ResourceManager(typeof(Resource)).GetString("NPiecesGrossTime");// enSerieProd.GrossTime.ToLocalizedString(_contextService.GetContext().ActualLanguage.InitialsLanguage) + " pz/h";
            serieGrossTime.color = CommonViewService.GetColorChart(enSerieProd.GrossTime);
            serieGrossTime.data  = data.Select(s => Common.GetRatioProductivity(s.CompletedCount, s.TotalTime) ?? 0).ToList();
            if (dataOther.Any())
            {
                serieGrossTime.data.Add(Common.GetRatioProductivity(dataOther.Sum(s => s.CompletedCount), dataOther.Sum(s => s.TotalTime)) ?? 0);
            }
            series.Add(serieGrossTime);

            var serieNetTime = new SerieViewModel();

            serieNetTime.type  = (int)enSerieProd.NetTime;
            serieNetTime.name  = new System.Resources.ResourceManager(typeof(Resource)).GetString("NPiecesNetTime");// enSerieProd.NetTime.ToLocalizedString(_contextService.GetContext().ActualLanguage.InitialsLanguage) + " pz/h";
            serieNetTime.color = CommonViewService.GetColorChart(enSerieProd.NetTime);
            serieNetTime.data  = data.Select(s => Common.GetRatioProductivity(s.CompletedCount, s.ProducingTime) ?? 0).ToList();
            if (dataOther.Any())
            {
                serieNetTime.data.Add(Common.GetRatioProductivity(dataOther.Sum(s => s.CompletedCount), dataOther.Sum(s => s.ProducingTime)) ?? 0);
            }
            series.Add(serieNetTime);

            return(series);
        }
Пример #5
0
        private ToolVueModel GetVueModel(MachineInfoModel machine, bool xmodule = false)
        {
            ToolVueModel result = new ToolVueModel();

            List <ToolMachineModel> data = _toolService.GetTools(machine, xmodule);

            List <ToolMachineModel> dataTools = data.Where(w => w.IsActive).ToList();

            //List<ToolMachineModel> dataHistorical = data.Where(w => w.IsActive == false).ToList();

            if (dataTools.Count == 0)
            {
                return(result);
            }
            var lan = _contextService.GetContext().ActualLanguage.InitialsLanguage;
            List <ToolDataModel> tools = dataTools.Select(t => new ToolDataModel()
            {
                code        = t.Code,
                description = t.Description,
                perc        = Common.GetPercentage(t.CurrentLife, t.ExpectedLife),
                changes     = new ChangeModel()
                {
                    //total = (t.BrokenEventsCount ?? 0) + (t.RevisedEventsCount ?? 0),
                    breaking    = 0,
                    replacement = 0,
                    //historical = dataHistorical.Where(w => w.Code == t.Code).Select(h => new HistoricalModel()
                    //{
                    //    date = h.DateReplaced.ToString(),
                    //    type = CommonViewService.GetTypeTool(h).ToLocalizedString(lan),
                    //    color_type = CommonViewService.GetTypeTool(h).GetDescription(),
                    //    duration = CommonViewService.getTimeViewModel(h.CurrentLife)
                    //}).OrderByDescending(o => o.date).ToList()
                },
                time = CommonViewService.getTimeViewModel((t.ExpectedLife ?? 0) - (t.CurrentLife ?? 0))
            }).ToList();

            tools = tools.OrderByDescending(o => o.perc).ToList();

            SortingViewModel sorting = new SortingViewModel();

            sorting.time = enSorting.Descending.GetDescription();

            result.tools   = tools;
            result.sorting = sorting;

            return(result);
        }
        public List <ManteinanceDataModel> GetNotification(ContextModel context)
        {
            var period = new PeriodModel
            {
                StartDate = DateTime.UtcNow.Date.AddTicks(1),
                EndDate   = DateTime.UtcNow.AddDays(1).Date.AddTicks(-1),
            };

            var messages = new List <ManteinanceDataModel>();

            if (context.AllMachines != null)
            {
                foreach (var machine in context.AllMachines)
                {
                    var userId = context.User.ID.ToString();
                    var data   = _messageService.GetMaintenanceNotifications(machine, period, userId);

                    data = data.Where(m => m.Day.HasValue && m.Day.Value.Date == DateTime.UtcNow.Date).ToList();

                    var mes = data.Select(a =>
                                          new ManteinanceDataModel
                    {
                        id            = a.Id,
                        code          = a.Code,
                        type          = ((enTypeAlarm)a.Type).GetDescription(),
                        time          = CommonViewService.getTimeViewModel(a.ElapsedTime),
                        timestamp     = DateTime.SpecifyKind(a.Day ?? DateTime.MinValue, DateTimeKind.Utc),
                        utc           = machine.UTC,
                        expiredSpan   = CommonViewService.getTimeViewModel(_messageService.GetExpiredSpan(a)),
                        description   = a.Description,
                        machineName   = machine.MachineName,
                        machineModel  = machine.Model.Name,
                        machineSerial = machine.Serial,
                        panelName     = Resource.PeriodicMaintenance
                    }).ToList();

                    messages.AddRange(mes);
                }
            }


            messages = messages.OrderByDescending(o => o.expiredSpan.elapsed).ToList();


            return(messages);
        }
Пример #7
0
        private JobVueModel GetVueModel(MachineInfoModel machine, PeriodModel period)
        {
            var result = new JobVueModel();

            var data = _jobService.GetAggregationJobs(machine, period);

            if (data.Count == 0)
            {
                return(result);
            }

            CurrentStateModel currentState = null;

            if (machine.Model.Name.ToUpper().Contains("FMC") ||
                (machine.Model.Name.ToUpper().Contains("LMX")))
            {
                currentState = GetCurrentState(machine.Id);
            }

            var jobs = data.Select(j => new JobDataModel()
            {
                code     = j.Code,
                perc     = getPercent(j),
                time     = CommonViewService.getTimeViewModel(j.ElapsedTime),
                quantity = j.PiecesProduced ?? 0,
                pieces   = j.TotalPieces != null && (j.TotalPieces > 0 && !j.Code.ToUpper().StartsWith("M#2")) ? (int)j.TotalPieces : (int)j.PiecesProduced,
                day      = j.Day.GetValueOrDefault(),
                ResidueWorkingTimeJob = getResTime(currentState, j)
            }).ToList();

            jobs = jobs.OrderBy(o => o.perc).ToList();

            var sorting = new SortingViewModel
            {
                progress = enSorting.Ascending.GetDescription()
            };

            result.jobs    = jobs;
            result.sorting = sorting;


            return(result);
        }
Пример #8
0
        private MessageDetailsVueModel GetMessageDetails(MachineInfoModel actualMachine, PeriodModel actualPeriod, string actualMachineGroup = null)
        {
            var result = new MessageDetailsVueModel();

            var data = _messageService.GetMessageDetails(actualMachine, actualPeriod, actualMachineGroup);

            if (data.Count == 0)
            {
                return(result);
            }

            var messages = data.Select(a => new MessageDetailViewModel()
            {
                code        = a.Code,
                parameters  = a.Params,
                timestamp   = DateTime.SpecifyKind(a.Day ?? DateTime.MinValue, DateTimeKind.Utc),
                utc         = actualMachine.UTC ?? 0,
                type        = ((enTypeAlarm)a.Type).GetDescription(),
                group       = a.GroupName,
                time        = CommonViewService.getTimeViewModel(a.ElapsedTime),
                description = a.Description
            }).ToList();

            messages = messages.OrderByDescending(o => o.timestamp).ToList();

            var sorting = new SortingViewModel();

            sorting.timestamp = enSorting.Descending.GetDescription();

            sorting.group = enSorting.Ascending.GetDescription();
            sorting.user  = enSorting.Ascending.GetDescription();

            result.messages = messages;
            result.sorting  = sorting;



            return(result);
        }
Пример #9
0
        private MaintenceVueModel GetVueModel(MachineInfoModel machine, PeriodModel period)
        {
            var result = new MaintenceVueModel();

            var data = _messageService.GetMaintenanceMessages(machine, period);

            if (data.Count == 0)
            {
                return(result);
            }

            var messages = data.Select(a =>
                                       new ManteinanceDataModel()
            {
                id          = a.Id,
                code        = a.Code,
                type        = ((enTypeAlarm)a.Type).GetDescription(),
                time        = CommonViewService.getTimeViewModel(a.ElapsedTime),
                timestamp   = DateTime.SpecifyKind(a.Day ?? DateTime.MinValue, DateTimeKind.Utc),
                utc         = machine.UTC,
                expiredSpan = CommonViewService.getTimeViewModel(_messageService.GetExpiredSpan(a)),
                description = a.Description,
                icon        = GetIcon(a)
            }).ToList();

            messages = messages.OrderByDescending(o => o.time.elapsed).ToList();

            var sorting = new SortingViewModel();

            sorting.duration = enSorting.Descending.GetDescription();

            result.messages = messages;
            result.sorting  = sorting;


            return(result);
        }
Пример #10
0
        private ChartViewModel GetHistoricalOptions(MachineInfoModel machine, PeriodModel period, enRole role, string actualMachineGroup = null)
        {
            var options = new ChartViewModel();

            var granularity    = Common.GetAggregationType(period.StartDate, period.EndDate);
            var startDateTrend = Common.GetStartDateTrend(period.EndDate, period.StartDate, granularity);

            var periodTrend = new PeriodModel();

            periodTrend.StartDate   = startDateTrend.ToUniversalTime().Date;
            periodTrend.EndDate     = period.EndDate.ToUniversalTime().Date.AddDays(1).AddTicks(-1);
            periodTrend.Aggregation = granularity;


            var data = _messageService.GetAggregationMessages(machine, periodTrend, enDataType.Historical, actualMachineGroup)?.OrderBy(o => o.Day).ToList() ?? new List <HistoryMessageModel>();

            if (data.Count == 0)
            {
                return(null);
            }

            options.yTitle = $"{Resource.Quantity} (n)";

            var days = data.Where(w => w.Day != null && (w.Type == (int)enTypeAlarm.Warning || w.Type == (int)enTypeAlarm.Error)).Select(s => s.Day.Value).Distinct().ToList();

            if (role == enRole.Administrator || role == enRole.RandD || role == enRole.Assistance)
            {
                days = data.Where(w => w.Day != null && (w.Type == (int)enTypeAlarm.Warning || w.Type == (int)enTypeAlarm.Error || w.Type == (int)enTypeAlarm.CN)).Select(s => s.Day.Value).Distinct().ToList();
            }

            options.categories = CommonViewService.GetTimeCategories(days, granularity);

            var series = new List <SerieViewModel>();

            var serieOperator = new SerieViewModel();

            serieOperator.name  = enTypeAlarm.Warning.ToLocalizedString(_contextService.GetContext().ActualLanguage.InitialsLanguage);
            serieOperator.color = CommonViewService.GetColorAlarm(enTypeAlarm.Warning);

            var serieError = new SerieViewModel();

            serieError.name  = enTypeAlarm.Error.ToLocalizedString(_contextService.GetContext().ActualLanguage.InitialsLanguage);
            serieError.color = CommonViewService.GetColorAlarm(enTypeAlarm.Error);

            var serieCN = new SerieViewModel();

            serieCN.name  = enTypeAlarm.CN.ToLocalizedString(_contextService.GetContext().ActualLanguage.InitialsLanguage);
            serieCN.color = CommonViewService.GetColorAlarm(enTypeAlarm.CN);

            serieOperator.data = new List <int>();
            serieError.data    = new List <int>();
            serieCN.data       = new List <int>();

            foreach (string cat in options.categories)
            {
                var catVal = data.Where(w => w.Type == (int)enTypeAlarm.Warning &&
                                        CommonViewService.GetTimeCategory((DateTime)w.Day, granularity) == cat).Select(s => s.Count ?? 0).FirstOrDefault();
                serieOperator.data.Add(catVal);
                var catVal2 = data.Where(w => w.Type == (int)enTypeAlarm.Error &&
                                         CommonViewService.GetTimeCategory((DateTime)w.Day, granularity) == cat).Select(s => s.Count ?? 0).FirstOrDefault();
                serieError.data.Add(catVal2);

                var catVal3 = data.Where(w => w.Type == (int)enTypeAlarm.CN &&
                                         CommonViewService.GetTimeCategory((DateTime)w.Day, granularity) == cat).Select(s => s.Count ?? 0).FirstOrDefault();
                serieCN.data.Add(catVal3);
            }

            series.Add(serieOperator);
            series.Add(serieError);
            if (role == enRole.Administrator || role == enRole.RandD || role == enRole.Assistance)
            {
                series.Add(serieCN);
            }

            options.series = series;

            return(options);
        }
Пример #11
0
        private List <MesDataViewModel> GetVueModel(PlantModel plant, List <MachineInfoModel> allMachines, bool onlyActive)
        {
            var result = new List <MesDataViewModel>();

            var dataAllMachines = _mesService.GetPlantData(plant);

            if (onlyActive)
            {
                dataAllMachines = dataAllMachines.Where(m => m.Expired == false).ToList();
            }


            foreach (var dataMachine in dataAllMachines)
            {
                var mes = new MesDataViewModel();

                var machine = allMachines.FirstOrDefault(w => w.Id == dataMachine.MachineId);

                if (machine?.Type == null || machine.Model == null)
                {
                    continue;
                }

                mes.info = new MachineInfoViewModel
                {
                    id          = machine.Id,
                    description = machine.Description == string.Empty ? null : machine.Description,
                    model       = machine.Model.Name,
                    machineName = machine.MachineName,
                    icon        = machine.Type.Image,
                    expired     = dataMachine.Expired,
                    id_mtype    = machine.Type?.Id ?? 0,
                    serial      = machine.Serial
                };


                var data = dataAllMachines.FirstOrDefault(w => w.MachineId == machine.Id);

                if (data == null)
                {
                    result.Add(mes);
                    continue;
                }

                if (data.enActualState != null)
                {
                    mes.state = new StateViewModel
                    {
                        code = data.enActualState.GetDescription(),
                        text = LocalizationService.GetResource(data.enActualState.ToString())
                    };

                    mes.error = data.ActualStateCode;
                }

                if (data.ActualJobPerc != null)
                {
                    mes.job = new JobDataModel
                    {
                        code = data.ActualJobCode,
                        perc = (data.ActualJobPerc ?? 0).RoundToInt()
                    };
                }

                mes.@operator = data.ActualOperator;

                if (data.StateEfficiency != null)
                {
                    mes.efficiency          = new EfficiencyVueModel();
                    mes.efficiency.kpi      = CommonViewService.getKpiViewModel((decimal)(data.StateEfficiency ?? 0), machine.StateProductivityGreenThreshold, machine.StateProductivityYellowThreshold);
                    mes.efficiency.overfeed = CommonViewService.getKpiViewModel((decimal)(data.StateOverfeedAvg ?? 0), null, null);
                }

                if (data.PieceCompletedCount != null)
                {
                    mes.productivity     = new ProductivityVueModel();
                    mes.productivity.kpi = CommonViewService.getKpiViewModel(Common.GetRatioProductivity(data.PieceCompletedCount, data.PieceElapsedTime),
                                                                             machine.PiecesProductivityGreenThreshold,
                                                                             machine.PiecesProductivityYellowThreshold);
                    mes.productivity.piece = new PieceViewModel()
                    {
                        total = (data.PieceCompletedCount ?? 0) + (data.PieceRedoneCount ?? 0)
                    };
                }

                if (data.AlarmCount != null)
                {
                    mes.errors          = new ErrorViewModel();
                    mes.errors.quantity = data.AlarmCount;
                }
                result.Add(mes);
            }

            return(result);
        }
Пример #12
0
        private EfficiencyVueModel GetVueModel(MachineInfoModel machine, PeriodModel period)
        {
            var result = new EfficiencyVueModel();

            var data = _stateService.GetAggregationStates(machine, period, enDataType.Dashboard);

            if (data.Count == 0)
            {
                return(result);
            }

            var stateProd = data.FirstOrDefault(w => w.enState == enState.Production);

            var totalProd = stateProd?.ElapsedTime;



            var totalOn = data.Where(w => w.enState != enState.Offline).Select(s => s.ElapsedTime).Sum();
            //long? totalOff = data.Where(w => w.enState == enState.Offline).Select(s => s.ElapsedTime).Sum();

            decimal?percProd = Common.GetPercentage(totalProd, totalOn);


            var total = new TotalTimeModel();

            total.on = CommonViewService.getTimeViewModel(totalOn);
            //total.off = CommonViewService.getTimeViewModel(totalOff);
            result.total = total;

            var states = new List <StateViewModel>();

            // state prod
            var prod = new StateViewModel();

            prod.code      = enState.Production.GetDescription();
            prod.text      = enState.Production.ToLocalizedString(_contextService.GetContext().ActualLanguage.InitialsLanguage);
            prod.perc      = percProd;
            prod.time      = CommonViewService.getTimeViewModel(totalProd);
            prod.orderView = _stateService.GetOrderViewState(enState.Production.GetDescription());
            states.Add(prod);

            // state pause
            var pause = new StateViewModel();

            pause.code = enState.Pause.GetDescription();
            pause.text = enState.Pause.ToLocalizedString(_contextService.GetContext().ActualLanguage.InitialsLanguage);

            var statePause = data.FirstOrDefault(w => w.enState == enState.Pause);

            if (statePause != null)
            {
                var totalPause = statePause.ElapsedTime;
                pause.perc = Common.GetPercentage(totalPause, totalOn);
                pause.time = CommonViewService.getTimeViewModel(totalPause);
            }
            pause.orderView = _stateService.GetOrderViewState(enState.Pause.GetDescription());
            states.Add(pause);

            // state manual
            var manual = new StateViewModel();

            manual.code = enState.Manual.GetDescription();
            manual.text = enState.Manual.ToLocalizedString(_contextService.GetContext().ActualLanguage.InitialsLanguage);

            var stateManual = data.FirstOrDefault(w => w.enState == enState.Manual);

            if (stateManual != null)
            {
                var totalManual = stateManual.ElapsedTime;
                manual.perc = Common.GetPercentage(totalManual, totalOn);
                manual.time = CommonViewService.getTimeViewModel(totalManual);
            }
            manual.orderView = _stateService.GetOrderViewState(enState.Manual.GetDescription());
            states.Add(manual);

            // state error
            var error = new StateViewModel();

            error.code = enState.Error.GetDescription();
            error.text = enState.Error.ToLocalizedString(_contextService.GetContext().ActualLanguage.InitialsLanguage);

            var stateError = data.FirstOrDefault(w => w.enState == enState.Error);

            if (stateError != null)
            {
                var totalError = stateError.ElapsedTime;
                error.perc = Common.GetPercentage(totalError, totalOn);
                error.time = CommonViewService.getTimeViewModel(totalError);
            }
            error.orderView = _stateService.GetOrderViewState(enState.Error.GetDescription());
            states.Add(error);

            result.states = states.OrderBy(o => o.orderView).ToList();


            var overfeed = stateProd?.OverfeedAvg;

            decimal percKpi;

            if (machine.MachineTypeId == (int)enMachineType.Troncatrice || machine.MachineTypeId == (int)enMachineType.CentroLavoro)
            {
                percKpi = (decimal)percProd + (manual.perc ?? 0);
            }
            else
            {
                percKpi = (decimal)percProd;
            }

            result.kpi      = CommonViewService.getKpiViewModel(percKpi, machine.StateProductivityGreenThreshold, machine.StateProductivityYellowThreshold);
            result.overfeed = CommonViewService.getKpiViewModel(overfeed, machine.OverfeedGreenThreshold, machine.OverfeedYellowThreshold);


            return(result);
        }
Пример #13
0
        private ChartViewModel GetStatesOptions(MachineInfoModel machine, PeriodModel period)
        {
            var options = new ChartViewModel();

            options.series = new List <SerieViewModel>();


            var data = _stateService.GetAggregationStates(machine, period, enDataType.Dashboard);

            if (!data.Any())
            {
                return(options);
            }

            var stateProd  = data.FirstOrDefault(w => w.enState == enState.Production);
            var statePause = data.FirstOrDefault(w => w.enState == enState.Pause);

            var stateError  = data.FirstOrDefault(w => w.enState == enState.Error);
            var stateManual = data.FirstOrDefault(w => w.enState == enState.Manual);

            long?totalProd   = stateProd?.ElapsedTime ?? 0;
            long?totalPause  = statePause?.ElapsedTime ?? 0;
            long?totalError  = stateError?.ElapsedTime ?? 0;
            long?totalManual = stateManual?.ElapsedTime ?? 0;

            var totalOn  = data.Where(w => w.enState != enState.Offline).Select(s => s.ElapsedTime).Sum();
            var totalOff = data.Where(w => w.enState == enState.Offline).Select(s => s.ElapsedTime).Sum();

            decimal?percProd   = Common.GetPercentage(totalProd, totalOn);
            decimal?percPause  = Common.GetPercentage(totalPause, totalOn);
            decimal?percError  = Common.GetPercentage(totalError, totalOn);
            decimal?percManual = Common.GetPercentage(totalManual, totalOn);


            // state prod
            var prod = new SerieViewModel();

            prod.name  = enState.Production.ToLocalizedString(_contextService.GetContext().ActualLanguage.InitialsLanguage);
            prod.y     = percProd ?? 0;
            prod.color = CommonViewService.GetColorState(enState.Production);
            options.series.Add(prod);

            // state pause
            var pause = new SerieViewModel();

            pause.name  = enState.Pause.ToLocalizedString(_contextService.GetContext().ActualLanguage.InitialsLanguage);
            pause.y     = percPause ?? 0;
            pause.color = CommonViewService.GetColorState(enState.Pause);
            options.series.Add(pause);


            var manual = new SerieViewModel();

            manual.name  = enState.Manual.ToLocalizedString(_contextService.GetContext().ActualLanguage.InitialsLanguage);
            manual.y     = percManual ?? 0;
            manual.color = CommonViewService.GetColorState(enState.Manual);
            options.series.Add(manual);


            var error = new SerieViewModel();

            error.name  = enState.Error.ToLocalizedString(_contextService.GetContext().ActualLanguage.InitialsLanguage);
            error.y     = percError ?? 0;
            error.color = CommonViewService.GetColorState(enState.Error);
            options.series.Add(error);


            return(options);
        }
Пример #14
0
        private ChartViewModel GetHistoricalOptions(MachineInfoModel machine, PeriodModel period)
        {
            var options = new ChartViewModel();

            var granularity    = Common.GetAggregationType(period.StartDate, period.EndDate);
            var startDateTrend = Common.GetStartDateTrend(period.EndDate, period.StartDate, granularity);

            var periodTrend = new PeriodModel
            {
                StartDate   = startDateTrend.ToUniversalTime().Date,
                EndDate     = period.EndDate.ToUniversalTime().Date.AddDays(1).AddMinutes(-1),
                Aggregation = granularity
            };

            var data = _stateService.GetAggregationStates(machine, periodTrend, enDataType.Historical).Where(w => w.enState != enState.Offline).OrderBy(o => o.Day).ToList();

            if (data.Count == 0)
            {
                return(null);
            }

            // calcolo dell'unità di misura delle serie del grafico sul valore medio
            var avgData     = (long)data.Average(a => a.ElapsedTime ?? 0);
            var measurement = Common.GetTimeMeasurement(avgData);

            options.yTitle      = $"{Resource.Duration} ({measurement.GetDescription()})";
            options.valueSuffix = $" {measurement.GetDescription()}";

            var days = data.Where(w => w.Day != null).Select(s => s.Day.Value).Distinct().ToList();

            options.categories = CommonViewService.GetTimeCategories(days, granularity);

            var series = new List <SerieViewModel>();

            var serieProd = new SerieViewModel();

            serieProd.name  = enState.Production.ToLocalizedString(_contextService.GetContext().ActualLanguage.InitialsLanguage);
            serieProd.color = CommonViewService.GetColorState(enState.Production);
            List <long> lista = GetDataGroup(data, days, granularity, enState.Production);

            serieProd.data = Common.ConvertElapsedByMeasurement(lista, measurement);
            series.Add(serieProd);


            var serieManual = new SerieViewModel();

            serieManual.name  = enState.Manual.ToLocalizedString(_contextService.GetContext().ActualLanguage.InitialsLanguage);
            serieManual.color = CommonViewService.GetColorState(enState.Manual);
            serieManual.data  = Common.ConvertElapsedByMeasurement(GetDataGroup(data, days, granularity, enState.Manual), measurement);
            series.Add(serieManual);

            var seriePause = new SerieViewModel();

            seriePause.name  = enState.Pause.ToLocalizedString(_contextService.GetContext().ActualLanguage.InitialsLanguage);
            seriePause.color = CommonViewService.GetColorState(enState.Pause);
            seriePause.data  = Common.ConvertElapsedByMeasurement(GetDataGroup(data, days, granularity, enState.Pause), measurement);
            series.Add(seriePause);

            var serieError = new SerieViewModel();

            serieError.name  = enState.Error.ToLocalizedString(_contextService.GetContext().ActualLanguage.InitialsLanguage);
            serieError.color = CommonViewService.GetColorState(enState.Error);
            serieError.data  = Common.ConvertElapsedByMeasurement(GetDataGroup(data, days, granularity, enState.Error), measurement);
            series.Add(serieError);

            options.series = series;

            return(options);
        }
Пример #15
0
        public List <MachineMessagesDataViewModel> GetVueModel(PlantModel plant, List <MachineInfoModel> allMachines, PeriodModel period)
        {
            if (period.StartDate == DateTime.MinValue || period.EndDate == DateTime.MinValue)
            {
                period.EndDate   = DateTime.UtcNow;
                period.StartDate = DateTime.Now.AddDays(-30);
            }
            var result = new List <MachineMessagesDataViewModel>();

            var dataAllMachines = _mesService.GetPlantData(plant);

            foreach (var dataMachine in dataAllMachines)
            {
                var machine = allMachines.FirstOrDefault(w => w.Id == dataMachine.MachineId);

                if (machine == null)
                {
                    continue;
                }

                var machineInfo = new MachineInfoViewModel()
                {
                    id          = machine.Id,
                    description = machine.Description == string.Empty ? null : machine.Description,
                    model       = machine.Model.Name,
                    machineName = machine.MachineName,
                    icon        = machine.Type.Image,
                    serial      = machine.Serial
                };


                var data = _messageService.GetMessageDetails(machine, period);

                if (data.Count == 0)
                {
                    continue;
                }

                var msgDet = data.Select(a => new MessageDetailViewModel()
                {
                    code       = a.Code,
                    parameters = a.Params,
                    timestamp  = DateTime.SpecifyKind(a.Day ?? DateTime.MinValue, DateTimeKind.Utc),
                    utc        = machine.UTC ?? 0,
                    type       = ((enTypeAlarm)a.Type).GetDescription(),
                    //((enTypeAlarm)a.StateId).GetDescription(),
                    group       = a.GroupName,
                    time        = CommonViewService.getTimeViewModel(a.ElapsedTime),
                    description = a.Description
                }).ToList();

                foreach (var det in msgDet)
                {
                    var msg = new MachineMessagesDataViewModel();
                    msg.message = det;
                    msg.machine = machineInfo;
                    result.Add(msg);
                }
            }
            if (result.Count == 0)
            {
                result = null;
            }

            return(result);
        }
        private ProductivityVueModel GetVueModel(List <EfficiencyStateMachineModel> operatorActivities, MachineInfoModel machine, PeriodModel period)
        {
            var result = new ProductivityVueModel();

            if (machine.MachineTypeId == (int)enMachineType.CentroLavoro || machine.MachineTypeId == (int)enMachineType.LineaTaglio ||
                (machine.MachineTypeId == (int)enMachineType.LineaTaglioLavoro))
            {
                result.currentState = GetCurrentState(machine.Id);
            }

            var data = _pieceService.GetAggregationPieces(machine, period, enDataType.Dashboard);

            //var operatorActivities =_stateService.GetOperatorsActivity(machine, period.StartDate, period.EndDate);
            if (data.Count == 0)
            {
                return(result);
            }

            // tempo lordo: devo andare sulla tabella degli stati perchè non ce l'ho sui pezzi
            var grossTime      = operatorActivities.Sum(m => m.TotalTime);
            var netTime        = operatorActivities.Sum(m => m.ProducingTime);
            var productionTime = operatorActivities.Sum(m => m.ProducionModeTime ?? 0);
            //var grossTime = data.Select(s => s.ElapsedTime).Sum();
            var doneCount   = data.Select(s => s.CompletedCount).Sum() ?? 0;
            var redoneCount = data.Select(s => s.RedoneCount).Sum() ?? 0;

            // kpi pezzi all'ora
            var ratio = Common.GetRatioProductivity(doneCount, grossTime);

            result.kpi = CommonViewService.getKpiViewModel(ratio, machine.PiecesProductivityGreenThreshold, machine.PiecesProductivityYellowThreshold);

            // pieces
            var piece = new PieceViewModel();

            piece.total = doneCount + redoneCount;

            var done = new ProdDataModel();

            done.perc   = Common.GetPercentage(doneCount, piece.total);
            done.number = doneCount;
            piece.done  = done;

            var redone = new ProdDataModel();

            redone.perc   = Common.GetPercentage(redoneCount, piece.total);
            redone.number = redoneCount;
            piece.redone  = redone;

            result.piece = piece;

            // materials
            var dataBars = _barService.GetAggregationBar(machine, period);

            if (dataBars.Count > 0)
            {
                var    barLength    = dataBars.Select(s => s.Length ?? 0).Sum().RoundToInt();
                double cutoffLength = dataBars.Select(s => s.OffcutLength ?? 0).Sum();
                var    totalLength  = barLength + cutoffLength;

                var material = new MaterialViewModel();
                material.total = (totalLength / 1000);

                var bar = new ProdDataModel();
                bar.perc     = Common.GetPercentage(barLength, totalLength);
                bar.number   = ((double)barLength / 1000);
                material.bar = bar;

                //Nelle troncatrici questi dati sono nascosti, non ci sono,
                //per le altre è da verificare cosa prendono
                var cutoff = new ProdDataModel();
                cutoff.perc     = Common.GetPercentage(cutoffLength, totalLength);
                cutoff.number   = ((double)cutoffLength / 1000);
                material.cutoff = cutoff;

                result.material = material;
            }


            // phases
            var phases = new List <ProdDataModel>();

            switch (machine.MachineTypeId)
            {
            case (int)enMachineType.Troncatrice:
            case (int)enMachineType.LineaTaglio:
                var cut = new ProdDataModel();
                cut.text = Resource.Cut;
                cut.perc = Common.GetPercentage(netTime, grossTime);
                phases.Add(cut);
                break;

            case (int)enMachineType.CentroLavoro:
                var working = new ProdDataModel();
                working.text = Resource.Working;
                working.perc = Common.GetPercentage(productionTime, grossTime);
                phases.Add(working);
                break;

            default:
                working      = new ProdDataModel();
                working.text = Resource.Working;
                working.perc = Common.GetPercentage(data.Select(s => s.ElapsedTimeWorking ?? 0).Sum(), grossTime);
                phases.Add(working);

                var trim = new ProdDataModel();
                trim.text = Resource.Trim;
                trim.perc = Common.GetPercentage(data.Select(s => s.ElapsedTimeTrim ?? 0).Sum(), grossTime);
                phases.Add(trim);

                cut      = new ProdDataModel();
                cut.text = Resource.Cut;
                cut.perc = Common.GetPercentage(data.Select(s => s.ElapsedTimeCut ?? 0).Sum(), grossTime);
                phases.Add(cut);

                break;
            }

            result.phases = phases.OrderByDescending(o => o.perc).ToList();

            // operators
            //var dataOperators = _pieceService.GetAggregationPieces(machine, period, enDataType.Operators);

            var dataOperators = operatorActivities;

            if (dataOperators.Count > 0)
            {
                var groupOperator = dataOperators.GroupBy(g => new { g.Operator, g.TotalTime }).OrderByDescending(x => x.Key.TotalTime).ToList();

                if (groupOperator.Count <= 3)
                {
                    result.operators = groupOperator.Select(o => new ProdDataModel()
                    {
                        text = o.Key.Operator,
                        perc = Common.GetPercentage(o.Key.TotalTime ?? 0, grossTime)
                    }).OrderByDescending(p => p.perc).ToList();
                }
                else
                {
                    var firstGroup  = groupOperator.GetRange(0, 2);
                    var secondGroup = groupOperator.GetRange(2, groupOperator.Count - 2);

                    if (firstGroup.Count > 0)
                    {
                        result.operators = firstGroup.Select(o => new ProdDataModel()
                        {
                            text = o.Key.Operator,
                            perc = Common.GetPercentage(o.Key.TotalTime ?? 0, grossTime)
                        }).OrderByDescending(p => p.perc).ToList();
                    }

                    if (secondGroup.Count > 0)
                    {
                        var elpasedTimeTotal = secondGroup.Select(s => s.Key.TotalTime ?? 0).Sum();

                        result.operators.Add(new ProdDataModel()
                        {
                            text = Resource.Others,
                            perc = Common.GetPercentage(elpasedTimeTotal, grossTime)
                        });
                    }
                }
            }

            // gross time
            result.time = CommonViewService.getTimeViewModel(grossTime);

            return(result);
        }
Пример #17
0
        private List <SerieViewModel> GetSeriesStackedBarChart(List <HistoryStateModel> data, List <string> categories, enDataType chart)
        {
            var series = new List <SerieViewModel>();

            var serieProd = new SerieViewModel();

            serieProd.name  = enState.Production.ToLocalizedString(_contextService.GetContext().ActualLanguage.InitialsLanguage);
            serieProd.color = CommonViewService.GetColorState(enState.Production);
            serieProd.data  = new List <int>();

            var seriePause = new SerieViewModel();

            seriePause.name  = enState.Pause.ToLocalizedString(_contextService.GetContext().ActualLanguage.InitialsLanguage);
            seriePause.color = CommonViewService.GetColorState(enState.Pause);
            seriePause.data  = new List <int>();

            var serieManual = new SerieViewModel();

            serieManual.name  = enState.Manual.ToLocalizedString(_contextService.GetContext().ActualLanguage.InitialsLanguage);
            serieManual.color = CommonViewService.GetColorState(enState.Manual);
            serieManual.data  = new List <int>();

            var serieError = new SerieViewModel();

            serieError.name  = enState.Error.ToLocalizedString(_contextService.GetContext().ActualLanguage.InitialsLanguage);
            serieError.color = CommonViewService.GetColorState(enState.Error);
            serieError.data  = new List <int>();

            // create data foreach categories (operator or shift)
            foreach (var categorie in categories)
            {
                var dataCategorie = new List <HistoryStateModel>();

                switch (chart)
                {
                case enDataType.Operators:
                    dataCategorie = data.Where(w => w.Operator == categorie).ToList();
                    break;
                }

                if (dataCategorie.Count == 0)
                {
                    continue;
                }

                var totalOn = dataCategorie.Where(w => w.enState != enState.Offline).Select(s => s.ElapsedTime).Sum();

                var stateProd = dataCategorie.FirstOrDefault(w => w.enState == enState.Production);

                if (stateProd != null)
                {
                    var     totalProd = stateProd.ElapsedTime;
                    decimal?percProd  = Common.GetPercentage(totalProd, totalOn);
                    serieProd.data.Add(((decimal)percProd).RoundToInt());
                }
                else
                {
                    serieProd.data.Add(0);
                }

                var stateManual = dataCategorie.FirstOrDefault(w => w.enState == enState.Manual);

                if (stateManual != null)
                {
                    var     totalManual = stateManual.ElapsedTime;
                    decimal?percManual  = Common.GetPercentage(totalManual, totalOn);
                    serieManual.data.Add(((decimal)percManual).RoundToInt());
                }
                else
                {
                    serieManual.data.Add(0);
                }

                var statePause = dataCategorie.FirstOrDefault(w => w.enState == enState.Pause);

                if (statePause != null)
                {
                    var     totalPause = statePause.ElapsedTime;
                    decimal?percPause  = Common.GetPercentage(totalPause, totalOn);
                    seriePause.data.Add(((decimal)percPause).RoundToInt());
                }
                else
                {
                    seriePause.data.Add(0);
                }

                var stateError = dataCategorie.FirstOrDefault(w => w.enState == enState.Error);

                if (stateError != null)
                {
                    var     totalError = stateError.ElapsedTime;
                    decimal?percError  = Common.GetPercentage(totalError, totalOn);
                    serieError.data.Add(((decimal)percError).RoundToInt());
                }
                else
                {
                    serieError.data.Add(0);
                }
            }

            series.Add(serieError);
            series.Add(seriePause);
            series.Add(serieManual);
            series.Add(serieProd);

            return(series);
        }