< Summary

Information
Class: Orchestrator.Services.MatchOutcomeCollectionResult
Assembly: Orchestrator
File(s): /home/runner/work/KicktippAi/KicktippAi/src/Orchestrator/Services/MatchOutcomeCollectionService.cs
Line coverage
100%
Covered lines: 4
Uncovered lines: 0
Coverable lines: 4
Total lines: 101
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
.ctor(...)100%210%
get_CurrentMatchday()100%11100%
set_CurrentMatchday(...)100%210%
get_IncompleteMatchdays()100%11100%
set_IncompleteMatchdays(...)100%210%
get_MatchdaySummaries()100%11100%
set_MatchdaySummaries(...)100%210%

File(s)

/home/runner/work/KicktippAi/KicktippAi/src/Orchestrator/Services/MatchOutcomeCollectionService.cs

#LineLine coverage
 1using EHonda.KicktippAi.Core;
 2using Microsoft.Extensions.Logging;
 3using Orchestrator.Infrastructure.Factories;
 4
 5namespace Orchestrator.Services;
 6
 7public record MatchdayOutcomeCollectionSummary(
 8    int Matchday,
 9    int FetchedMatches,
 10    int CompletedMatches,
 11    int PendingMatches,
 12    int CreatedCount,
 13    int UpdatedCount,
 14    int UnchangedCount);
 15
 116public record MatchOutcomeCollectionResult(
 117    int CurrentMatchday,
 118    IReadOnlyList<int> IncompleteMatchdays,
 119    IReadOnlyList<MatchdayOutcomeCollectionSummary> MatchdaySummaries);
 20
 21public class MatchOutcomeCollectionService
 22{
 23    private readonly IFirebaseServiceFactory _firebaseServiceFactory;
 24    private readonly IKicktippClientFactory _kicktippClientFactory;
 25    private readonly ILogger<MatchOutcomeCollectionService> _logger;
 26
 27    public MatchOutcomeCollectionService(
 28        IFirebaseServiceFactory firebaseServiceFactory,
 29        IKicktippClientFactory kicktippClientFactory,
 30        ILogger<MatchOutcomeCollectionService> logger)
 31    {
 32        _firebaseServiceFactory = firebaseServiceFactory;
 33        _kicktippClientFactory = kicktippClientFactory;
 34        _logger = logger;
 35    }
 36
 37    public async Task<MatchOutcomeCollectionResult> CollectAsync(
 38        string communityContext,
 39        bool dryRun,
 40        CancellationToken cancellationToken = default)
 41    {
 42        var kicktippClient = _kicktippClientFactory.CreateClient();
 43        var matchOutcomeRepository = _firebaseServiceFactory.CreateMatchOutcomeRepository();
 44
 45        var currentMatchday = await kicktippClient.GetCurrentTippuebersichtMatchdayAsync(communityContext);
 46        var incompleteMatchdays = await matchOutcomeRepository.GetIncompleteMatchdaysAsync(
 47            communityContext,
 48            currentMatchday,
 49            cancellationToken);
 50
 51        var summaries = new List<MatchdayOutcomeCollectionSummary>();
 52
 53        foreach (var matchday in incompleteMatchdays)
 54        {
 55            var outcomes = await kicktippClient.GetMatchdayOutcomesAsync(communityContext, matchday);
 56            var createdCount = 0;
 57            var updatedCount = 0;
 58            var unchangedCount = 0;
 59
 60            if (!dryRun)
 61            {
 62                foreach (var outcome in outcomes)
 63                {
 64                    var result = await matchOutcomeRepository.UpsertMatchOutcomeAsync(outcome, communityContext, cancell
 65                    switch (result.Disposition)
 66                    {
 67                        case MatchOutcomeWriteDisposition.Created:
 68                            createdCount++;
 69                            break;
 70                        case MatchOutcomeWriteDisposition.Updated:
 71                            updatedCount++;
 72                            break;
 73                        default:
 74                            unchangedCount++;
 75                            break;
 76                    }
 77                }
 78            }
 79
 80            summaries.Add(new MatchdayOutcomeCollectionSummary(
 81                matchday,
 82                outcomes.Count,
 83                outcomes.Count(outcome => outcome.HasOutcome),
 84                outcomes.Count(outcome => !outcome.HasOutcome),
 85                createdCount,
 86                updatedCount,
 87                unchangedCount));
 88        }
 89
 90        _logger.LogInformation(
 91            "Outcome collection evaluated current matchday {CurrentMatchday} and selected {IncompleteMatchdayCount} inco
 92            currentMatchday,
 93            incompleteMatchdays.Count,
 94            communityContext);
 95
 96        return new MatchOutcomeCollectionResult(
 97            currentMatchday,
 98            incompleteMatchdays,
 99            summaries.AsReadOnly());
 100    }
 101}