Exemplo n.º 1
0
        public bool CanWork(IShift shift)
        {
            if (_rules == null)
            {
                throw new ArgumentNullException("IBusinessRules", "Business Rules object must be set before CanWork can be called");
            }

            if (ShiftDuration >= MaxShiftDuration)
            {
                return(false);
            }

            if (!_rules.AllowConsecutiveDays)
            {
                if (Shifts.Any(s => s.Day == shift.Day - 1))
                {
                    return(false);
                }
            }

            if (Shifts.Count(s => s.Day == shift.Day) >= _rules.MaxShiftsPerDay)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        public Point GetShift(Position cursor_position)
        {
            LastPosition = cursor_position;
            CursorPositionUpdated?.Invoke(this, new EventArgs());
            var closest_indices = GetClosestShiftIndexes(cursor_position, Options.Instance.calibration_mode.considered_zones_count);

            if (closest_indices == null)
            {
                Debug.Assert(Shifts.Count() == 0);
                return(new Point(0, 0));
            }

            double sum_of_reverse_distances = 0;

            foreach (var index in closest_indices)
            {
                sum_of_reverse_distances += (1 / index.Item2);
            }

            Point resulting_shift = new Point(0, 0);

            foreach (var index in closest_indices)
            {
                resulting_shift.X += (int)(Shifts[index.Item1].Shift.X / index.Item2 / sum_of_reverse_distances);
                resulting_shift.Y += (int)(Shifts[index.Item1].Shift.Y / index.Item2 / sum_of_reverse_distances);
            }

            return(resulting_shift);
        }
Exemplo n.º 3
0
        private List <Tuple <int /*index*/, double /*distance*/> > GetClosestShiftIndexes(Position cursor_position, int number)
        {
            if (Shifts.Count() == 0)
            {
                return(null);
            }

            var retval = new List <Tuple <int, double> >();

            for (int i = 0; i < Shifts.Count(); i++)
            {
                double distance = Shifts[i].Position.GetDistance(cursor_position);
                if (distance < 0.1)
                {
                    distance = 0.1;
                }

                if (retval.Count == 0)
                {
                    retval.Add(new Tuple <int, double>(i, distance));
                    continue;
                }

                int j = 0;
                for (; j < retval.Count; j++)
                {
                    if (distance < retval[j].Item2)
                    {
                        retval.Insert(j, new Tuple <int, double>(i, distance));
                        break;
                    }
                }
                if (j == retval.Count)
                {
                    retval.Add(new Tuple <int, double>(i, distance));
                }

                if (retval.Count > number)
                {
                    retval.RemoveAt(retval.Count - 1);
                }
            }
            return(retval);
        }
Exemplo n.º 4
0
        public void AddShift(Position cursor_position, Point shift)
        {
            var indices = GetClosestShiftIndexes(cursor_position, 2);

            if (indices != null && indices[0].Item2 < Options.Instance.calibration_mode.zone_size)
            {
                Shifts[indices[0].Item1] = new ShiftItem(cursor_position, shift);
                if (indices.Count > 1 && indices[1].Item2 < Options.Instance.calibration_mode.zone_size)
                {
                    Shifts.RemoveAt(indices[1].Item1);
                }
            }
            else if (Shifts.Count() < Options.Instance.calibration_mode.max_zones_count)
            {
                Shifts.Add(new ShiftItem(cursor_position, shift));
            }
            else
            {
                Shifts[GetClosestPointOfHihestDensity(cursor_position)] = new ShiftItem(cursor_position, shift);
            }

            AsyncSaver.Save(Filepath, GetDeepCopy);
            NotifyOnChange();
        }