public void EventFromJsonEventSecondHalfTest()
        {
            // set up
            DateTime start = new DateTime(2014, 1, 1);
            GameEventMiner miner = new GameEventMiner();
            GameEvent evnt = null;
            Game game = new Game()
            {
                Id = 1,
                Start = start,
                HalftimeStart = start.AddMinutes(45)
            };
            JsonGameEvent jsonEvnt = new JsonGameEvent()
            {
                Comment = "Goal",
                CommentTypeId = 1,
                MatchPeriodId = 2,
                Minute = 55,
                Second = 2,
                Time = "55'"
            };

            // exercise
            evnt = miner.EventFromJsonEvent(jsonEvnt, game);

            // validate
            Assert.IsNotNull(evnt);
            Assert.AreEqual(GameEventType.GOAL, evnt.Type);
            Assert.AreEqual(new DateTime(2014, 1, 1, 1, 10, 2), evnt.Timestamp);
            Assert.AreEqual("55'", evnt.MatchTime);
            Assert.AreEqual("Goal", evnt.Comment);
        }
        public void EventFromJsonEventFailTest()
        {
            // set up
            GameEventMiner miner = new GameEventMiner();
            GameEvent evnt = null;
            Game game = new Game()
            {
                Id = 1,
                Start = new DateTime(2014, 1, 1)
            };
            JsonGameEvent jsonEvnt = new JsonGameEvent()
            {
                Comment = "Invalid",
                CommentTypeId = 99,
                MatchPeriodId = 1,
                Minute = 40,
                Second = 2,
                Time = "40'"
            };

            // exercise
            evnt = miner.EventFromJsonEvent(jsonEvnt, game);

            // validate
            Assert.IsNull(evnt);
        }
예제 #3
0
        static void Main(string[] args)
        {
            if (args[0] == "fixture")
            {
                int start = Int32.Parse(args[1]);
                int end = Int32.Parse(args[2]);
                var miner = new FixtureMiner()
                {
                    StartWeek = start,
                    EndWeek = end
                };
                miner.Mine();
            }
            else if (args[0] == "event")
            {
                int matchId = -1;
                int dayIdStart = -1;
                int dayIdEnd = -1;
                if (args.Length == 4)
                {
                    matchId = Int32.Parse(args[1]);
                    dayIdStart = Int32.Parse(args[2]);
                    dayIdEnd = Int32.Parse(args[3]);
                }
                else if (args.Length == 2)
                {
                    dayIdEnd = Int32.Parse(args[1]);
                    using (var repository = new GameRepository())
                    {
                        var game = repository.GetAll()
                            .Where(g => g.MatchDay == dayIdEnd - 1)
                            .OrderByDescending(g => g.LiveMatchId ?? -1).Take(1).First();
                        matchId = (int)game.LiveMatchId + 1;
                        dayIdStart = dayIdEnd;
                    }
                }
                else
                {
                    using (var repository = new GameRepository())
                    {
                        var game = repository.GetAll().OrderByDescending(g => g.LiveMatchId ?? -1).Take(1).First();
                        matchId = (int)game.LiveMatchId + 1;
                        dayIdStart = (int)game.MatchDay;
                        dayIdEnd = 38; // assume 38 weeks in season
                    }
                }
                GameEventMiner miner = new GameEventMiner()
                {
                    StartMatchId = matchId,
                    StartMatchDayId = dayIdStart,
                    EndMatchDayId = dayIdEnd
                };
                miner.Mine();

            }
            else if (args[0] == "twitter")
            {
                int minMatchDay = 0;
                if (args.Length == 2)
                {
                    minMatchDay = Int32.Parse(args[1]);
                }
                TweetMiner miner = new TweetMiner()
                {
                    MinGameDay = minMatchDay
                };
                var task = miner.Mine();
                Console.Out.WriteLine("Complete!");
            }
            else if (args[0] == "print")
            {
                long id = 0;
                DateTime time;
                if (args.Length == 3)
                {
                    time = DateTime.Parse(args[1]);
                    DateTimeOffset offset = new DateTimeOffset(time, new TimeSpan(0, 0, 0));
                    id = long.Parse(args[2]);
                    TweetMiner miner = new TweetMiner();
                    miner.PrintTweetsAfterTime(time, id);
                }
            }
            else if (args[0] == "activity")
            {
                ActivityChartManager manager = new ActivityChartManager();
                manager.UpdateAll();

                Console.Out.WriteLine("Complete!");
            }
            else if (args[0] == "counts")
            {
                TweetCountManager manager = new TweetCountManager();
                manager.UpdateAll();

                Console.Out.WriteLine("Complete!");
            }
            else if (args[0] == "topevents")
            {
                TopEventManager top = new TopEventManager();
                top.Update();
                Console.Out.WriteLine("Complete!");
            }
        }
        public void EventFromJsonEventTest()
        {
            // set up
            GameEventMiner miner = new GameEventMiner();
            GameEvent evnt = null;
            Game game = new Game()
            {
                Id = 1,
                Start = new DateTime(2014, 1, 1)
            };
            JsonGameEvent jsonEvnt = new JsonGameEvent()
            {
                Comment = "Goal",
                CommentTypeId = 5,
                MatchPeriodId = 1,
                Minute = 40,
                Second = 2,
                Time = "40'"
            };

            // exercise
            evnt = miner.EventFromJsonEvent(jsonEvnt, game);

            // validate
            Assert.IsNotNull(evnt);
            Assert.AreEqual(GameEventType.RED, evnt.Type);
            Assert.AreEqual(new DateTime(2014, 1, 1, 0, 40, 2), evnt.Timestamp);
            Assert.AreEqual("40'", evnt.MatchTime);
            Assert.AreEqual("Goal", evnt.Comment);
        }
        public void GetJsonEventsFromCommentaryTest()
        {
            // set up
            string testData = File.ReadAllText("Resources/commentary-example.txt");
            GameEventMiner miner = new GameEventMiner();

            // execute
            List<JsonGameEvent> events = miner.GetJsonEventsFromCommentary(testData);

            Assert.IsNotNull(events);
            Assert.IsTrue(events.Count > 0);
            Assert.AreEqual("Match ends, Chelsea 6, Arsenal 0.", events[0].Comment);
        }
        public void GetGameFromDetailsDataTest()
        {
            // set up
            string testData = File.ReadAllText("Resources/details-example.txt");
            DateTime kickoff = new DateTime(2014, 3, 29, 17, 30, 00);
            GameEventMiner miner = new GameEventMiner();
            Team ars = null, mci = null;
            using (var repository = new TeamRepository())
            {
                ars = repository.GetAll().Where(t => t.ShortName.Equals("ARS")).SingleOrDefault();
                mci = repository.GetAll().Where(t => t.ShortName.Equals("MCI")).SingleOrDefault();
            }

            // execute
            Game game = miner.GetGameFromDetailsData(testData);

            Assert.IsNotNull(game);
            Assert.AreEqual(ars.Id, game.HomeTeamId);
            Assert.AreEqual(mci.Id, game.AwayTeamId);
            Assert.AreEqual(kickoff, game.Start);
        }