public IEnumerable<GameEvent> Get(long gameId) { using (var repository = new GameEventRepository()) { return (from evnt in repository.GetAll() where evnt.GameId == gameId select evnt).OrderBy(evnt => evnt.Timestamp).ToList(); } }
public void Update() { // Delete everything using (var repository = new TopEventRepository()) { var evnts = (from evnt in repository.GetAll() select evnt).ToList(); foreach(var evnt in evnts) { repository.Delete(evnt); } } // update top points by count List<ActivityPoint> topPoints = new List<ActivityPoint>(); List<GameEvent> topEvents = new List<GameEvent>(); int skipPoints = 0; while (topEvents.Count < 10) { ActivityPoint point = null; GameEvent gameEvent = null; using (var repository = new ActivityRepository()) { point = (from p in repository.DataSet.Include("Game") where p.Game.TweetCount > 0 && (p.Time < p.Game.HalftimeStart || p.Game.HalftimeEnd < p.Time) select p).OrderByDescending(p => p.TweetCount).Skip(skipPoints).Take(1).First(); } using (var repository = new GameEventRepository()) { gameEvent = (from evnt in repository.GetAll() where evnt.GameId == point.GameId && evnt.Timestamp < point.Time select evnt).OrderByDescending(evnt => evnt.Timestamp).Take(1).SingleOrDefault(); } if (gameEvent == null || gameEvent.Type == GameEventType.FIRST_HALF_START || gameEvent.Type == GameEventType.FIRST_HALF_END || gameEvent.Type == GameEventType.SECOND_HALF_START || gameEvent.Type == GameEventType.SECOND_HALF_END || topEvents.Where(evnt => evnt.Id == gameEvent.Id).Count() > 0) { // this event is already in the list skipPoints++; } else { topEvents.Add(gameEvent); topPoints.Add(point); } } using (var repository = new TopEventRepository()) { for (int i = 0; i < topPoints.Count; i++) { TopEvent evnt = new TopEvent() { IsRelativeTop = false, Rank = i + 1, GameId = topPoints[i].GameId, ActivityId = topPoints[i].Id, EventId = topEvents[i].Id }; repository.Save(evnt); } } // update top points by percentage topPoints = new List<ActivityPoint>(); topEvents = new List<GameEvent>(); skipPoints = 0; while (topEvents.Count < 10) { ActivityPoint point = null; GameEvent gameEvent = null; using (var repository = new ActivityRepository()) { point = (from p in repository.DataSet.Include("Game") where p.Game.TweetCount > 0 && (p.Time < p.Game.HalftimeStart || p.Game.HalftimeEnd < p.Time) select p).OrderByDescending(p => (double)p.TweetCount / (double)p.Game.TweetCount).Skip(skipPoints).Take(1).First(); } using (var repository = new GameEventRepository()) { gameEvent = (from evnt in repository.GetAll() where evnt.GameId == point.GameId && evnt.Timestamp < point.Time select evnt).OrderByDescending(evnt => evnt.Timestamp).Take(1).SingleOrDefault(); } if (gameEvent == null || gameEvent.Type == GameEventType.FIRST_HALF_START || gameEvent.Type == GameEventType.FIRST_HALF_END || gameEvent.Type == GameEventType.SECOND_HALF_START || gameEvent.Type == GameEventType.SECOND_HALF_END || topEvents.Where(evnt => evnt.Id == gameEvent.Id).Count() > 0) { // this event is already in the list skipPoints++; } else { topEvents.Add(gameEvent); topPoints.Add(point); } } using (var repository = new TopEventRepository()) { for (int i = 0; i < topPoints.Count; i++) { TopEvent evnt = new TopEvent() { IsRelativeTop = true, Rank = i + 1, GameId = topPoints[i].GameId, ActivityId = topPoints[i].Id, EventId = topEvents[i].Id }; repository.Save(evnt); } } }