/// <summary> /// Get the finished matches of a competition. /// </summary> /// <param name="service">Football service.</param> static public void Matches(FootballService service) { // Get the Ligue 1 by its code var ligue1 = service.GetCompetition("FL1"); // Get every finished matches of the Ligue 1 var matchRequest = service.GetMatches(ligue1, Status.FINISHED); // Check if there is a message, which means something went wrong if (matchRequest.IsValid) { // Display ever matches foreach (var match in matchRequest.Matches) { Console.WriteLine($"{match.HomeTeam} vs {match.AwayTeam} ({match.Score.FullTime}) | {match.UTCDate}"); } } else { Console.WriteLine($"Failed to send match request : {matchRequest.Message}"); } // Separatation DisplayLine(); }
static void Main(string[] args) { string pathToData; if (!args.Any()) { Console.WriteLine("No arguents passed assuming football.dat file is in same directory as execcutable."); pathToData = "./football.dat"; } else { pathToData = args[0]; } if (!File.Exists(pathToData)) { Console.WriteLine($"Could not find data: {pathToData}"); return; } var footballData = new FootballFileReader(pathToData).GetAll(); var teamWithSmallestScoreDifference = new FootballService(footballData).GetTeamWithSmallestScoringDifference(); Console.WriteLine($"The team with the samllest score difference is: {teamWithSmallestScoreDifference.TeamName}"); Console.ReadKey(); }
/// <summary> /// Display response headers. /// </summary> /// <param name="service">Football service.</param> static public void DisplayHeaders(FootballService service) { Console.WriteLine($"Requests available : {service.RequestsAvailable}"); Console.WriteLine($"Seconds until request counter reset : {service.CounterReset}"); Console.WriteLine($"Account authenticated : {service.Auth}"); Console.WriteLine($"API version : {service.Version}"); }
/// <summary> /// Get the standings of a competition. /// </summary> /// <param name="service">Football service.</param> static public void Standings(FootballService service) { // Get the Premiere League by uts code var premiereLeague = service.GetCompetition("PL"); // Get the standing for the Premiere League var standingRequest = service.GetStandings(premiereLeague); // Check if there is a message, which means something went wrong if (standingRequest.IsValid) { // Display the table of the Premiere League foreach (var table in standingRequest.Standings[0].Table) // First standing is the classic standing, there is 3 standings : Full, Home and Away. { Console.WriteLine($"{table.Position}. {table.Team} | Points: {table.Points} ({table.GoalDifference})"); } } else { Console.WriteLine($"Failed to send standing request : {standingRequest.Message}"); } // Separatation DisplayLine(); }
public FootballServiceTests() { var csvPath = "https://raw.githubusercontent.com/jalapic/engsoccerdata/master/data-raw/england.csv"; var appConfig = new Mock <IApplicationConfiguration>(); appConfig.Setup(x => x.FootballCsvPath).Returns(csvPath); _footballService = new FootballService(appConfig.Object); }
public bool ExtractInfoFromFile(string filePath = "") { if (string.IsNullOrEmpty(filePath)) { filePath = _defaultFilePath; } try { // Get registered service FootballService footballService = new FootballService(ServiceProvider.GetService <IFileParser>()); // Try to read & parse file bool ret = footballService.LoadFile(filePath); // Validate file, and produce output if (ret && footballService.IsFilePathValid) { if (footballService.IsFileColValid) { Console.WriteLine("The file columns are valid."); Console.WriteLine("The team with the smallest difference in ‘for’ and ‘against’ goals is: " + footballService.GetTeamWithMinGap()); return(true); } else { Console.WriteLine("The file columns are not valid."); return(false); } } else { Console.WriteLine("Cannot open file."); return(false); } } catch (Exception e) { Console.WriteLine(e.Message); return(false); } }
/// <summary> /// Main method. /// </summary> /// <param name="args">Arguments.</param> static void Main(string[] args) { // Create the service first, using your token FootballService service = new FootballService("your-api-token-here"); // To get a token, register here : https://www.football-data.org/client/register // Subscribe to the Log event - Note that you need to subscribe only if you more informations about the requests service.Log += ServiceLog; // Display examples Competitions(service); Matches(service); Standings(service); // Display the response headers after several requests DisplayHeaders(service); // Don't let the program close Console.ReadKey(); }
/// <summary> /// Get the competitions. /// </summary> /// <param name="service">Football service.</param> static public void Competitions(FootballService service) { // Get every competitions available with the tier one (free plan) var competitionsRequest = service.GetCompetitions(Plan.TIER_ONE); // Check if there is a message, which means something went wrong if (competitionsRequest.IsValid) { // Display ever competitions foreach (var competition in competitionsRequest.Competitions) { Console.WriteLine($"{competition.Code} | {competition.Name} | ({competition.Area.Name})"); } } else { Console.WriteLine($"Failed to send competition request : {competitionsRequest.Message}"); } // Separatation DisplayLine(); }
public void ThenGetTeamWithSmallestScoringDifferenceReturnsTheTeamWithTheSmallestScoringDifference() { var footballService = new FootballService(new List <FootballStat> { new FootballStat { TeamName = "Team 1", GoalsFor = 50, GoalsAgainst = 40 }, new FootballStat { TeamName = "Team 2", GoalsFor = 50, GoalsAgainst = 45 }, new FootballStat { TeamName = "Team 3", GoalsFor = 40, GoalsAgainst = 44 }, new FootballStat { TeamName = "Team 4", GoalsFor = 45, GoalsAgainst = 30 } }); var footballStat = footballService.GetTeamWithSmallestScoringDifference(); const string expectedTeam = "Team 3"; Assert.IsNotNull(footballStat); Assert.AreEqual(expectedTeam, footballStat.TeamName); }