private void Check(AutoSanctionCycleConfig[] cycles, int numCards, int expectedIteration, int expectedRuleIndex)
        {
            var resultIteration = AutoSanctionDispatcher.GetCycleIterationForNumCards(cycles, numCards, out AutoSanctionCycleConfig rule);

            Assert.AreEqual(expectedIteration, resultIteration);
            Assert.AreEqual(cycles[expectedRuleIndex], rule);
        }
示例#2
0
        public void ComboMatchesEvents_InverseMatch()
        {
            // Ensure blue + yellow matches yellow + blue combo

            var events = new MatchEvent[]
            {
                // Blue + yellow
                new MatchEvent {
                    Id = 11, IdMatch = 1001, Type = (int)MatchEventType.Card3, IdPlayer = 101, MatchMinute = 8
                },
                new MatchEvent {
                    Id = 12, IdMatch = 1001, Type = (int)MatchEventType.Card1, IdPlayer = 101, MatchMinute = 20
                },
            };

            // Yellow + Blue generate red card
            var combo = new AutoSanctionCardConfig {
                Card1Type = 1, Card2Type = 3, Penalty = new PenaltyConfig {
                    Type1 = 2
                }
            };

            var result = AutoSanctionDispatcher.ComboAppliesToMatchEvents(combo, events, out MatchEvent ev1, out MatchEvent ev2);

            Assert.IsTrue(result);
        }
        public void ComboMatchesEvents_Single()
        {
            var events = new MatchEvent[]
            {
                // Two yellow cards
                new MatchEvent {
                    Id = 11, IdMatch = 1001, Type = (int)MatchEventType.Card1, IdPlayer = 101, MatchMinute = 8
                },
                new MatchEvent {
                    Id = 12, IdMatch = 1001, Type = (int)MatchEventType.Card1, IdPlayer = 101, MatchMinute = 20
                },
                new MatchEvent {
                    Id = 13, IdMatch = 1001, Type = (int)MatchEventType.Card3, IdPlayer = 101, MatchMinute = 20
                },
                new MatchEvent {
                    Id = 14, IdMatch = 1001, Type = (int)MatchEventType.Card2, IdPlayer = 101, MatchMinute = 30
                },
            };

            var combos = new AutoSanctionCardConfig[]
            {
                new AutoSanctionCardConfig {
                    Card1Type = 1, Card2Type = 1, Penalty = new PenaltyConfig {
                        Type1 = 2
                    }
                },
            };

            var result = AutoSanctionDispatcher.GetCardCombosForMatchEvents(combos, events);

            Assert.AreEqual(1, result.Count());
            Assert.AreEqual(combos[0], result[0]);
        }
示例#4
0
        public IActionResult InsertOrUpdate([FromBody] AutoSanctionConfig asc)
        {
            return(DbTransaction((c, t) =>
            {
                if (asc == null)
                {
                    throw new NoDataException();
                }

                if (!AutoSanctionDispatcher.IsValidConfig(asc.Config))
                {
                    throw new Exception("Error.InvalidConfig");
                }

                CheckAuthLevel(UserLevel.OrgAdmin);

                var dbSanctionConfig = c.Query <AutoSanctionConfig>("SELECT * FROM autosanctionconfigs WHERE idtournament = @idTournament", new { idTournament = asc.IdTournament }, t).SingleOrDefault();

                if (dbSanctionConfig == null)
                {
                    var newId = c.Insert(asc, t);
                    return newId;
                }
                else
                {
                    dbSanctionConfig.Config = asc.Config;
                    var result = c.Update(dbSanctionConfig, t);
                    return asc.Id;
                }
            }));
        }
        public void GroupPlayerEvents22()
        {
            var events = new MatchEvent[]
            {
                new MatchEvent {
                    Id = 11, IdMatch = 1001, Type = (int)MatchEventType.Card1, IdPlayer = 101, MatchMinute = 8
                },
                new MatchEvent {
                    Id = 12, IdMatch = 1001, Type = (int)MatchEventType.Card1, IdPlayer = 101, MatchMinute = 20
                },
                new MatchEvent {
                    Id = 13, IdMatch = 1001, Type = (int)MatchEventType.Card3, IdPlayer = 102, MatchMinute = 20
                },
                new MatchEvent {
                    Id = 14, IdMatch = 1001, Type = (int)MatchEventType.Card2, IdPlayer = 102, MatchMinute = 30
                },
            };

            var result = AutoSanctionDispatcher.GroupPlayerEvents(events);

            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(2, result[101].Count);
            Assert.AreEqual(2, result[102].Count);

            Assert.AreEqual(events[0], result[101][0]);
            Assert.AreEqual(events[1], result[101][1]);
            Assert.AreEqual(events[2], result[102][0]);
            Assert.AreEqual(events[3], result[102][1]);
        }
        public void GetCardCyclesSanctionsNull1()
        {
            var cc     = AutoSanctionDispatcher_CycleTests.GetCycleConfigs(5, 4, 3);
            var result = AutoSanctionDispatcher.GetCardCyclesSanctions(null, null, cc, new Match());

            Assert.IsNull(result);
        }
示例#7
0
        public void ComboMatchesEvents_Larger()
        {
            // Ensure yellow, yellow, blue, yellow matches blue alone

            var events = new MatchEvent[]
            {
                new MatchEvent {
                    Id = 11, IdMatch = 1001, Type = (int)MatchEventType.Card1, IdPlayer = 101, MatchMinute = 8
                },
                new MatchEvent {
                    Id = 12, IdMatch = 1001, Type = (int)MatchEventType.Card1, IdPlayer = 101, MatchMinute = 20
                },
                new MatchEvent {
                    Id = 11, IdMatch = 1001, Type = (int)MatchEventType.Card3, IdPlayer = 101, MatchMinute = 8
                },
                new MatchEvent {
                    Id = 12, IdMatch = 1001, Type = (int)MatchEventType.Card1, IdPlayer = 101, MatchMinute = 20
                },
            };

            // Blue alone generates red card
            var combo = new AutoSanctionCardConfig {
                Card1Type = 3, Card2Type = 0, Penalty = new PenaltyConfig {
                    Type1 = 2
                }
            };

            var result = AutoSanctionDispatcher.ComboAppliesToMatchEvents(combo, events, out MatchEvent ev1, out MatchEvent ev2);

            Assert.IsTrue(result);
        }
        private IEnumerable <Sanction> Check(AutoSanctionCycleConfig[] cc, int previousData1, int currentData1)
        {
            var currentAccumulated = new PlayerDayResult[]
            {
                new PlayerDayResult {
                    IdPlayer = 10, IdTeam = 1, Data1 = currentData1
                },
            };

            var previousAccumulated = new PlayerDayResult[]
            {
                new PlayerDayResult {
                    IdPlayer = 10, IdTeam = 1, Data1 = previousData1
                },
            };

            var current  = currentAccumulated.ToDictionary(pdr => pdr.IdPlayer);
            var previous = previousAccumulated.ToDictionary(pdr => pdr.IdPlayer);

            var match = new Match();

            var result = AutoSanctionDispatcher.GetCardCyclesSanctions(current, previous, cc, match);

            return(result);
        }
示例#9
0
        public void ComboMatchesEvents_Negative1()
        {
            // Ensure blue + yellow doesn't match yellow + yellow

            var events = new MatchEvent[]
            {
                new MatchEvent {
                    Id = 11, IdMatch = 1001, Type = (int)MatchEventType.Card3, IdPlayer = 101, MatchMinute = 8
                },
                new MatchEvent {
                    Id = 12, IdMatch = 1001, Type = (int)MatchEventType.Card1, IdPlayer = 101, MatchMinute = 20
                },
            };

            // Yellow + Yellow generate red card
            var combo = new AutoSanctionCardConfig {
                Card1Type = 1, Card2Type = 1, Penalty = new PenaltyConfig {
                    Type1 = 2
                }
            };

            var result = AutoSanctionDispatcher.ComboAppliesToMatchEvents(combo, events, out MatchEvent ev1, out MatchEvent ev2);

            Assert.IsFalse(result);
        }
示例#10
0
        public void ComboMatchesEvents_EqualCards()
        {
            // Ensure two yellow cards are matched

            var events = new MatchEvent[]
            {
                // Two yellow cards
                new MatchEvent {
                    Id = 11, IdMatch = 1001, Type = (int)MatchEventType.Card1, IdPlayer = 101, MatchMinute = 8
                },
                new MatchEvent {
                    Id = 12, IdMatch = 1001, Type = (int)MatchEventType.Card1, IdPlayer = 101, MatchMinute = 20
                },
            };

            // Two yellow cards generate a red card
            var combo = new AutoSanctionCardConfig {
                Card1Type = 1, Card2Type = 1, Penalty = new PenaltyConfig {
                    Type1 = 2
                }
            };

            var result = AutoSanctionDispatcher.ComboAppliesToMatchEvents(combo, events, out MatchEvent ev1, out MatchEvent ev2);

            Assert.IsTrue(result);
        }
示例#11
0
        public void DeserializeCardComboConfig()
        {
            //var input = "{\"cards\":[{\"card1Type\":1,\"card2Type\":1,\"s1\":\"\",\"penalty\":{\"text\":\"Tarjeta roja por 2 amarillas\",\"type1\":2,\"type2\":\"2\",\"type3\":0},\"s2\":\"\",\"addYellowCards\":1,\"card2type\":0,\"id\":1545848047566},{\"card1Type\":3,\"card2Type\":0,\"s1\":\"\",\"penalty\":{\"text\":\"5 partidos por tarjeta azul\",\"type1\":0,\"type2\":\"5\",\"type3\":0},\"s2\":\"\",\"addYellowCards\":0,\"card2type\":0,\"id\":1545848072412}],\"cycles\":[]}";
            //var input = @"{""cards"":[{""card1Type"":1,""card2Type"":1,""penalty"":{""text"":""Tarjeta roja por 2 amarillas"",""type1"":2,""type2"":""2"",""type3"":0},""addYellowCards"":1,""id"":1545848047566},{""card1Type"":3,""card2Type"":0,""s1"":"""",""penalty"":{""text"":""5 partidos por tarjeta azul"",""type1"":0,""type2"":""5"",""type3"":0},""s2"":"""",""addYellowCards"":0,""card2type"":0,""id"":1545848072412}],""cycles"":[]}";
            var input = @"
                {
                  ""cards"": [
                    {
                      ""card1Type"": 1,
                      ""card2Type"": 1,
                      ""s1"": """",
                      ""penalty"": {
                        ""text"": ""Roja por dos amarillas"",
                        ""type1"": 2,
                        ""type2"": ""0"",
                        ""type3"": 0
                      },
                      ""s2"": """",
                      ""addYellowCards"": 1,
                      ""id"": 1545862775520
                    },
                    {
                      ""card1Type"": 2,
                      ""card2Type"": 0,
                      ""s1"": """",
                      ""penalty"": {
                        ""text"": ""2 partidos de sanción por tarjeta roja"",
                        ""type1"": 0,
                        ""type2"": ""2"",
                        ""type3"": 0
                      },
                      ""s2"": """",
                      ""addYellowCards"": 0,
                      ""id"": 1545862802034
                    },
                    {
                      ""card1Type"": 3,
                      ""card2Type"": 0,
                      ""s1"": """",
                      ""penalty"": {
                        ""text"": ""5 partidos de sanción por tarjeta azul"",
                        ""type1"": 0,
                        ""type2"": ""5"",
                        ""type3"": 0
                      },
                      ""s2"": """",
                      ""addYellowCards"": 0,
                      ""id"": 1545862829857
                    }
                  ],
                  ""cycles"": []
                }
                ";

            var config = AutoSanctionDispatcher.ParseJsonConfig(input);

            Assert.AreEqual(1, config.Cards[0].Card2Type);
        }
        public void GetCycleIterationForNumCards13()
        {
            var cc = new AutoSanctionCycleConfig[0];

            var result = AutoSanctionDispatcher.GetCycleIterationForNumCards(cc, 0, out AutoSanctionCycleConfig rule);

            Assert.AreEqual(-1, result);
            Assert.AreEqual(null, rule);
        }
        public void GetCycleIterationForNumCards12()
        {
            var cycleConfigs = GetCycleConfigs(5, 4, 3);

            var result = AutoSanctionDispatcher.GetCycleIterationForNumCards(cycleConfigs, 0, out AutoSanctionCycleConfig rule);

            Assert.AreEqual(0, result);
            Assert.AreEqual(cycleConfigs[0], rule);
        }
        public void GetYellowCardsToSubtractForCardCombo22()
        {
            var combo = new AutoSanctionCardConfig {
                AddYellowCards = 2, Card1Type = 1, Card2Type = 1
            };
            var result = AutoSanctionDispatcher.GetYellowCardsToSubtractForCardCombo(combo);

            Assert.AreEqual(0, result);
        }
        public void GroupPlayerEvents_Empty()
        {
            var events = new MatchEvent[]
            {
            };

            var result = AutoSanctionDispatcher.GroupPlayerEvents(events);

            Assert.AreEqual(0, result.Count);
        }
        public void GetCardComboNewCards_OnlyLast()
        {
            // Several events already happened to same player, yellow arrives.
            // Check that a new event is returned with a red card, and only that.

            var events = new MatchEvent[]
            {
                new MatchEvent {
                    Id = 11, IdMatch = 1001, Type = (int)MatchEventType.Card1, IdPlayer = 101, MatchMinute = 8
                },
                new MatchEvent {
                    Id = 12, IdMatch = 1001, Type = (int)MatchEventType.Card3, IdPlayer = 101, MatchMinute = 8
                },
                new MatchEvent {
                    Id = 13, IdMatch = 1001, Type = (int)MatchEventType.Card4, IdPlayer = 101, MatchMinute = 8
                },
                new MatchEvent {
                    Id = 14, IdMatch = 1001, Type = (int)MatchEventType.Card5, IdPlayer = 101, MatchMinute = 8
                },
                new MatchEvent {
                    Id = 15, IdMatch = 1001, Type = (int)MatchEventType.Card1, IdPlayer = 101, MatchMinute = 30
                }
            };

            var combos = new AutoSanctionCardConfig[]
            {
                new AutoSanctionCardConfig {
                    Card1Type = 1, Card2Type = 1, Penalty = new PenaltyConfig {
                        Type1 = 2
                    }, AddYellowCards = 0
                },
                new AutoSanctionCardConfig {
                    Card1Type = 3, Card2Type = 0, Penalty = new PenaltyConfig {
                        Type1 = 5
                    }
                },
            };

            var newEvent = events[4];

            var result = AutoSanctionDispatcher.GetCardCombosNewCards(events, combos, newEvent);

            Assert.AreEqual(2, result.Count());

            var resultEvents = result.ToList();

            Assert.AreEqual((int)MatchEventType.Card2, resultEvents[0].Type);

            var ev2 = resultEvents[1];

            Assert.AreEqual((int)MatchEventType.AddToPdrData1, ev2.Type);
            Assert.AreEqual(-2, ev2.IntData1);
        }
        public IActionResult ClearAutomaticSanctions(long id)
        {
            return(DbTransaction((c, t) =>
            {
                if (!IsOrganizationAdmin())
                {
                    throw new UnauthorizedAccessException();
                }

                AutoSanctionDispatcher.ClearAllAutomaticSanctions(c, t, id);

                ResetStats(c, t, id).Wait();

                return true;
            }));
        }
        public void GetCardCyclesSanctionsNull3()
        {
            var cc = AutoSanctionDispatcher_CycleTests.GetCycleConfigs(5, 4, 3);

            var currentAccumulated = new PlayerDayResult[]
            {
                new PlayerDayResult {
                    IdPlayer = 10, IdTeam = 1, Data1 = 1
                },
            };

            var current = currentAccumulated.ToDictionary(pdr => pdr.IdPlayer);

            var result = AutoSanctionDispatcher.GetCardCyclesSanctions(current, null, cc, new Match());

            Assert.IsNull(result);
        }
        public void GetCardComboNewCards_Single()
        {
            var events = new MatchEvent[]
            {
                new MatchEvent {
                    Id = 11, IdMatch = 1001, Type = (int)MatchEventType.Card1, IdPlayer = 101, MatchMinute = 8
                },
                new MatchEvent {
                    Id = 15, IdMatch = 1001, Type = (int)MatchEventType.Card1, IdPlayer = 101, MatchMinute = 30
                }
            };

            var combos = new AutoSanctionCardConfig[]
            {
                new AutoSanctionCardConfig {
                    Card1Type = 1, Card2Type = 1, Penalty = new PenaltyConfig {
                        Type1 = 2
                    }, AddYellowCards = 1
                },
                new AutoSanctionCardConfig {
                    Card1Type = 2, Card2Type = 3, Penalty = new PenaltyConfig {
                        Type1 = 5
                    }
                },
            };

            var newEvent = events[1];

            var result = AutoSanctionDispatcher.GetCardCombosNewCards(events, combos, newEvent);

            Assert.AreEqual(2, result.Count());

            var resultEvents = result.ToList();

            Assert.AreEqual((int)MatchEventType.Card2, resultEvents[0].Type);

            var ev2 = resultEvents[1];

            Assert.AreEqual((int)MatchEventType.AddToPdrData1, ev2.Type);
            Assert.AreEqual(-1, ev2.IntData1);
        }