Пример #1
0
        public Form1()
        {
            // Initialise the form and set up our stream from constructor
            InitializeComponent();

            var webRequest = WebRequest.Create(@"http://fantasyoverlord.com/FPL/Data");

            IWebProxy proxy = webRequest.Proxy;

            if (proxy != null)
            {
                string proxyuri = proxy.GetProxy(webRequest.RequestUri).ToString();
                webRequest.UseDefaultCredentials = true;
                webRequest.Proxy             = new WebProxy(proxyuri, false);
                webRequest.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
            }

            using (var response = webRequest.GetResponse())
            {
                var responseStream = response.GetResponseStream();
                var streamReader   = new StreamReader(responseStream);
                Footballer.LoadFromCSV(streamReader, listA);
            }

            var teams     = listA.Select(player => player.Team).Distinct();
            var positions = listA.Select(player => player.Position).Distinct();

            // Initialising the Team Combo Box
            TeamComboBox.Items.Clear();
            TeamComboBox.Items.Add("ALL");
            TeamComboBox.Items.AddRange(teams.ToArray());
            TeamComboBox.SelectedIndex = 0;

            // Initialising the Positions Combo Box
            PositionComboBox.Items.Clear();
            PositionComboBox.Items.Add("ALL");
            PositionComboBox.Items.AddRange(positions.ToArray());
            PositionComboBox.SelectedIndex = 0;

            label1.Text = "Footballer Info Loaded Successfully from website";
        }
        public static void LoadFromCSV(StreamReader reader, List <Footballer> listA)
        {
            //Cycle through my CSV file and load values into instances of Footballer Class
            // then save it in a List to be interrogated later

            // Read the header thenwe are ready for the actual data
            var line = reader.ReadLine();

            while (!reader.EndOfStream)
            {
                line = reader.ReadLine();
                var values = line.Split(',');

                Footballer data = new Footballer();

                data.FirstName        = values[0];
                data.Surname          = values[1];
                data.Position         = values[2];
                data.Team             = values[3];
                data.Cost             = values[4];
                data.PointsLstRnd     = values[5];
                data.TotalPoints      = values[6];
                data.AveragePoints    = values[7];
                data.AvgPointsDollar  = values[8];
                data.TotPointsDollar  = values[9];
                data.WeekWeighting    = values[10];
                data.TransfersOut     = values[11];
                data.YellowCards      = values[12];
                data.GoalsConceded    = values[13];
                data.GoalsConcededPts = values[14];
                data.Saves            = values[15];
                data.SavesPts         = values[16];
                data.GoalsScored      = values[17];
                data.GoalsScoredPts   = values[18];
                data.ValueSeason      = values[19];
                data.TransfersOutRnd  = values[20];
                data.PriceRise        = values[21];
                data.PriceFallRnd     = values[22];
                data.LstSeasonPts     = values[23];
                data.PriceFall        = values[24];
                data.ValueForm        = values[25];
                data.PenaltiesMissed  = values[26];
                data.Form             = values[27];
                data.Bonus            = values[28];
                data.FanRating        = values[29];
                data.CleanSheets      = values[30];
                data.CleansheetsPts   = values[31];
                data.Assists          = int.Parse(values[32]);
                data.SelectedByPcent  = values[33];
                data.TransfersIn      = values[34];
                data.OwnGoals         = values[35];
                data.EAIndex          = values[36];
                data.PenaltiesSaved   = values[37];
                data.DreamTeamCount   = values[38];
                data.MinutesPlayed    = values[39];
                data.TransfersInRound = values[40];
                data.PriceRiseRound   = values[41];
                data.RedCards         = values[42];
                data.BPS          = values[43];
                data.NextFixture1 = values[44];
                data.NextFixture2 = values[45];
                data.NextFixture3 = values[46];
                data.NextFixture4 = values[47];
                data.NextFixture5 = values[48];

                listA.Add(data);
            }
        }
        public static void LoadFromCSV(StreamReader reader, List<Footballer> listA)
        {
            //Cycle through my CSV file and load values into instances of Footballer Class
            // then save it in a List to be interrogated later

            // Read the header thenwe are ready for the actual data
            var line = reader.ReadLine();

            while (!reader.EndOfStream)
            {
                line = reader.ReadLine();
                var values = line.Split(',');

                Footballer data = new Footballer();

                data.FirstName = values[0];
                data.Surname = values[1];
                data.Position = values[2];
                data.Team = values[3];
                data.Cost = values[4];
                data.PointsLstRnd = values[5];
                data.TotalPoints = values[6];
                data.AveragePoints = values[7];
                data.AvgPointsDollar = values[8];
                data.TotPointsDollar = values[9];
                data.WeekWeighting = values[10];
                data.TransfersOut = values[11];
                data.YellowCards = values[12];
                data.GoalsConceded = values[13];
                data.GoalsConcededPts = values[14];
                data.Saves = values[15];
                data.SavesPts = values[16];
                data.GoalsScored = values[17];
                data.GoalsScoredPts = values[18];
                data.ValueSeason = values[19];
                data.TransfersOutRnd = values[20];
                data.PriceRise = values[21];
                data.PriceFallRnd = values[22];
                data.LstSeasonPts = values[23];
                data.PriceFall = values[24];
                data.ValueForm = values[25];
                data.PenaltiesMissed = values[26];
                data.Form = values[27];
                data.Bonus = values[28];
                data.FanRating = values[29];
                data.CleanSheets = values[30];
                data.CleansheetsPts = values[31];
                data.Assists = int.Parse(values[32]);
                data.SelectedByPcent = values[33];
                data.TransfersIn = values[34];
                data.OwnGoals = values[35];
                data.EAIndex = values[36];
                data.PenaltiesSaved = values[37];
                data.DreamTeamCount = values[38];
                data.MinutesPlayed = values[39];
                data.TransfersInRound = values[40];
                data.PriceRiseRound = values[41];
                data.RedCards = values[42];
                data.BPS = values[43];
                data.NextFixture1 = values[44];
                data.NextFixture2 = values[45];
                data.NextFixture3 = values[46];
                data.NextFixture4 = values[47];
                data.NextFixture5 = values[48];

                listA.Add(data);

            }
        }
        public FootballerStats(Footballer fb)
        {
            InitializeComponent();

            string photourl = "https://platform-static-files.s3.amazonaws.com/premierleague/photos/players/110x140/p" + fb.photo + ".png" ;

            try
            {
                pbPlayer.Load(photourl);
            }
            catch (Exception)
            {
            }

            var proxy = client.Proxy;
            client.UseDefaultCredentials = true;
            client.Proxy.Credentials = CredentialCache.DefaultCredentials;

            ServicePointManager.DefaultConnectionLimit = 300;

            // I need to Deserialise the JSON API object into RootObject, then I need to pick
            // out the Footballers and return them, also I can return the Events list

            Stream stream = client.OpenRead("https://fantasy.premierleague.com/drf/element-summary/"+fb.id);

            using (StreamReader reader = new StreamReader(stream))
            {
                root = (FootballerHistory)JsonConvert.DeserializeObject(reader.ReadLine(), typeof(FootballerHistory));
            }

            if (root !=null)
            {
                Label[] labels = { lblFixture0, lblFixture1, lblFixture2, lblFixture3, lblFixture4 };

                for (int i = 0; i < 5; i++)
                {
                    string fixture = root.fixtures[i].is_home ? " (H)" : " (A)";
                    labels[i].Text = root.fixtures[i].event_name + Environment.NewLine + Environment.NewLine + root.fixtures[i].opponent_name
                        + fixture + Environment.NewLine + Environment.NewLine + root.fixtures[i].kickoff_time_formatted ;

                    switch (root.fixtures[i].difficulty)
                    {
                        case 1:
                            labels[i].BackColor = Color.Green;
                            break;
                        case 2:
                            labels[i].BackColor = Color.DarkSeaGreen;
                            break;
                        case 3:
                            labels[i].BackColor = Color.LightGoldenrodYellow;
                            break;
                        case 4:
                            labels[i].BackColor = Color.Orange;
                            break;
                        case 5:
                            labels[i].BackColor = Color.Firebrick;
                            break;
                        default:
                            break;
                    }
                }

                // Working out our History drop down list and setting it
                var history = new HashSet<string>();

                foreach (var year in root.history_past)
                {
                    history.Add(year.season_name);
                }

                var histArr = history.ToArray();
                Array.Sort(histArr);
                Array.Reverse(histArr);

                cboHistory.Items.AddRange(histArr);
                if (cboHistory.Items.Count > 0) {
                    cboHistory.SelectedIndex = 0;
                }

                //Working out our current game week hist and setting it
                var gwHistory = new HashSet<string>();

                foreach (var week in root.history)
                {
                    gwHistory.Add(week.round.ToString());
                }

                var gwHistArr = gwHistory.ToArray();
                Array.Sort(gwHistArr);
                Array.Reverse(gwHistArr);

                cboGameHist.Items.AddRange(gwHistArr);
                if (cboGameHist.Items.Count > 0)
                {
                    cboGameHist.SelectedIndex = 0;
                }

            }

            lblFirstName.Text = fb.first_name;
            lblSurname.Text = fb.second_name;
            lblPosition.Text = fb.web_name;
            lblTeam.Text = fb.squad_number;
            lblCost.Text = fb.selected_by_percent;
        }
        private void dbgPlayers_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            Footballer fb = new Footballer();
            fb.photo = dbgPlayers.Rows[e.RowIndex].Cells[44].Value.ToString();
            fb.id = Convert.ToInt32(dbgPlayers.Rows[e.RowIndex].Cells[45].Value);
            fb.first_name = dbgPlayers.Rows[e.RowIndex].Cells[0].Value.ToString();
            fb.second_name = dbgPlayers.Rows[e.RowIndex].Cells[1].Value.ToString();
            fb.web_name = dbgPlayers.Rows[e.RowIndex].Cells[2].Value.ToString();
            fb.squad_number = dbgPlayers.Rows[e.RowIndex].Cells[3].Value.ToString();
            fb.selected_by_percent = dbgPlayers.Rows[e.RowIndex].Cells[4].Value.ToString();

            FootballerStats frm = new FootballerStats(fb);
            frm.Show();
        }