コード例 #1
0
 protected override void Add(EmployeeActionBase employeeAction)
 {
     foreach (var indicators in _indicatorsDictionary.Values)
     {
         indicators.AddQuantity(employeeAction);
     }
 }
コード例 #2
0
        public EmployeeActionBase GetDbModel(ProductivityImportModel productivityImportModel)
        {
            EmployeeActionBase action = null;

            if (productivityImportModel.ProductId == null)
            {
                if (productivityImportModel.ClientCargoQuantityt == null &&
                    productivityImportModel.CommonCargoQuantity == null &&
                    productivityImportModel.WeightPerEmployee == null &&
                    productivityImportModel.VolumePerEmployee == null)
                {
                    action = GetOtherAction(productivityImportModel);
                }
                else
                {
                    action = GetShipmentAction(productivityImportModel);
                }
            }
            else if (!string.IsNullOrWhiteSpace(productivityImportModel.SenderAddress) &&
                     string.IsNullOrWhiteSpace(productivityImportModel.ReceiverAddress))
            {
                action = GetInventoryAction(productivityImportModel);
            }
            else if (string.IsNullOrWhiteSpace(productivityImportModel.SenderAddress) &&
                     !string.IsNullOrWhiteSpace(productivityImportModel.ReceiverAddress))
            {
                action = GetReceptionAction(productivityImportModel);
            }
            else
            {
                action = GetDoubleAddressAction(productivityImportModel);
            }

            return(action);
        }
コード例 #3
0
ファイル: ImportService.cs プロジェクト: p1eXu5/WorkSpeed
            public static bool IsEmployeeBaseActionCorrect(EmployeeActionBase a)
            {
                if (a.Id.Length < 10)
                {
                    return(false);
                }
                int.TryParse(a.Id.Substring(4), out var num);

                var res = num > 0 &&
                          !string.IsNullOrWhiteSpace(a.Id) &&
                          char.IsLetter(a.Id[0]) && char.IsLetter(a.Id[1]) &&
                          char.IsDigit(a.Id[2]) && a.Id[3].Equals('-') &&
                          a.StartTime >= DNS_BEGIN_TIME && a.StartTime < _nowDate &&
                          IsEmployeeCorrect(a.Employee) &&
                          a.Operation?.Name?.Length > 1;

#if DEBUG
                if (!res)
                {
                    Debug.WriteLine($"num: {num}; a.Id[ 0 ]: {a.Id[ 0 ]}; a.Id[ 1 ]: {a.Id[ 1 ]}; a.Id[ 2 ]: {a.Id[ 2 ]}; a.Id[ 3 ]: {a.Id[ 3 ]};");
                    Debug.WriteLine($"a.StartTime: {a.StartTime}; DNS_BEGIN_TIME: {DNS_BEGIN_TIME};");
                    Debug.WriteLine($"IsEmployeeCorrect: {IsEmployeeCorrect( a.Employee )}; a.Operation?.Name?.Length: {a.Operation?.Name?.Length};");
                }
#endif
                return(res);
            }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="action"></param>
        public void AddAction(EmployeeActionBase action)
        {
            if (!_actionRepositories.ContainsKey(action.Employee.Id))
            {
                _actionRepositories[action.Employee.Id] = new RepositoryEmployeeAction(PauseBetweenActions, CategoryFilter, _pauseThreshold);
            }

            _actionRepositories[action.Employee.Id].AddAction(action);
        }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="employeeAction"></param>
        /// <returns></returns>
        public static DateTime EndTime(this EmployeeActionBase employeeAction)
        {
            if (employeeAction == null)
            {
                throw new ArgumentNullException(nameof(employeeAction), "EmployeeAction cannot be null.");
            }

            return(employeeAction.StartTime.Add(employeeAction.Duration));
        }
コード例 #6
0
        public override void AddDetails(EmployeeActionBase action, TimeSpan pause)
        {
            base.AddDetails(action, pause);

            if (!(action is ReceptionAction reception))
            {
                return;
            }

            //Scans[ _filter.GetCategoryIndex( reception.Product ) ] += reception.ScanQuantity;
        }
コード例 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="employeeAction"></param>
        /// <returns></returns>
        public static bool IsShipmentOperation(this EmployeeActionBase employeeAction)
        {
            var operationGroup = employeeAction?.Operation?.Group ?? throw new ArgumentNullException();

            switch (operationGroup)
            {
            case OperationGroups.Shipment:

                return(true);
            }

            return(false);
        }
コード例 #8
0
        public void SubstractLunch_TwoDowntimesGreaterLunch_SubstractOneLunch()
        {
            // Arrange:
            var builder           = GetBuilder();
            var momento           = builder.BuildNew();
            var shipmentOperation = new Operation {
                Name = "Packing Operation", Group = OperationGroups.Shipment
            };
            var gatheringOperation = new Operation {
                Name = "Packing Operation", Group = OperationGroups.Gathering
            };

            var shift = new Shift {
                Lunch = TimeSpan.FromMinutes(30),
            };

            var actions = new EmployeeActionBase[] {
                new ShipmentAction()
                {
                    StartTime = DateTime.Parse("22.02.2019 8:00:00"),
                    Duration  = TimeSpan.FromMinutes(60),
                    Operation = shipmentOperation,
                },

                new DoubleAddressAction()
                {
                    StartTime = DateTime.Parse("22.02.2019 9:30:20"),
                    Duration  = TimeSpan.FromMinutes(30),
                    Operation = gatheringOperation,
                },

                new DoubleAddressAction()
                {
                    StartTime = DateTime.Parse("22.02.2019 10:30:40"),
                    Duration  = TimeSpan.FromMinutes(55),
                    Operation = gatheringOperation,
                },
            };

            // Action:
            var next    = builder.CheckDuration(actions[2], momento);
            var current = builder.CheckDuration(actions[1], momento);

            next    = builder.CheckPause(current, next, momento);
            current = builder.CheckDuration(actions[0], momento);
            builder.CheckPause(current, next, momento);
            builder.SubstractLunch(shift, momento);

            // Assert:
            Assert.That(momento.DowntimePeriods, Is.Not.Empty);
        }
コード例 #9
0
        public override void AddDetails(EmployeeActionBase action, TimeSpan pause)
        {
            base.AddDetails(action, pause);

            //if ( !(action is WithProductAction withProductAction) ) return;

            //var product = withProductAction.Product;
            //var category = _filter.GetCategoryIndex( product );

            //if ( category < 0) return;

            //Weight[ category ] += product.Weight * withProductAction.ProductQuantity;
            //Volume[ category ] += product.GetVolume() * withProductAction.ProductQuantity;
            //Quantity[ category ] += withProductAction.ProductQuantity;
            //Lines[ category ]++;
        }
コード例 #10
0
        /// <summary>
        /// Null check.
        /// </summary>
        /// <param name="action"><see cref="EmployeeAction"/></param>
        /// <param name="pause">Pause between actions</param>
        public virtual void AddDetails(EmployeeActionBase action, TimeSpan pause)
        {
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action), "EmployeeActiuon cannot be null.");
            }

            End = action.StartTime.Add(action.Duration);

            if (Duration == TimeSpan.Zero)
            {
                Start = action.StartTime;
            }

            Duration += pause + action.Duration;
        }
コード例 #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="employeeAction"></param>
        /// <returns></returns>
        public static bool IsGatheringOperation(this EmployeeActionBase employeeAction)
        {
            var operationGroup = employeeAction?.Operation?.Group ?? throw new ArgumentNullException();

            switch (operationGroup)
            {
            case OperationGroups.Gathering:
            case OperationGroups.Packing:
            case OperationGroups.Defragmentation:
            case OperationGroups.Placing:

                return(true);
            }

            return(false);
        }
コード例 #12
0
        public void SubstractBreaks__ShipmentActionWhenBreakTime_FirstDowntimeInTime__DowntimesNotEmptyInResult()
        {
            // Arrange:
            var builder           = GetBuilder();
            var momento           = builder.BuildNew();
            var shipmentOperation = new Operation {
                Name = "Packing Operation", Group = OperationGroups.Shipment
            };
            var gatheringOperation = new Operation {
                Name = "Packing Operation", Group = OperationGroups.Gathering
            };

            var shortBreaks = new ShortBreakSchedule {
                Duration       = TimeSpan.FromMinutes(5),
                FirstBreakTime = new TimeSpan(8, 55, 0),
                Periodicity    = TimeSpan.FromHours(1)
            };

            var actions = new EmployeeActionBase[] {
                new ShipmentAction()
                {
                    StartTime = DateTime.Parse("22.02.2019 8:00:00"),
                    Duration  = TimeSpan.FromMinutes(110),
                    Operation = shipmentOperation,
                },

                new DoubleAddressAction()
                {
                    StartTime = DateTime.Parse("22.02.2019 10:10:20"),
                    Duration  = TimeSpan.FromMinutes(55),
                    Operation = gatheringOperation,
                },
            };

            // Action:
            var next    = builder.CheckDuration(actions[1], momento);
            var current = builder.CheckDuration(actions[0], momento);

            builder.CheckPause(current, next, momento);
            builder.SubstractBreaks(shortBreaks, momento);

            // Assert:
            Assert.That(momento.DowntimePeriods, Is.Not.Empty);
        }
コード例 #13
0
        private ProductivityTime GetProductivityTimer(EmployeeActionBase employeeAction, AddTimeOptions option, ProductivityTime timer)
        {
            switch (option)
            {
            case AddTimeOptions.Continuous:

                var endTime = employeeAction.StartTime.Add(employeeAction.Duration);
                timer.Duration = endTime - timer.EndTime;
                timer.EndTime  = endTime;

                break;

            case AddTimeOptions.Duration:

                timer.Duration += employeeAction.Duration;
                timer.EndTime   = employeeAction.StartTime.Add(employeeAction.Duration);

                break;
            }

            return(timer);
        }
コード例 #14
0
        /// <summary>
        ///     #1. Check operation duration.
        ///     BreakDuration changes for receptions, buyer gatheriond and (probably) for
        ///     packing operation (if it was fast packing).
        /// </summary>
        /// <param name="action"></param>
        /// <param name="momento"></param>
        /// <returns></returns>
        public (Period, EmployeeActionBase) CheckDuration(EmployeeActionBase action, ShortBreakInspectorMomento momento)
        {
            if (action.Operation == null)
            {
                throw new ArgumentException(@"Operation cannot be null.", nameof(action.Operation));
            }

            Period period;

            switch (action.GetOperationGroup())
            {
            case OperationGroups.Packing:
                var newDuration = (( DoubleAddressAction )action).GetPackingDuration(new[] { 7.0, 8.0, 9.0, 10.0 });
                period = new Period(action.StartTime, action.StartTime.Add(newDuration));
                break;

            case OperationGroups.BuyerGathering:
                newDuration = (( DoubleAddressAction )action).GetBuyerGatheringDuration(5, 30, 60);
                period      = new Period(action.StartTime, action.StartTime.Add(newDuration));
                break;

            case OperationGroups.Reception:
                period = new Period(action.StartTime, action.StartTime.Add(action.Duration + TimeSpan.FromSeconds(10)));
                break;

            default:
                period = new Period(action.StartTime, action.StartTime.Add(action.Duration));
                break;
            }

            if (!momento.ProductivityMap.ContainsKey(action.Operation))
            {
                momento.ProductivityMap[action.Operation] = new Productivity();
            }
            momento.ProductivityMap[action.Operation].Add(action, period);

            return(period, action);
        }
コード例 #15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="action"></param>
        public void AddAction(EmployeeActionBase action)
        {
            if (_lastAction != null)
            {
                var lastActionEnd = _lastAction.StartTime.Add(_lastAction.Duration);

                if (lastActionEnd > action.StartTime)
                {
                    var diff = lastActionEnd - action.StartTime;
                    _lastAction.Duration -= diff;

                    var lastOperation = ( int )_lastAction.GetOperationGroup();
                    _actions[lastOperation].Duration -= diff;
                }
            }

            var pause = _pause.GetPauseInterval(_lastAction, action);

            _pauses.Enqueue(pause);

            if (pause > _pauseThreshold)
            {
                // OffTime
                //_actions[ _actions.Length - 1 ].AddDetails( new EmployeeActionBase(), pause - _pauseThreshold );
                pause = _pauseThreshold;
            }

            if (pause < TimeSpan.Zero)
            {
                pause = _pauseThreshold;
            }

            var operation = ( int )action.GetOperationGroup();

            _actions[operation].AddDetails(action, pause);

            UpdateLastAction(action);
        }
コード例 #16
0
ファイル: CargoIndicators.cs プロジェクト: p1eXu5/WorkSpeed
 protected override void Add(EmployeeActionBase employeeAction)
 {
     throw new NotImplementedException();
 }
コード例 #17
0
ファイル: Productivity.cs プロジェクト: p1eXu5/WorkSpeed
 public Period this [EmployeeActionBase action]
 {
     get => _actionPeriodMap[action];
コード例 #18
0
ファイル: Productivity.cs プロジェクト: p1eXu5/WorkSpeed
 public void Add(EmployeeActionBase action, Period period)
 {
     _actionPeriodMap[action] = period;
 }
コード例 #19
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="employeeAction"></param>
 /// <returns></returns>
 public static OperationGroups GetOperationGroup(this EmployeeActionBase employeeAction)
 {
     return(employeeAction?.Operation?.Group ?? throw new ArgumentNullException());
 }
コード例 #20
0
ファイル: LineIndicators.cs プロジェクト: p1eXu5/WorkSpeed
 protected override void Add(EmployeeActionBase employeeAction)
 {
 }
コード例 #21
0
 protected abstract void Add(EmployeeActionBase employeeAction);
コード例 #22
0
        public void AddTime(EmployeeActionBase employeeAction, AddTimeOptions option = AddTimeOptions.Duration)
        {
            switch (employeeAction.Operation.Group)
            {
            case OperationGroups.Gathering:
            case OperationGroups.Packing:

                (( TimeIndicators )Times).GatheringTime +=
                    GetProductivityTimer(employeeAction, option, (( TimeIndicators )Times).GatheringTime);
                break;

            //case OperationGroups.ClientGathering :
            //case OperationGroups.ClientPacking :

            //    (( TimeIndicators )Times).ClientGatheringTime +=
            //        GetProductivityTimer( employeeAction,  option,  (( TimeIndicators )Times).ClientGatheringTime );
            //    break;

            //case OperationGroups.ShopperGathering:

            //    (( TimeIndicators )Times).ShopperGatheringTime +=
            //        GetProductivityTimer( employeeAction,  option,  (( TimeIndicators )Times).ShopperGatheringTime );
            //    break;

            //case OperationGroups.Scanning :

            //    (( TimeIndicators )Times).ScanningTime +=
            //        GetProductivityTimer( employeeAction,  option,  (( TimeIndicators )Times).ScanningTime );
            //    break;

            //case OperationGroups.ClientScanning :

            //    (( TimeIndicators )Times).ClientScanningTime +=
            //        GetProductivityTimer( employeeAction,  option,  (( TimeIndicators )Times).ClientScanningTime );
            //    break;

            case OperationGroups.Defragmentation:

                (( TimeIndicators )Times).DefragmentationTime +=
                    GetProductivityTimer(employeeAction, option, (( TimeIndicators )Times).DefragmentationTime);
                break;

            case OperationGroups.Placing:

                (( TimeIndicators )Times).PlacingTime +=
                    GetProductivityTimer(employeeAction, option, (( TimeIndicators )Times).PlacingTime);
                break;

            case OperationGroups.Inventory:

                (( TimeIndicators )Times).InventoryTime +=
                    GetProductivityTimer(employeeAction, option, (( TimeIndicators )Times).InventoryTime);
                break;

            case OperationGroups.Shipment:

                (( TimeIndicators )Times).ShipmentTime +=
                    GetProductivityTimer(employeeAction, option, (( TimeIndicators )Times).ShipmentTime);
                break;

            default:

                (( TimeIndicators )Times).NonProductivTime +=
                    GetProductivityTimer(employeeAction, option, (( TimeIndicators )Times).NonProductivTime);
                break;
            }
        }
コード例 #23
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="lastAction"></param>
        /// <param name="action"></param>
        /// <returns>TimeSpan.Zero if another shift.</returns>
        public TimeSpan GetPauseInterval(EmployeeActionBase lastAction, EmployeeActionBase action)
        {
            if (lastAction == null || lastAction.StartTime == action.StartTime)
            {
                return(TimeSpan.Zero);
            }

            Period pause;

            if (action.StartTime > lastAction.StartTime)
            {
                if (lastAction.EndTime() > action.StartTime)
                {
                    return(TimeSpan.Zero);
                }
                pause = new Period(lastAction.EndTime(), action.StartTime);
            }
            else
            {
                if (action.EndTime() > lastAction.StartTime)
                {
                    return(TimeSpan.Zero);
                }
                pause = new Period(action.EndTime(), lastAction.StartTime);
            }

            var duration = pause.Duration;

            if (duration < TimeSpan.Zero)
            {
                throw new InvalidOperationException("Pause duration less than TimeSpan.Zero");
            }
            if (duration < BreakRepository.ShortBreakDownLimit)
            {
                return(pause.Duration);
            }

            if (duration > MinRestBetweenShifts)
            {
                return(TimeSpan.FromSeconds(-1));
            }


            if (duration > BreakRepository.ShortBreakUpLimit)
            {
                var shiftList = BreakRepository.CheckLunchBreak(pause);

                if (shiftList.Any())
                {
                    for (int i = 0; i < shiftList.Length; ++i)
                    {
                        var date = lastAction.StartTime.Date;

                        if (!_catchedLunches.ContainsKey(date) ||
                            !_catchedLunches[date].Contains(shiftList[i]))
                        {
                            if (duration > shiftList[i].Lunch)
                            {
                                duration -= shiftList[i].Lunch;

                                if (!_catchedLunches.ContainsKey(date))
                                {
                                    _catchedLunches[date] = new Queue <Shift>(new [] { shiftList[i] });
                                }
                                else
                                {
                                    _catchedLunches[date].Enqueue(shiftList[i]);
                                }
                            }
                        }
                    }
                }
            }

            if (duration >= BreakRepository.ShortBreakDownLimit)
            {
                if (pause.Duration > duration)
                {
                    var leftPause  = new Period(pause.Start, pause.End.Subtract(duration));
                    var rightPause = new Period(pause.Start.Add(duration), pause.End);

                    var leftShortBreakRes  = BreakRepository.CheckShortBreak(leftPause, lastAction.Employee);
                    var rightShortBreakRes = BreakRepository.CheckShortBreak(rightPause, lastAction.Employee);

                    (ShortBreakSchedule shortBreak, TimeSpan breakLength)resShortBreakRes = (null, TimeSpan.Zero);

                    if (leftShortBreakRes.shortBreak != null && rightShortBreakRes.shortBreak != null)
                    {
                        if (leftShortBreakRes.breakLength > rightShortBreakRes.breakLength)
                        {
                            resShortBreakRes = leftShortBreakRes;
                        }
                        else
                        {
                            resShortBreakRes = rightShortBreakRes;
                        }
                    }
                    else if (rightShortBreakRes.shortBreak != null)
                    {
                        resShortBreakRes = rightShortBreakRes;
                    }
                    else if (leftShortBreakRes.shortBreak != null)
                    {
                        resShortBreakRes = leftShortBreakRes;
                    }

                    duration -= resShortBreakRes.breakLength;

                    while (duration < TimeSpan.Zero)
                    {
                        duration += leftShortBreakRes.shortBreak.Duration;
                    }
                }
                else
                {
                    var shortBreakRes = BreakRepository.CheckShortBreak(pause, lastAction.Employee);

                    if (shortBreakRes.shortBreak != null)
                    {
                        duration -= shortBreakRes.breakLength;

                        while (duration < TimeSpan.Zero)
                        {
                            duration += shortBreakRes.shortBreak.Duration;
                        }
                    }
                }
            }

            return(duration);
        }
コード例 #24
0
 private void UpdateLastAction(EmployeeActionBase action)
 {
     _lastAction = action;
 }