< Summary

Information
Class: Orchestrator.Commands.Operations.Wm26RecentHistory.Wm26RecentHistoryProbePredictionLookupCommand
Assembly: Orchestrator
File(s): /home/runner/work/KicktippAi/KicktippAi/src/Orchestrator/Commands/Operations/Wm26RecentHistory/Wm26RecentHistoryProbePredictionLookupCommand.cs
Line coverage
86%
Covered lines: 39
Uncovered lines: 6
Coverable lines: 45
Total lines: 91
Line coverage: 86.6%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
.ctor(...)100%11100%
ExecuteAsync()75%4480.65%
FormatPlayedAt(...)100%11100%

File(s)

/home/runner/work/KicktippAi/KicktippAi/src/Orchestrator/Commands/Operations/Wm26RecentHistory/Wm26RecentHistoryProbePredictionLookupCommand.cs

#LineLine coverage
 1using System.Globalization;
 2using Microsoft.Extensions.Logging;
 3using NodaTime;
 4using Orchestrator.Infrastructure;
 5using Orchestrator.Infrastructure.Factories;
 6using Spectre.Console;
 7using Spectre.Console.Cli;
 8
 9namespace Orchestrator.Commands.Operations.Wm26RecentHistory;
 10
 11public sealed class Wm26RecentHistoryProbePredictionLookupCommand
 12    : AsyncCommand<Wm26RecentHistoryProbePredictionLookupSettings>
 13{
 114    private static readonly DateTimeZone BerlinTimeZone = DateTimeZoneProviders.Tzdb["Europe/Berlin"];
 15
 16    private readonly IAnsiConsole _console;
 17    private readonly IFirebaseServiceFactory _firebaseServiceFactory;
 18    private readonly ILogger<Wm26RecentHistoryProbePredictionLookupCommand> _logger;
 19
 120    public Wm26RecentHistoryProbePredictionLookupCommand(
 121        IAnsiConsole console,
 122        IFirebaseServiceFactory firebaseServiceFactory,
 123        ILogger<Wm26RecentHistoryProbePredictionLookupCommand> logger)
 24    {
 125        _console = console;
 126        _firebaseServiceFactory = firebaseServiceFactory;
 127        _logger = logger;
 128    }
 29
 30    protected override async Task<int> ExecuteAsync(
 31        CommandContext context,
 32        Wm26RecentHistoryProbePredictionLookupSettings settings,
 33        CancellationToken cancellationToken)
 34    {
 35        try
 36        {
 137            var competition = CompetitionResolver.ResolveCompetition(
 138                settings.Competition,
 139                communityContext: settings.CommunityContext);
 140            var repositoryCompetition = CompetitionResolver.ToRepositoryCompetitionArgument(competition);
 141            var predictionRepository = _firebaseServiceFactory.CreatePredictionRepository(repositoryCompetition);
 42
 143            _console.MarkupLine("[green]Probing latest predicted match lookup[/]");
 144            _console.MarkupLine($"[blue]Using community context:[/] [yellow]{Markup.Escape(settings.CommunityContext)}[/
 145            _console.MarkupLine($"[blue]Using competition:[/] [yellow]{Markup.Escape(competition)}[/]");
 146            _console.MarkupLine(
 147                $"[blue]Query:[/] [yellow]{Markup.Escape(settings.HomeTeam.Trim())}[/] vs [yellow]{Markup.Escape(setting
 48
 149            if (settings.Verbose)
 50            {
 151                _console.MarkupLine(
 152                    "[dim]Firestore query filters match-predictions by competition, communityContext, homeTeam, awayTeam
 53            }
 54
 155            var match = await predictionRepository.GetLatestPredictedMatchByTeamsAsync(
 156                settings.HomeTeam,
 157                settings.AwayTeam,
 158                settings.CommunityContext,
 159                cancellationToken);
 60
 161            if (match is null)
 62            {
 063                _console.MarkupLine("[yellow]No matching prediction found[/]");
 064                return 1;
 65            }
 66
 167            _console.MarkupLine(
 168                "[green]Found latest predicted match:[/] " +
 169                $"{Markup.Escape(match.HomeTeam)} vs {Markup.Escape(match.AwayTeam)}, " +
 170                $"matchday {match.Matchday}, starts at {FormatPlayedAt(match.StartsAt)}");
 71
 172            return 0;
 73        }
 074        catch (Exception ex)
 75        {
 076            _logger.LogError(ex, "Failed to probe WM26 prediction lookup");
 077            _console.MarkupLine($"[red]Error:[/] {Markup.Escape(ex.Message)}");
 078            return 1;
 79        }
 180    }
 81
 82    private static string FormatPlayedAt(ZonedDateTime startsAt)
 83    {
 184        var local = startsAt.WithZone(BerlinTimeZone);
 185        var dateTimeOffset = new DateTimeOffset(
 186            local.LocalDateTime.ToDateTimeUnspecified(),
 187            local.Offset.ToTimeSpan());
 88
 189        return dateTimeOffset.ToString("yyyy-MM-dd'T'HH:mm:sszzz", CultureInfo.InvariantCulture);
 90    }
 91}