Esempio n. 1
0
        private void RaiseGameEvent(string jsonString)
        {
            TimeOfLastRadarGameEventOrHeartbeat = DateTime.Now;
            bool            isHeartbeat     = jsonString.Contains("heartbeat");
            NcaafbGameEvent ncaafbGameEvent = null;

            //if (isHeartbeat)
            //{
            //    Logger.Info("Radar heartbeat");
            //}

            if (!isHeartbeat)
            {
                Logger.Info(jsonString);
                ncaafbGameEvent = NcaafbGameEvent.FromJson(jsonString);
            }

            bool isGameEvent = ncaafbGameEvent != null;

            if (isGameEvent)
            {
                NcaafbGameEventEventArgs ncaafbGameEventEventArgs = new NcaafbGameEventEventArgs
                {
                    GameEvent = ncaafbGameEvent
                };
                OnRadarGameEvent(ncaafbGameEventEventArgs);
            }
        }
Esempio n. 2
0
        private void HandleGameEvent(object sender, NcaafbGameEventEventArgs ncaafbGameEventEventArgs)
        {
            NcaafbGameEvent ncaafbGameEvent = ncaafbGameEventEventArgs.GameEvent;
            Guid            gameId          = ncaafbGameEvent.Payload.Game.Id;

            if (gameId == GameId)
            {
                //string eventType = ncaafbGameEvent.Metadata.EventType;

                // switch (eventType) {}
                //string message = $"Handling Radar game event: GameId = {gameId}, EventType = {eventType}";
                //Logger.Info(message);

                ProcessRadarGameEvent1(ncaafbGameEvent);
                ModelUpdateRequired = true;
            }
        }
Esempio n. 3
0
        private void ProcessRadarGameEvent1(NcaafbGameEvent ncaafbGameEvent)
        {
            if (ncaafbGameEvent.Metadata == null)
            {
                Logger.Error("ProcessRadarGameEvent1(): game event metadata was null");
                return;
            }

            try
            {
                string eventType  = ncaafbGameEvent.Metadata.EventType;
                string possession = "N";

                // todo create an object from NFL event definition
                NcaafbGameState.Status = ncaafbGameEvent.Metadata.Status;
                Event     payloadEvent = ncaafbGameEvent.Payload.Event;
                Situation endSituation = payloadEvent.EndSituation;
                NcaafbGameState.YardsToGo  = endSituation.Yfd;
                NcaafbGameState.Down       = endSituation.Down;
                NcaafbGameState.Clock      = endSituation.Clock;
                NcaafbGameState.Seconds    = Utils.ConvertPeriodToGameString(payloadEvent.Period.Sequence, payloadEvent.EndSituation.Clock, 3600);
                NcaafbGameState.Possession = 0;

                if (ncaafbGameEvent.Payload.Event.EndSituation.Possession.Id == AwayTeam.TeamId)
                {
                    NcaafbGameState.Possession = 1;
                    possession = "V";
                }

                if (ncaafbGameEvent.Payload.Event.EndSituation.Possession.Id == HomeTeam.TeamId)
                {
                    NcaafbGameState.Possession = 2;
                    possession = "H";
                }

                NcaafbGameState.FieldPosition      = ToInt32(ncaafbGameEvent.Payload.Event.EndSituation.Location.Yardline);
                NcaafbGameState.Quarter            = ncaafbGameEvent.Payload.Game.Quarter;
                ModelData[NcaafbModelDataKeys.Egt] = new Dictionary <string, double>
                {
                    { "S", ToDouble(NcaafbGameState.Seconds) },
                    { "FP", ToDouble(NcaafbGameState.FieldPosition) },
                    { "DN", ToDouble(NcaafbGameState.Down) },
                    { "YF", ToDouble(NcaafbGameState.YardsToGo) },
                    { "P", ToDouble(NcaafbGameState.Possession) }
                };

                //ModelData[NcaafbModelDataKeys.Egt] = new Dictionary<string, double>();

                int awayScore = ncaafbGameEvent.Payload.Game.Summary.Away.Points;
                int homeScore = ncaafbGameEvent.Payload.Game.Summary.Home.Points;
                Dictionary <string, double> evsDictionary = ModelData[NcaafbModelDataKeys.Evs];

                // todo are the if checks necessary?
                if (!evsDictionary.ContainsKey("H,Q1"))
                {
                    evsDictionary["V,Q1"] = 0;
                    evsDictionary["H,Q1"] = 0;
                }

                if (!evsDictionary.ContainsKey("H,H1"))
                {
                    evsDictionary["V,H1"] = 0;
                    evsDictionary["H,H1"] = 0;
                }

                if (!evsDictionary.ContainsKey("H,Q2"))
                {
                    evsDictionary["V,Q2"] = 0;
                    evsDictionary["H,Q2"] = 0;
                }

                if (!evsDictionary.ContainsKey("H,H2"))
                {
                    evsDictionary["V,H2"] = 0;
                    evsDictionary["H,H2"] = 0;
                }

                if (!evsDictionary.ContainsKey("H,Q3"))
                {
                    evsDictionary["V,Q3"] = 0;
                    evsDictionary["H,Q3"] = 0;
                }

                if (!evsDictionary.ContainsKey("H,Q4"))
                {
                    evsDictionary["V,Q4"] = 0;
                    evsDictionary["H,Q4"] = 0;
                }

                evsDictionary["H,CG"] = homeScore;
                evsDictionary["V,CG"] = awayScore;

                switch (NcaafbGameState.Quarter)
                {
                case 1:
                    evsDictionary["V,Q1"] = awayScore;
                    evsDictionary["H,Q1"] = homeScore;
                    break;

                case 2:
                    evsDictionary["V,Q2"] = awayScore - evsDictionary["V,Q1"];
                    evsDictionary["H,Q2"] = homeScore - evsDictionary["H,Q1"];
                    break;

                case 3:
                    evsDictionary["V,Q3"] = awayScore - (evsDictionary["V,Q1"] + evsDictionary["V,Q2"]);
                    evsDictionary["H,Q3"] = homeScore - (evsDictionary["H,Q1"] + evsDictionary["H,Q2"]);
                    break;

                case 4:
                    evsDictionary["V,Q4"] =
                        awayScore - (evsDictionary["V,Q1"] + evsDictionary["V,Q2"] + evsDictionary["V,Q3"]);
                    evsDictionary["H,Q4"] =
                        homeScore - (evsDictionary["H,Q1"] + evsDictionary["H,Q2"] + evsDictionary["H,Q3"]);
                    break;
                }

                evsDictionary["H,H1"] = evsDictionary["H,Q1"] + evsDictionary["H,Q2"];
                evsDictionary["V,H1"] = evsDictionary["V,Q1"] + evsDictionary["V,Q2"];
                evsDictionary["H,H2"] = evsDictionary["H,Q3"] + evsDictionary["H,Q4"];
                evsDictionary["V,H2"] = evsDictionary["V,Q3"] + evsDictionary["V,Q4"];

                ModelUpdateRequired = true;
                string quarter = $"Q{NcaafbGameState.Quarter}";
                string clock   = NcaafbGameState.Clock;

                switch (NcaafbGameState.Status)
                {
                case "halftime":
                    quarter = "HT";
                    break;

                case "closed":
                    quarter = "FN";
                    break;
                }

                if (eventType == "period_end")
                {
                    int qplus = NcaafbGameState.Quarter + 1;
                    quarter = $"Q{qplus}";
                    clock   = "15:00";
                }

                string messageJson = $@"{{
                                        ""game"":               ""{GameId}"",
                                        ""Status"":             ""{NcaafbGameState.Status}"",
                                        ""away_score"":         {awayScore},
                                        ""home_score"":         {homeScore},
                                         ""away_q1"":           {evsDictionary["V,Q1"]},
                                        ""home_q1"":            {evsDictionary["H,Q1"]},
                                        ""away_q2"":            {evsDictionary["V,Q2"]},
                                        ""home_q2"":            {evsDictionary["H,Q2"]},
                                         ""away_q3"":           {evsDictionary["V,Q3"]},
                                        ""home_q3"":            {evsDictionary["H,Q3"]},
                                        ""away_q4"":            {evsDictionary["V,Q4"]},
                                        ""home_q4"":            {evsDictionary["H,Q4"]},
                                        ""period"":             ""{quarter}"",
                                        ""clock"":              ""{clock}"",
                                        ""possession"":         ""{possession}"",
                                        ""down"":               {NcaafbGameState.Down},
                                        ""Y2F"":                {NcaafbGameState.YardsToGo},
                                        ""FP"":                 {NcaafbGameState.FieldPosition}
                                    }}";

                if (!Utils.IsValidJson(messageJson))
                {
                    throw new Exception("JSON is invalid: {jsonString}");
                }

                string       messageKey = GameId + "score";
                const string eventName  = "NFLTEAM";
                Logger.Info(messageJson);
                _pusherUtil.SendScoreMessage(messageJson, eventName, messageKey);
            }
            catch (Exception exception)
            {
                Logger.Error(exception);
            }
            //NcaafbGameState.Quarter = ncaafbGameEvent.Metadata.Quarter;
            //NcaafbGameState.Possession = ncaafbGameEvent.Metadata.Possession;

            //Event payloadEvent = ncaafbGameEvent.Payload.Event;

            // check to make sure its moving forward
            //int sequence = payloadEvent.SequenceNumber;

            //if (sequence <= NcaafbGameState.Sequence)
            //{
            //    return;
            //}

            //NcaafbGameState.Sequence = sequence;
            //bool isHit = false;

            /* TO DO ADD PROCESSING LOGIC FOR NFL STREAMING EVENTS */
        }