< Summary

Information
Class: EHonda.KicktippAi.Core.MatchContextDocumentCatalog
Assembly: EHonda.KicktippAi.Core
File(s): /home/runner/work/KicktippAi/KicktippAi/src/Core/MatchContextDocumentCatalog.cs
Line coverage
98%
Covered lines: 49
Uncovered lines: 1
Coverable lines: 50
Total lines: 81
Line coverage: 98%
Branch coverage
80%
Covered branches: 8
Total branches: 10
Branch coverage: 80%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
ForMatch(...)100%11100%
GetTeamAbbreviation(...)80%101088.89%

File(s)

/home/runner/work/KicktippAi/KicktippAi/src/Core/MatchContextDocumentCatalog.cs

#LineLine coverage
 1using System.Text;
 2
 3namespace EHonda.KicktippAi.Core;
 4
 5public sealed record MatchContextDocumentSelection(
 6    IReadOnlyList<string> RequiredDocumentNames,
 7    IReadOnlyList<string> OptionalDocumentNames);
 8
 9public static class MatchContextDocumentCatalog
 10{
 111    private static readonly IReadOnlyDictionary<string, string> TeamAbbreviations =
 112        new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
 113        {
 114            { "1. FC Heidenheim 1846", "fch" },
 115            { "1. FC Köln", "fck" },
 116            { "1. FC Union Berlin", "fcu" },
 117            { "1899 Hoffenheim", "tsg" },
 118            { "Bayer 04 Leverkusen", "b04" },
 119            { "Bor. Mönchengladbach", "bmg" },
 120            { "Borussia Dortmund", "bvb" },
 121            { "Eintracht Frankfurt", "sge" },
 122            { "FC Augsburg", "fca" },
 123            { "FC Bayern München", "fcb" },
 124            { "FC St. Pauli", "fcs" },
 125            { "FSV Mainz 05", "m05" },
 126            { "Hamburger SV", "hsv" },
 127            { "RB Leipzig", "rbl" },
 128            { "SC Freiburg", "scf" },
 129            { "VfB Stuttgart", "vfb" },
 130            { "VfL Wolfsburg", "wob" },
 131            { "Werder Bremen", "svw" }
 132        };
 33
 34    public static MatchContextDocumentSelection ForMatch(string homeTeam, string awayTeam, string communityContext)
 35    {
 136        ArgumentException.ThrowIfNullOrWhiteSpace(homeTeam);
 137        ArgumentException.ThrowIfNullOrWhiteSpace(awayTeam);
 138        ArgumentException.ThrowIfNullOrWhiteSpace(communityContext);
 39
 140        var homeAbbreviation = GetTeamAbbreviation(homeTeam);
 141        var awayAbbreviation = GetTeamAbbreviation(awayTeam);
 42
 143        return new MatchContextDocumentSelection(
 144            [
 145                "bundesliga-standings.csv",
 146                $"community-rules-{communityContext}.md",
 147                $"recent-history-{homeAbbreviation}.csv",
 148                $"recent-history-{awayAbbreviation}.csv",
 149                $"home-history-{homeAbbreviation}.csv",
 150                $"away-history-{awayAbbreviation}.csv",
 151                $"head-to-head-{homeAbbreviation}-vs-{awayAbbreviation}.csv"
 152            ],
 153            [
 154                $"{homeAbbreviation}-transfers.csv",
 155                $"{awayAbbreviation}-transfers.csv"
 156            ]);
 57    }
 58
 59    public static string GetTeamAbbreviation(string teamName)
 60    {
 161        ArgumentException.ThrowIfNullOrWhiteSpace(teamName);
 62
 163        if (TeamAbbreviations.TryGetValue(teamName, out var abbreviation))
 64        {
 065            return abbreviation;
 66        }
 67
 168        var words = teamName.Split(' ', StringSplitOptions.RemoveEmptyEntries);
 169        var builder = new StringBuilder();
 70
 171        foreach (var word in words.Take(3))
 72        {
 173            if (word.Length > 0 && char.IsLetter(word[0]))
 74            {
 175                builder.Append(char.ToLowerInvariant(word[0]));
 76            }
 77        }
 78
 179        return builder.Length > 0 ? builder.ToString() : "unknown";
 80    }
 81}