Ejemplo n.º 1
0
        private static bool Check_bin(int binIndex, SelectDueCardContextModel model)
        {
            if (binIndex <= 0)
            {
                return(false);
            }
            if (binIndex >= model.Bins.Length)
            {
                return(false);
            }
            if (model.Bins[binIndex].Length == 0)
            {
                return(false);
            }

            var configIndex = binIndex - 1;

            if (configIndex < 0)
            {
                return(false);
            }
            if (configIndex >= model.Config.Bins.Length)
            {
                return(false);
            }

            if (binIndex == model.DueBinIndex)
            {
                return(model.Bins[binIndex].Length >= model.Config.Bins[configIndex].LowerDueThreshold);
            }

            return(model.Bins[binIndex].Length >= model.Config.Bins[configIndex].UpperDueThreshold);
        }
Ejemplo n.º 2
0
 private static Event[] Select_first_bin_with_cards(SelectDueCardContextModel model)
 {
     for (var i = 1; i < Math.Min(model.Bins.Length - 1, model.Config.Bins.Length + 1); i++)
     {
         if (model.Bins[i].Length > 0)
         {
             return new[] { new DueCardSelected {
                                CardId = model.Bins[i].First(), BinIndex = i
                            } }
         }
     }
     ;
     return(new Event[0]);
 }
Ejemplo n.º 3
0
        private static Event[] Select_due_bin_in_specific_order(SelectDueCardContextModel model)
        {
            var dueBinIndex = Order_in_which_to_check_bins().FirstOrDefault(binIndex => Check_bin(binIndex, model));

            return(dueBinIndex > 0
                    ? new[] { new DueCardSelected {
                                  CardId = model.Bins[dueBinIndex].First(), BinIndex = dueBinIndex
                              } }
                    : new Event[0]);


            IEnumerable <int> Order_in_which_to_check_bins()
            => new[] { model.DueBinIndex,
                       1 }
            .Concat(Enumerable.Range(2, model.Config.Bins.Length - 1).Reverse());
        }
Ejemplo n.º 4
0
        private static Event[] Fill_bin_1_and_select(SelectDueCardContextModel model)
        {
            var additionalCardsForBin1 = model.Bins[0].Take(model.Config.Bins[0].UpperDueThreshold - model.Bins[1].Length).ToArray();

            model.Bins[1] = model.Bins[1].Concat(additionalCardsForBin1).ToArray();

            var events = additionalCardsForBin1.Select(cardId => new CardMovedTo {
                CardId = cardId, BinIndex = 1
            }).ToList <Event>();

            if (Check_bin(1, model))
            {
                events.Add(new DueCardSelected {
                    CardId = model.Bins[1].First(), BinIndex = 1
                });
            }

            return(events.ToArray());
        }