private static UpdateGameEventStateCommand ConstructUpdateGameEventStateCommand(MessageContext<OddsChange> messageContext, LineService lineService)
		{
			var message = messageContext.Message;
			var status = message.SportEventStatus;

			return new UpdateGameEventStateCommand
			(
				lineService: lineService,
				gameEventId: message.EventId.ToTransmitterEventId(),
				receivedOn: messageContext.ReceivedOn,
				incomingId: messageContext.IncomingId,
				description: GetDescription()
			);

			UpdateGameEventStateCommandDescription GetDescription()
			{
				var builder = new UpdateGameEventStateCommandDescription.Builder();

				// Status
				if (lineService != LineService.BetradarUnifiedFeedLCoO)
					builder.WithStatus(MatchStatusConverter.Convert(status.MatchStatus));

				// ScoresTotal
				if (status.HomeScore.HasValue || status.AwayScore.HasValue)
				{
					var home = status.HomeScore ?? 0;
					var away = status.AwayScore ?? 0;

					builder.WithScoresTotal
					(
						home.ToString(CultureInfo.InvariantCulture),
						away.ToString(CultureInfo.InvariantCulture)
					);
				}

				//scoresGame
				if (status.HomeGameScore.HasValue || status.AwayGameScore.HasValue)
				{
					var home = status.HomeGameScore ?? 0;
					var away = status.AwayGameScore ?? 0;

					builder.WithSubject(TransmitterCommandDescriptionKeys.ScoresGame, new GameEventStateScore
					(
						home.ToString(CultureInfo.InvariantCulture),
						away.ToString(CultureInfo.InvariantCulture)
					));
				}

				// ScoresByParts
				if (status.PeriodScores.Any())
				{
					var scoreLine = CalcScoreLine(status);
					builder.WithScoresByParts(scoreLine);
				}

				// MatchTime
				if (status.Clock?.MatchTime != null)
				{
					var matchTime = status.Clock.MatchTime.ParseMinutesFrom(Rounding.AwayFromZero);
					builder.WithSubject(TransmitterCommandDescriptionKeys.MatchTime, $"{matchTime}");
				}


				// RemainingTime
				if (status.Clock?.RemainingTime != null)
				{
					var remainingTime = status.Clock.RemainingTime.ParseMinutesFrom(Rounding.ToZero);
					builder.WithSubject(TransmitterCommandDescriptionKeys.Timer_Remaining, $"{remainingTime}");
				}


				// Cards.Red
				if (status.Statistics != null)
				{
					var home = message.SportEventStatus.Statistics.HomeRedCards + message.SportEventStatus.Statistics.HomeYellowRedCards;
					var away = message.SportEventStatus.Statistics.AwayRedCards + message.SportEventStatus.Statistics.AwayYellowRedCards;

					if ((home | away) > 0)
						builder.WithCards(GameEventStateCardType.Red, new GameEventStateScore(home, away));
				}

				// Server
				if (status.CurrentServer.HasValue)
					builder.WithSubject(TransmitterCommandDescriptionKeys.Server, status.CurrentServer.Value);

				return builder.ToImmutable();
			}
		}
Beispiel #2
0
        public IEnumerable <ITransmitterCommand> Adapt(
            MessageContext <MatchSummary> messageContext,
            Language language,
            LineService lineService
            )
        {
            var message = messageContext.Message;

            var status = message.SportEventStatus;

            if (status != null)
            {
                yield return(new UpdateGameEventStateCommand
                             (
                                 lineService: lineService,
                                 gameEventId: message.SportEvent.Id.ToTransmitterEventId(),
                                 receivedOn: messageContext.ReceivedOn,
                                 incomingId: messageContext.IncomingId,
                                 description: GetDescription()
                             ));

                UpdateGameEventStateCommandDescription GetDescription()
                {
                    var builder = new UpdateGameEventStateCommandDescription.Builder();

                    // Status
                    if (status.MatchStatusCode.HasValue && lineService != LineService.BetradarUnifiedFeedLCoO)
                    {
                        builder.WithStatus(MatchStatusConverter.Convert(status.MatchStatusCode.Value));
                    }

                    if (status.HomeScore.HasValue || status.AwayScore.HasValue)
                    {
                        var home = status.HomeScore ?? 0;
                        var away = status.AwayScore ?? 0;

                        builder.WithScoresTotal
                        (
                            home.ToString(CultureInfo.InvariantCulture),
                            away.ToString(CultureInfo.InvariantCulture)
                        );
                    }

                    if (status.PeriodScores.Any())
                    {
                        var scoreLine = CalcScoreLine(status);
                        builder.WithScoresByParts(scoreLine);
                    }

                    if (status.Clock != null)
                    {
                        int ParseTime(string s)
                        {
                            var fractions  = s.Split(':');
                            var seconds    = 0;
                            var multiplier = 1;

                            for (var i = fractions.Length - 1; i >= 0; i--)
                            {
                                seconds = int.Parse(fractions[i]) * multiplier;

                                multiplier = multiplier * 60;
                            }

                            return(seconds);
                        }

                        if (!string.IsNullOrEmpty(status.Clock.MatchTime))
                        {
                            builder.WithElapsedTime(
                                ParseTime(status.Clock.MatchTime));
                        }
                    }

                    return(builder.ToImmutable());
                }
            }
        }
Beispiel #3
0
        public IEnumerable <ITransmitterCommand> Adapt(MessageContext <EventData, TranslationSubscription> context)
        {
            var list             = new List <ITransmitterCommand>();
            var translationState = context.State.PersistableState;
            var msg = context.Message;

            list.Add(
                new UpdateGameEventStateCommand(
                    lineService: LineService.SportLevel,
                    gameEventId: msg.TranslationId,
                    receivedOn: context.ReceivedOn,
                    incomingId: context.IncomingId,
                    description: GetDescription()
                    )
                );

            context.State.SaveState();
            return(list);

            UpdateGameEventStateCommandDescription GetDescription()
            {
                var builder = new UpdateGameEventStateCommandDescription.Builder();

                // Status
                var status = MatchStatusConverter.Convert(msg.EventCode);

                if (status != null)
                {
                    builder.WithStatus(status);
                }

                else if (msg.GamePeriod.HasValue && msg.GamePeriod.Value > 0)                 //msg.EventCode == EventCode.START_PERIOD)
                {
                    builder.WithStatus(new SportLevelGameEventStatus(msg.GamePeriod.Value + "set"));
                }

                // Time
                if (msg.Playtime > 0)
                {
                    builder.WithSubject("matchtime", Convert.ToInt32(TimeSpan.FromMilliseconds(msg.Playtime).TotalMinutes) + 1);
                }

                // Score
                if (msg.ScoreHome.HasValue || msg.ScoreAway.HasValue)
                {
                    var home = msg.ScoreHome ?? 0;
                    var away = msg.ScoreAway ?? 0;

                    builder.WithScoresTotal
                    (
                        home.ToString(CultureInfo.InvariantCulture),
                        away.ToString(CultureInfo.InvariantCulture)
                    );
                }

                // Score part
                if (msg.Extra != null && msg.GamePeriod.HasValue && msg.GamePeriod.Value > 0)
                {
                    if (msg.Extra.Points1.HasValue || msg.Extra.Points2.HasValue)
                    {
                        // fix previos states
                        for (var i = 1; i < msg.GamePeriod; i++)
                        {
                            translationState.MatchScore.GetOrAdd(i, y => new Score());
                        }

                        // save current score to state
                        translationState.MatchScore.AddOrUpdate(
                            msg.GamePeriod.Value,
                            id => new Score()
                        {
                            Home = msg.Extra.Points1 ?? 0, Away = msg.Extra.Points2 ?? 0
                        },
                            (id, score) =>
                        {
                            score.Home = msg.Extra.Points1 ?? 0;
                            score.Away = msg.Extra.Points2 ?? 0;
                            return(score);
                        }
                            );

                        var scoreLine = new GameEventStateScoreLine(
                            translationState.MatchScore
                            .OrderBy(entry => entry.Key)
                            .Select(
                                entry =>
                                new GameEventStateScore(entry.Value.Home, entry.Value.Away)
                                )
                            );
                        builder.WithScoresByParts(scoreLine);
                    }
                }

                switch (msg.EventCode)
                {
                case EventCode.POSESSION_1:
                    builder.WithSubject(GameEventStateDescriptionSubject.Server, "1");
                    break;

                case EventCode.POSESSION_2:
                    builder.WithSubject(GameEventStateDescriptionSubject.Server, "2");
                    break;
                }
                return(builder.ToImmutable());
            }
        }