Example #1
0
    static void GetAsyncCallback(object sender, DownloadStringCompletedEventArgs args)
    {
        LeagueTable league = JsonConvert.DeserializeObject <LeagueTable>(args.Result);

        Console.WriteLine(league.leagueCaption);
        Console.WriteLine(league.standing[0].teamName);
    }
        public void PopulateLeagueTable()
        {
            PopulatePlayerPicks();

            using (var db = new leaguepredictorEntities())
            {
                CurrentLeaguePositions = db.team_rankings.Select(tr => new LeaguePosition {
                    Team = tr.team.team_name, Position = tr.position
                })
                                         .ToList();

                //calculate each player scores
                PlayerPicks.ForEach(pp =>
                {
                    var ltm = GenerateLeagueTableModel(pp);
                    ltm.ID  = pp.ID;
                    LeagueTable.Add(ltm);
                });

                LeagueTable = LeagueTable.OrderBy(ltm => ltm.Points).ToList();
                foreach (var ltm in LeagueTable)
                {
                    ltm.Position = LeagueTable.IndexOf(ltm) + 1;
                }
            }
        }
Example #3
0
        public LeagueTable GetLeagueTable(Guid season)
        {
            LeagueTable leagueTable = new LeagueTable();

            using (SqlConnection connection = new SqlConnection(connStr))
            {
                if (season == Season.PremierLeague_2014_2015)
                {
                    connection.Open();
                    string        query              = "SELECT * FROM dbo.LeagueTable1415";
                    SqlCommand    queryCommand       = new SqlCommand(query, connection);
                    SqlDataReader queryCommandReader = queryCommand.ExecuteReader();
                    DataTable     dataTable          = new DataTable();
                    dataTable.Load(queryCommandReader);
                    List <LeagueTable.LeagueTableRow> rows = new List <LeagueTable.LeagueTableRow>();
                    foreach (DataRow row in dataTable.Rows)
                    {
                        rows.Add(new LeagueTable.LeagueTableRow(row));
                    }

                    leagueTable = new LeagueTable(rows);
                    connection.Close();
                }
            }
            return(leagueTable);
        }
Example #4
0
        private static int CheckMatchResults(LeagueTable leagueTable, LeagueTablePosition pos1, LeagueTablePosition pos2, IMatchRepository matchRepository)
        {
            int result = 0;

            var team1   = pos1.TeamId;
            var team2   = pos2.TeamId;
            var matches = matchRepository.GetMatchesBetweenTeams(leagueTable.SeasonCompetition, team1, team2).ToList();

            if (matches.Any())
            {
                int team1GoalDiff = 0;
                int team2GoalDiff = 0;
                foreach (var match in matches)
                {
                    if (match.HomeTeamId == team1)
                    {
                        team1GoalDiff += match.HomeScore - match.AwayScore;
                        team2GoalDiff += match.AwayScore - match.HomeScore;
                    }
                    else
                    {
                        team1GoalDiff += match.AwayScore - match.HomeScore;
                        team2GoalDiff += match.HomeScore - match.AwayScore;
                    }
                }

                result = team2GoalDiff.CompareTo(team1GoalDiff);
            }

            return(result);
        }
Example #5
0
        public IActionResult LeagueTable()
        {
            LeagueTable nbaLeague = new LeagueTable();

            nbaLeague.createTableInstance();

            return(View(nbaLeague));
        }
        public IActionResult LeagueTable()
        {
            LeagueTable premierLeague = new LeagueTable();

            premierLeague.createTableInstance();

            return(View(premierLeague));
        }
Example #7
0
        /// <summary>
        /// C'tor that gets the id (int) and make a League instance of the
        /// asked country
        /// </summary>
        /// <param name="league"></param>
        public League(int league)
        {
            String  stringJson = DataExtractor.GetInstance().GetJsonStringFromUrl(DataType.LEAGUE, league);
            JObject json       = JObject.Parse(stringJson);

            Parse(json);
            leagueTable = new LeagueTable(json);
        }
        public void ReturnNull_WhenPassedIdIsInvalid()
        {
            var repositoryMock = new Mock <IWhoScoredRepository <LeagueTable> >();
            ILeagueTableService leagueTableService = new LeagueTableService(repositoryMock.Object);

            int         invalidLeagueTableId = 33;
            LeagueTable resultLeagueTable    = leagueTableService.GetLeagueTableById(invalidLeagueTableId);

            Assert.IsNull(resultLeagueTable);
        }
Example #9
0
        /// <summary>
        /// Call api resource: /competitions/{competitionid}/leagueTable/?matchday={matchday}
        /// </summary>
        /// <param name="competitionid">int</param>
        /// <param name="matchday">int</param>
        /// <returns>LeagueTable</returns>
        public async Task <LeagueTable> GetLeagueTableAsync(int competitionid, int matchday)
        {
            var result = new LeagueTable();
            var j      = await SendRequest("/competitions/" + competitionid + "/leagueTable?matchday=" + matchday);

            if (!string.IsNullOrEmpty(j))
            {
                result = JsonConvert.DeserializeObject <LeagueTable>(j);
            }
            return(result);
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            LeagueTable = await SearchLeagueTable(CompetitionNumber);

            return(Page());
        }
        /// <summary>
        /// Call api resource: /competitions/{competitionid}/leagueTable
        /// </summary>
        /// <param name="competitionid">int</param>
        /// <returns>LeagueTable</returns>
        public LeagueTable GetLeagueTable(int competitionid)
        {
            var result = new LeagueTable();
            var j      = SendRequest("/competitions/" + competitionid + "/leagueTable");

            if (!string.IsNullOrEmpty(j))
            {
                result = JsonConvert.DeserializeObject <LeagueTable>(j);
            }
            return(result);
        }
Example #12
0
        private void UpdateLeagueTablePositions(string seasonId, LeagueTable leagueTable)
        {
            var teams = leagueTable.LeagueTablePositions.Select(x => x.Team);

            foreach (var team in teams)
            {
                var teamStatistics = _seasonTeamStatistics[team.Id];
                teamStatistics.CurrentLeagueTablePosition = team.CurrentLeaguePosition;
                teamStatistics.LeagueTablePositions      += team.CurrentLeaguePosition + ",";
            }
        }
Example #13
0
        private static void UpdatePositionNumbers(LeagueTable leagueTable)
        {
            int position = 1;

            foreach (var leagueTablePosition in leagueTable.LeagueTablePositions)
            {
                leagueTablePosition.Position = position;
                leagueTablePosition.Team.CurrentLeaguePosition = position;
                position++;
            }
        }
Example #14
0
    static void GetSync(int leagueId)
    {
        Console.WriteLine("...... Requesting " + leagueId);
        string      path    = string.Format(FOOTBALL_URI, leagueId);
        WebClient   client  = new WebClient();
        string      content = client.DownloadString(path);
        LeagueTable league  = JsonConvert.DeserializeObject <LeagueTable>(content);

        Console.WriteLine(league.leagueCaption);
        Console.WriteLine(league.standing[0].teamName);
    }
Example #15
0
    static void Main()
    {
        WebClient   client = new WebClient();
        string      body   = client.DownloadString("http://api.football-data.org/v1/soccerseasons/445/leagueTable");
        LeagueTable table  = (LeagueTable)JsonConvert.DeserializeObject(body, typeof(LeagueTable));

        Console.WriteLine(table._links.self.href);
        foreach (Standing l in table.standing)
        {
            Console.WriteLine(l.teamName);
        }
    }
Example #16
0
        public IActionResult LeaguePDF()
        {
            LeagueTable nbaLeague = new LeagueTable();

            nbaLeague.createTableInstance();


            return(new ViewAsPdf("LeagueTable", nbaLeague)
            {
                CustomSwitches = "--footer-center [page]"
            });
        }
Example #17
0
        static void Main(string[] args)
        {
            //First of all we need to create our web Service
            ISoccerDataService sds = SoccerDataFactory.GetSoccerDataService(WebServiceName.FootBallDataService);
            //now lets choose a league...
            //lets say spanish league!
            League league = sds.GetLeague(LeagueNameId.SPAIN);
            //now lets see the league table
            LeagueTable lt = league.LeagueTable;

            Console.WriteLine(lt.ToString());
        }
        public async Task <IActionResult> GetLeagueTable()
        {
            var option = new FootballDataOption
            {
                ApiKey          = string.Empty,
                ResponseControl = ResponseControl.Full
            };
            IFootballDataClient client      = new FootballDataClient(option);
            LeagueTable         leagueTable = await client.GetLeagueTable(445, null);

            return(Json(leagueTable));
        }
Example #19
0
        public void UpdateLeagueTable_SortsAlpabetically()
        {
            // We need 4 teams.
            var team1 = new Team {
                Id = "1", Name = "Team1"
            };
            var team2 = new Team {
                Id = "2", Name = "Team2"
            };
            var team3 = new Team {
                Id = "3", Name = "Team3"
            };
            var team4 = new Team {
                Id = "4", Name = "Team4"
            };

            // Every team has a league table position.
            var positions = new List <LeagueTablePosition>
            {
                new LeagueTablePosition {
                    Team = team4, Position = 4
                },
                new LeagueTablePosition {
                    Team = team1, Position = 1
                },
                new LeagueTablePosition {
                    Team = team2, Position = 2
                },
                new LeagueTablePosition {
                    Team = team3, Position = 3
                },
            };

            var leagueTable = new LeagueTable {
                LeagueTablePositions = positions
            };

            _repositoryFactory.Setup(x => x.CreateMatchRepository()).Returns(_matchRepository.Object);
            var leagueTableManager = new LeagueTableManager(_repositoryFactory.Object);

            leagueTableManager.UpdateLeagueTable(leagueTable, new List <Match>());

            // Because all positions have the exact same number of matches, points and goals, the positions should be sorted alphabetically.
            Assert.AreEqual("1", leagueTable.LeagueTablePositions[0].TeamId);
            Assert.AreEqual(1, leagueTable.LeagueTablePositions[0].Position);
            Assert.AreEqual("2", leagueTable.LeagueTablePositions[1].TeamId);
            Assert.AreEqual(2, leagueTable.LeagueTablePositions[1].Position);
            Assert.AreEqual("3", leagueTable.LeagueTablePositions[2].TeamId);
            Assert.AreEqual(3, leagueTable.LeagueTablePositions[2].Position);
            Assert.AreEqual("4", leagueTable.LeagueTablePositions[3].TeamId);
            Assert.AreEqual(4, leagueTable.LeagueTablePositions[3].Position);
        }
        public void ReturnCorrectLeagueTable_WhenPassedIdIsValid()
        {
            var repositoryMock = new Mock <IWhoScoredRepository <LeagueTable> >();

            LeagueTable leagueTable = new LeagueTable();

            repositoryMock.Setup(x => x.GetById(It.IsAny <int>())).Returns(leagueTable);

            ILeagueTableService leagueTableService = new LeagueTableService(repositoryMock.Object);
            LeagueTable         actualLeagueTable  = leagueTableService.GetLeagueTableById(It.IsAny <int>());

            Assert.AreSame(leagueTable, actualLeagueTable);
        }
        public void ReturnTeamsInOrderOfGoalDifference()
        {
            //arrange
            List <MatchResult> matchResults = MatchResultsFixtures.GetChampionByGoalDifference();
            var mockResultsRepository       = new Mock <IMatchResultsRepository>();

            mockResultsRepository.Setup(r => r.GetAll()).Returns(matchResults);
            //act
            var leagueTable = new LeagueTable(mockResultsRepository.Object);

            //assert
            Assert.AreEqual("Liverpool", leagueTable.GetWinningTeamName());
        }
        public void ReturnTeamsInOrderOfGoalsScored()
        {
            //arrange
            var matchResults          = MatchResultsFixtures.GetChampionByGoalsScored();
            var mockResultsRepository = new Mock <IMatchResultsRepository>();

            mockResultsRepository.Setup(r => r.GetAll()).Returns(matchResults);
            //act
            var champion = new LeagueTable(mockResultsRepository.Object).GetWinningTeamName();

            //assert
            Assert.AreEqual("Stoke", champion);
        }
        public IActionResult LeaguePDF()
        {
            LeagueTable premierLeague = new LeagueTable();

            premierLeague.createTableInstance();

            ViewData["Name"] = "Daniel Davies";

            return(new ViewAsPdf("LeagueTable", premierLeague)
            {
                CustomSwitches = "--footer-center [page]"
            });
        }
Example #24
0
        private void ProcessarCompetitions(List <Competition> competitions)
        {
            AzureStorageUtil azureStorageUtil = new AzureStorageUtil();

            // Elimina Tudo;
            azureStorageUtil.ClearAzureStructure();

            List <string>  ignoredCompetitions   = GetIgnoredCompetitions();
            List <dynamic> competitionsProcessed = new List <dynamic>();

            foreach (Competition competition in competitions)
            {
                dynamic competitionProcessed = new ExpandoObject();
                competitionProcessed.Name = competition.caption;
                competitionProcessed.Id   = competition.id;
                competitionsProcessed.Add(competitionProcessed);


                if (ignoredCompetitions.Count(s => s.Equals(competition.league)) == 0)
                {
                    LeagueTable leagueTable = GetLeagueTable(competition.id);
                    Fixtures    fixtures    = GetFixtures(competition.id);

                    // Somente campeonatos pontos corridos
                    if ((leagueTable != null) && (leagueTable.standing != null) && (fixtures != null))
                    {
                        string jsonLeagueTable = JsonConvert.SerializeObject(leagueTable);
                        string jsonFixtures    = JsonConvert.SerializeObject(fixtures);

                        Model.Azure.Competition competitionAzure = GetCompetitionAzure(competition);

                        azureStorageUtil.AddCompetition(competitionAzure);
                        azureStorageUtil.AddLeagueTableData(competitionAzure, jsonLeagueTable);
                        azureStorageUtil.AddFixturesData(competitionAzure, jsonFixtures);

                        competitionProcessed.Status = "OK";
                    }
                    else
                    {
                        competitionProcessed.Status = "Does not have LeagueTable.";
                    }
                }
                else
                {
                    competitionProcessed.Status = "Ignorada";
                }
            }

            dataGridView1.DataSource = competitionsProcessed.ToDataTable();
            dataGridView1.Refresh();
        }
        public void ReturnTeamsWithPositions()
        {
            //arrange
            var matchResults          = MatchResultsFixtures.GetChampionByGoalsScored();
            var mockResultsRepository = new Mock <IMatchResultsRepository>();

            mockResultsRepository.Setup(r => r.GetAll()).Returns(matchResults);
            //act
            var standings = new LeagueTable(mockResultsRepository.Object).GetStandings();
            //assert
            var arsenalRank = standings.First(s => s.Team.Equals("Arsenal")).LeaguePosition;

            Assert.AreEqual(3, arsenalRank);
        }
Example #26
0
    static void GetAsync(int leagueId)
    {
        Console.WriteLine("...... Requesting " + leagueId);
        string    path   = string.Format(FOOTBALL_URI, leagueId);
        WebClient client = new WebClient();

        client.DownloadStringCompleted += (sender, args) => {
            LeagueTable league = JsonConvert.DeserializeObject <LeagueTable>(args.Result);
            Console.WriteLine("> {0} --- leader: {1}",
                              league.leagueCaption,
                              league.standing[0].teamName);
        };
        client.DownloadStringAsync(new Uri(path));
    }
Example #27
0
        private LeagueTable GetLeagueTable(int competitionId)
        {
            try
            {
                string jsonData = GetJsonData($"http://www.football-data.org/v1/competitions/{competitionId}/leagueTable").Result;

                jsonData = jsonData.RemoveAccents();
                LeagueTable leagueTable = JsonConvert.DeserializeObject <LeagueTable>(jsonData);
                return(leagueTable);
            }
            catch
            {
                return(null);
            }
        }
Example #28
0
    static void GetAsyncBadPromise(int leagueId)
    {
        Console.WriteLine("...... Requesting " + leagueId);
        string        path   = string.Format(FOOTBALL_URI, leagueId);
        HttpClient    client = new HttpClient();
        Task <string> res    = client.GetStringAsync(new Uri(path));

        // !!!!! NAO fazer isto => bloqueante
        string      content = res.Result; //!!!!! Bloqueante
        LeagueTable league  = JsonConvert.DeserializeObject <LeagueTable>(content);

        Console.WriteLine("> {0} --- leader: {1}",
                          league.leagueCaption,
                          league.standing[0].teamName);
    }
        public void ReturnTeamsAsEqualPositionsWhenSamePoints()
        {
            //arrange
            var matchResults          = MatchResultsFixtures.GetTeamsWithEqualStats();
            var mockResultsRepository = new Mock <IMatchResultsRepository>();

            mockResultsRepository.Setup(r => r.GetAll()).Returns(matchResults);
            //act
            var standings = new LeagueTable(mockResultsRepository.Object).GetStandings();

            //assert
            Assert.AreEqual(1, standings.First(s => s.Team.Equals("Stoke")).LeaguePosition);
            Assert.AreEqual(2, standings.First(s => s.Team.Equals("Liverpool")).LeaguePosition);
            Assert.AreEqual(2, standings.First(s => s.Team.Equals("Man Utd")).LeaguePosition);
            Assert.AreEqual(4, standings.First(s => s.Team.Equals("Arsenal")).LeaguePosition);
        }
Example #30
0
    static void GetAsyncPromise(int leagueId)
    {
        Console.WriteLine("...... Requesting " + leagueId);
        string     path   = string.Format(FOOTBALL_URI, leagueId);
        HttpClient client = new HttpClient();

        client
        .GetStringAsync(new Uri(path))
        .ContinueWith(res => {
            string content     = res.Result;
            LeagueTable league = JsonConvert.DeserializeObject <LeagueTable>(content);
            Console.WriteLine("> {0} --- leader: {1}",
                              league.leagueCaption,
                              league.standing[0].teamName);
        });
    }
Example #31
0
 public League()
 {
     Teams = new List<LeagueTeam>().ToArray();
     Gameweeks = new List<Gameweek>().ToArray();
     Table = new LeagueTable(this);
 }