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