< Summary

Information
Class: EHonda.KicktippAi.Core.MatchContextDocumentSelection
Assembly: EHonda.KicktippAi.Core
File(s): /home/runner/work/KicktippAi/KicktippAi/src/Core/MatchContextDocumentCatalog.cs
Line coverage
100%
Covered lines: 3
Uncovered lines: 0
Coverable lines: 3
Total lines: 81
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_RequiredDocumentNames()100%11100%
set_RequiredDocumentNames(...)100%210%
get_OptionalDocumentNames()100%11100%
set_OptionalDocumentNames(...)100%210%

File(s)

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

#LineLine coverage
 1using System.Text;
 2
 3namespace EHonda.KicktippAi.Core;
 4
 15public sealed record MatchContextDocumentSelection(
 16    IReadOnlyList<string> RequiredDocumentNames,
 17    IReadOnlyList<string> OptionalDocumentNames);
 8
 9public static class MatchContextDocumentCatalog
 10{
 11    private static readonly IReadOnlyDictionary<string, string> TeamAbbreviations =
 12        new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
 13        {
 14            { "1. FC Heidenheim 1846", "fch" },
 15            { "1. FC Köln", "fck" },
 16            { "1. FC Union Berlin", "fcu" },
 17            { "1899 Hoffenheim", "tsg" },
 18            { "Bayer 04 Leverkusen", "b04" },
 19            { "Bor. Mönchengladbach", "bmg" },
 20            { "Borussia Dortmund", "bvb" },
 21            { "Eintracht Frankfurt", "sge" },
 22            { "FC Augsburg", "fca" },
 23            { "FC Bayern München", "fcb" },
 24            { "FC St. Pauli", "fcs" },
 25            { "FSV Mainz 05", "m05" },
 26            { "Hamburger SV", "hsv" },
 27            { "RB Leipzig", "rbl" },
 28            { "SC Freiburg", "scf" },
 29            { "VfB Stuttgart", "vfb" },
 30            { "VfL Wolfsburg", "wob" },
 31            { "Werder Bremen", "svw" }
 32        };
 33
 34    public static MatchContextDocumentSelection ForMatch(string homeTeam, string awayTeam, string communityContext)
 35    {
 36        ArgumentException.ThrowIfNullOrWhiteSpace(homeTeam);
 37        ArgumentException.ThrowIfNullOrWhiteSpace(awayTeam);
 38        ArgumentException.ThrowIfNullOrWhiteSpace(communityContext);
 39
 40        var homeAbbreviation = GetTeamAbbreviation(homeTeam);
 41        var awayAbbreviation = GetTeamAbbreviation(awayTeam);
 42
 43        return new MatchContextDocumentSelection(
 44            [
 45                "bundesliga-standings.csv",
 46                $"community-rules-{communityContext}.md",
 47                $"recent-history-{homeAbbreviation}.csv",
 48                $"recent-history-{awayAbbreviation}.csv",
 49                $"home-history-{homeAbbreviation}.csv",
 50                $"away-history-{awayAbbreviation}.csv",
 51                $"head-to-head-{homeAbbreviation}-vs-{awayAbbreviation}.csv"
 52            ],
 53            [
 54                $"{homeAbbreviation}-transfers.csv",
 55                $"{awayAbbreviation}-transfers.csv"
 56            ]);
 57    }
 58
 59    public static string GetTeamAbbreviation(string teamName)
 60    {
 61        ArgumentException.ThrowIfNullOrWhiteSpace(teamName);
 62
 63        if (TeamAbbreviations.TryGetValue(teamName, out var abbreviation))
 64        {
 65            return abbreviation;
 66        }
 67
 68        var words = teamName.Split(' ', StringSplitOptions.RemoveEmptyEntries);
 69        var builder = new StringBuilder();
 70
 71        foreach (var word in words.Take(3))
 72        {
 73            if (word.Length > 0 && char.IsLetter(word[0]))
 74            {
 75                builder.Append(char.ToLowerInvariant(word[0]));
 76            }
 77        }
 78
 79        return builder.Length > 0 ? builder.ToString() : "unknown";
 80    }
 81}