예제 #1
0
        public static List <PlayerStatT> RetrievePlayerStat(string name)
        {
            List <PlayerStatT> playerFound = new List <PlayerStatT>();

            using (SqlConnection con = new SqlConnection("Data Source=" + ConfigFile.DB_NAME + ";Initial Catalog=LEAD_DATA;User Id=general;Password=33333333")) //Integrated Security=SSPI"))
            {
                try
                {
                    int type = 0;
                    using (SqlCommand command = new SqlCommand("SELECT * FROM LEAD_DATA.dbo.SEASONED WHERE pname LIKE @varName ORDER BY season, type", con))
                    {
                        command.Parameters.AddWithValue("@pType", type);
                        command.Parameters.Add(new SqlParameter("@varName", SqlDbType.Text)
                        {
                            Value = name
                        });
                        con.Open();
                        using (SqlDataReader oReader = command.ExecuteReader())
                        {
                            while (oReader.Read())
                            {
                                PlayerStatT newData    = new PlayerStatT();
                                double      tempDouble = 0.0;
                                long        tempLong   = 0;
                                newData.Name              = oReader["pname"].ToString();
                                newData.Season            = (int)oReader["season"];
                                newData.Category          = (int)oReader["type"];
                                newData.Rank              = (int)oReader["rank"];
                                newData.AvarageMatchScore = (int)oReader["avms"];
                                newData.Deaths            = (int)oReader["d"];
                                newData.Kills             = (int)oReader["k"];
                                newData.Wins              = (int)oReader["w"];
                                newData.Losses            = (int)oReader["l"];
                                newData.GamesPlayed       = long.TryParse(oReader["played"].ToString(), out tempLong) ? tempLong : 0;
                                newData.WLr = double.TryParse(oReader["wlr"].ToString(), out tempDouble) ? tempDouble : 0.0;
                                newData.KDr = double.TryParse(oReader["kdr"].ToString(), out tempDouble) ? tempDouble : 0.0;
                                newData.KpM = double.TryParse(oReader["kpm"].ToString(), out tempDouble) ? tempDouble : 0.0;
                                newData.DpM = double.TryParse(oReader["dpm"].ToString(), out tempDouble) ? tempDouble : 0.0;
                                playerFound.Add(newData);
                            }
                            con.Close();
                        }
                    }
                }
                catch (Exception exp)
                {
                    Console.WriteLine("Could not insert.");
                }
            }
            return(playerFound);
        }
예제 #2
0
        /// <summary>
        /// ** DEPRECATED **
        /// Writes a single line of data on a file
        /// (determined in the ConfigFile)
        /// </summary>
        /// <param name="player"></param>
        /// <returns></returns>
        public static bool WriteLine(PlayerStatT player)
        {
            string valore = player.Rank + ConfigFile.SEPARATOR +
                            player.Name + ConfigFile.SEPARATOR +
                            player.Wins + ConfigFile.SEPARATOR +
                            player.Losses + ConfigFile.SEPARATOR +
                            player.WLr + ConfigFile.SEPARATOR +
                            player.Kills + ConfigFile.SEPARATOR +
                            player.Deaths + ConfigFile.SEPARATOR +
                            player.KDr + ConfigFile.SEPARATOR +
                            player.GamesPlayed + ConfigFile.SEPARATOR +
                            player.AvarageMatchScore + ConfigFile.SEPARATOR;

            Logger.PrintF(ConfigFile.FILE_OUTPUT, valore, false);
            return(true);
        }
예제 #3
0
        public static bool InsertPlayerDataInDB(PlayerStatT actualPlayer)
        {
            //SQL SIDE
            //using (SqlConnection con = new SqlConnection("Data Source=" + ConfigFile.DB_NAME +
            //                                             ";Initial Catalog=" + ConfigFile.TABLE_NAME +
            //                                             ";" + ConfigFile.DB_CREDENTIALS))
            using (SqlConnection con = new SqlConnection("Data Source=WEPLUS19\\SQLEXPRESS;Initial Catalog=LEAD_DATA;Integrated Security=SSPI"))

            {
                con.Open();
                try
                {
                    using (SqlCommand command = new SqlCommand(
                               "INSERT INTO SEASONED VALUES(@season, @type, @name, @rank, @w, @l, @wlr, @k, @d, @kdr, @played, @avms)", con))
                    {
                        command.Parameters.Add(new SqlParameter("season", (int)actualPlayer.Season));
                        command.Parameters.Add(new SqlParameter("type", (int)actualPlayer.Category));
                        command.Parameters.Add(new SqlParameter("name", actualPlayer.Name));
                        command.Parameters.Add(new SqlParameter("rank", (long)actualPlayer.Rank));
                        command.Parameters.Add(new SqlParameter("w", (int)actualPlayer.Wins));
                        command.Parameters.Add(new SqlParameter("l", (int)actualPlayer.Losses));
                        command.Parameters.Add(new SqlParameter("wlr", (double)actualPlayer.WLr));
                        command.Parameters.Add(new SqlParameter("k", (int)actualPlayer.Kills));
                        command.Parameters.Add(new SqlParameter("d", (int)actualPlayer.Deaths));
                        command.Parameters.Add(new SqlParameter("kdr", (double)actualPlayer.KDr));
                        command.Parameters.Add(new SqlParameter("played", (int)actualPlayer.GamesPlayed));
                        command.Parameters.Add(new SqlParameter("avms", (int)actualPlayer.AvarageMatchScore));
                        command.ExecuteNonQuery();
                    }
                }
                catch (Exception exp)
                {
                    Console.WriteLine("Could not insert.");
                }
            }
            //##############
            return(true);
        }
        public void Elaborate(List <PlayerStatT> playerGlobal, string playerName, FileInfo textFile = null, bool toPDF = false)
        {
            try
            {
                plName    = playerName;
                txtFile   = textFile.FullName;
                this.Text = "BBARST - Live Charts - " + playerName;

                //K/D ratio & W/L ratio SECTION
                double[]      KDr;
                double[]      WLr;
                List <double> listKDr = new List <double>();
                List <double> listWLr = new List <double>();
                for (int season = 1; season <= ConfigFile.SEASON_LAST; season++)
                {
                    List <PlayerStatT> listAllPlayer = new List <PlayerStatT>();
                    PlayerStatT        actualPlayer  = new PlayerStatT();
                    listAllPlayer = playerGlobal.Where(x => x.Season == season && x.Category == 0).ToList();
                    actualPlayer  = listAllPlayer.Count > 0 ? listAllPlayer.First() : null;
                    if (actualPlayer != null)
                    {
                        if (actualPlayer.Name != null)
                        {
                            if (actualPlayer.Name.ToUpper() == playerName.ToUpper())
                            {
                                plName = actualPlayer.Name;
                                if (actualPlayer.KDr != null)
                                {
                                    listKDr.Add((double)actualPlayer.KDr);
                                }
                                else
                                {
                                    listKDr.Add(0);
                                }
                                if (actualPlayer.WLr != null)
                                {
                                    listWLr.Add((double)actualPlayer.WLr);
                                }
                                else
                                {
                                    listWLr.Add(0);
                                }
                            }
                            else
                            {
                                listKDr.Add(0);
                                listWLr.Add(0);
                            }
                        }
                        else
                        {
                            listKDr.Add((double)0.0);
                            listWLr.Add((double)0.0);
                        }
                    }
                    else
                    {
                        listKDr.Add(0);
                        listWLr.Add(0);
                    }
                }
                KDr = listKDr.ToArray();
                WLr = listWLr.ToArray();
                GraphOps.DrawChartKDWLr(crtKDWKr, KDr, WLr,
                                        (double)playerGlobal.Where(x => x.Season == 0 && x.Category == 0).First().KDr,
                                        (double)playerGlobal.Where(x => x.Season == 0 && x.Category == 0).First().WLr);

                // Kills per Match & Deaths per Match SECTION
                double[]      KpM;
                double[]      DpM;
                List <int>    listPlayedG = new List <int>();
                List <double> listKpM     = new List <double>();
                List <double> listDpM     = new List <double>();
                for (int season = 1; season <= ConfigFile.SEASON_LAST; season++)
                {
                    int kills  = 0;
                    int deaths = 0;
                    int played = 0;
                    List <PlayerStatT> listAllPlayer = new List <PlayerStatT>();
                    PlayerStatT        actualPlayer  = new PlayerStatT();
                    listAllPlayer = playerGlobal.Where(x => x.Season == season && x.Category == 0).ToList();
                    actualPlayer  = listAllPlayer.Count > 0 ? listAllPlayer.First() : null;
                    if (actualPlayer != null)
                    {
                        if (actualPlayer.Name != null)
                        {
                            if (actualPlayer.Name.ToUpper() == playerName.ToUpper())
                            {
                                if (actualPlayer.Kills != null)
                                {
                                    kills = (int)actualPlayer.Kills;
                                }
                                else
                                {
                                    kills = 0;
                                }
                                if (actualPlayer.Deaths != null)
                                {
                                    deaths = (int)actualPlayer.Deaths;
                                }
                                else
                                {
                                    deaths = 0;
                                }
                                if (actualPlayer.GamesPlayed != 0)
                                {
                                    played = (int)actualPlayer.GamesPlayed;
                                }
                                else
                                {
                                    played = 0;
                                }
                                listKpM.Add((double)((double)kills / (double)played));
                                listDpM.Add((double)((double)deaths / (double)played));
                                listPlayedG.Add(played);
                            }
                            else
                            {
                                listKpM.Add((double)0.0);
                                listDpM.Add((double)0.0);
                                listPlayedG.Add(0);
                            }
                        }
                        else
                        {
                            listKpM.Add((double)0.0);
                            listDpM.Add((double)0.0);
                            listPlayedG.Add(0);
                        }
                    }
                    else
                    {
                        listKpM.Add((double)0.0);
                        listDpM.Add((double)0.0);
                        listPlayedG.Add(0);
                    }
                }
                KpM = listKpM.ToArray();
                DpM = listDpM.ToArray();
                PlayerStatT tempPlayer = playerGlobal.Where(x => x.Season == 0 && x.Category == 0).First();
                GraphOps.DrawChartKDpM(crtKDpM, KpM, DpM,
                                       Math.Round((double)tempPlayer.Kills / (double)tempPlayer.GamesPlayed, 2),
                                       Math.Round((double)tempPlayer.Deaths / (double)tempPlayer.GamesPlayed, 2));

                // Avarage MS SECTION
                int[]      AvMS;
                List <int> listAvMS = new List <int>();
                for (int season = 1; season <= ConfigFile.SEASON_LAST; season++)
                {
                    List <PlayerStatT> listAllPlayer = new List <PlayerStatT>();
                    PlayerStatT        actualPlayer  = new PlayerStatT();
                    listAllPlayer = playerGlobal.Where(x => x.Season == season && x.Category == 0).ToList();
                    actualPlayer  = listAllPlayer.Count > 0 ? listAllPlayer.First() : null;
                    if (actualPlayer != null)
                    {
                        if (actualPlayer.Name != null)
                        {
                            if (actualPlayer.Name.ToUpper() == playerName.ToUpper())
                            {
                                if (actualPlayer.Kills != null)
                                {
                                    listAvMS.Add((int)actualPlayer.AvarageMatchScore);
                                }
                                else
                                {
                                    listAvMS.Add(0);
                                }
                            }
                            else
                            {
                                listAvMS.Add(0);
                            }
                        }
                        else
                        {
                            listAvMS.Add(0);
                        }
                    }
                    else
                    {
                        listAvMS.Add(0);
                    }
                }
                AvMS = listAvMS.ToArray();
                GraphOps.DrawChartAvMS(crtAvMS, AvMS, listPlayedG.ToArray(),
                                       (double)playerGlobal.Where(x => x.Season == 0 && x.Category == 0).First().AvarageMatchScore,
                                       Math.Round((double)playerGlobal.Where(x => x.Season == 0 && x.Category == 0).First().GamesPlayed / (double)ConfigFile.SEASON_LAST, 2));
                this.Text = "BBARST - Live Charts - " + plName;
                fileText  = textFile;



                List <double> lightKDr   = new List <double>();
                List <double> lightWLr   = new List <double>();
                List <double> lightKpM   = new List <double>();
                List <double> lightDpM   = new List <double>();
                List <double> mediumKDr  = new List <double>();
                List <double> mediumWLr  = new List <double>();
                List <double> mediumKpM  = new List <double>();
                List <double> mediumDpM  = new List <double>();
                List <double> heavyKDr   = new List <double>();
                List <double> heavyWLr   = new List <double>();
                List <double> heavyKpM   = new List <double>();
                List <double> heavyDpM   = new List <double>();
                List <double> assaultKDr = new List <double>();
                List <double> assaultWLr = new List <double>();
                List <double> assaultKpM = new List <double>();
                List <double> assaultDpM = new List <double>();

                try
                {
                    playerGlobal.OrderBy(x => x.Season).ToList().ForEach(z =>
                    {
                        if (z.Category == 1)
                        {
                            lightKDr.Add(z.KDr == null ? 0 : (double)z.KDr);
                            lightWLr.Add(z.WLr == null ? 0 : (double)z.WLr);
                            lightKpM.Add(z.KpM == null ? 0 : (double)z.KpM);
                            lightDpM.Add(z.DpM == null ? 0 : (double)z.DpM);
                        }
                        if (z.Category == 2)
                        {
                            mediumKDr.Add(z.KDr == null ? 0 : (double)z.KDr);
                            mediumWLr.Add(z.WLr == null ? 0 : (double)z.WLr);
                            mediumKpM.Add(z.KpM == null ? 0 : (double)z.KpM);
                            mediumDpM.Add(z.DpM == null ? 0 : (double)z.DpM);
                        }
                        if (z.Category == 3)
                        {
                            heavyKDr.Add(z.KDr == null ? 0 : (double)z.KDr);
                            heavyWLr.Add(z.WLr == null ? 0 : (double)z.WLr);
                            heavyKpM.Add(z.KpM == null ? 0 : (double)z.KpM);
                            heavyDpM.Add(z.DpM == null ? 0 : (double)z.DpM);
                        }
                        if (z.Category == 4)
                        {
                            assaultKDr.Add(z.KDr == null ? 0 : (double)z.KDr);
                            assaultWLr.Add(z.WLr == null ? 0 : (double)z.WLr);
                            assaultKpM.Add(z.KpM == null ? 0 : (double)z.KpM);
                            assaultDpM.Add(z.DpM == null ? 0 : (double)z.DpM);
                        }
                    });
                }
                catch (Exception exp)
                {
                    Logger.PrintC(exp.Message);
                }

                //playerGlobal.Where(x => x.Season == 0 && x.Category == 1).FirstOrDefault().DpM;
                GraphOps.DrawChartByClass(crtByClass, lightKDr.ToArray(), lightWLr.ToArray(), lightKpM.ToArray(), lightDpM.ToArray(), "Light",
                                          (double)playerGlobal.Where(x => x.Season == 0 && x.Category == 1).FirstOrDefault().KDr,
                                          (double)playerGlobal.Where(x => x.Season == 0 && x.Category == 1).FirstOrDefault().WLr,
                                          (double)playerGlobal.Where(x => x.Season == 0 && x.Category == 1).FirstOrDefault().KpM,
                                          (double)playerGlobal.Where(x => x.Season == 0 && x.Category == 1).FirstOrDefault().DpM);
                GraphOps.DrawChartByClass(crtByClass, mediumKDr.ToArray(), mediumWLr.ToArray(), mediumKpM.ToArray(), mediumDpM.ToArray(), "Medium",
                                          (double)playerGlobal.Where(x => x.Season == 0 && x.Category == 2).FirstOrDefault().KDr,
                                          (double)playerGlobal.Where(x => x.Season == 0 && x.Category == 2).FirstOrDefault().WLr,
                                          (double)playerGlobal.Where(x => x.Season == 0 && x.Category == 2).FirstOrDefault().KpM,
                                          (double)playerGlobal.Where(x => x.Season == 0 && x.Category == 2).FirstOrDefault().DpM);
                GraphOps.DrawChartByClass(crtByClass, heavyKDr.ToArray(), heavyWLr.ToArray(), heavyKpM.ToArray(), heavyDpM.ToArray(), "Heavy",
                                          (double)playerGlobal.Where(x => x.Season == 0 && x.Category == 3).FirstOrDefault().KDr,
                                          (double)playerGlobal.Where(x => x.Season == 0 && x.Category == 3).FirstOrDefault().WLr,
                                          (double)playerGlobal.Where(x => x.Season == 0 && x.Category == 3).FirstOrDefault().KpM,
                                          (double)playerGlobal.Where(x => x.Season == 0 && x.Category == 3).FirstOrDefault().DpM);
                GraphOps.DrawChartByClass(crtByClass, assaultKDr.ToArray(), assaultWLr.ToArray(), assaultKpM.ToArray(), assaultDpM.ToArray(), "Assault",
                                          (double)playerGlobal.Where(x => x.Season == 0 && x.Category == 4).FirstOrDefault().KDr,
                                          (double)playerGlobal.Where(x => x.Season == 0 && x.Category == 4).FirstOrDefault().WLr,
                                          (double)playerGlobal.Where(x => x.Season == 0 && x.Category == 4).FirstOrDefault().KpM,
                                          (double)playerGlobal.Where(x => x.Season == 0 && x.Category == 4).FirstOrDefault().DpM);



                if (toPDF)
                {
                    PdfOps.CreatePDFFileFromTxtFile(textFile.FullName, playerName);
                }
                else
                {
                    DataOps.PrintData(rtbData, textFile.FullName);
                }

                /*
                 * if (new FileInfo(Path.Combine(ConfigFile.DIRECTORY_OUTPUT.FullName, "chart.png")).Exists)
                 *  File.Delete(Path.Combine(ConfigFile.DIRECTORY_OUTPUT.FullName, "chart.png"));
                 * if (new FileInfo(Path.Combine(ConfigFile.DIRECTORY_OUTPUT.FullName, "chart2.png")).Exists)
                 *  File.Delete(Path.Combine(ConfigFile.DIRECTORY_OUTPUT.FullName, "chart2.png"));
                 * if (new FileInfo(Path.Combine(ConfigFile.DIRECTORY_OUTPUT.FullName, "chart3.png")).Exists)
                 *  File.Delete(Path.Combine(ConfigFile.DIRECTORY_OUTPUT.FullName, "chart3.png"));
                 * if (new FileInfo(Path.Combine(ConfigFile.DIRECTORY_OUTPUT.FullName, "Light.png")).Exists)
                 *  File.Delete(Path.Combine(ConfigFile.DIRECTORY_OUTPUT.FullName, "Light.png"));
                 * if (new FileInfo(Path.Combine(ConfigFile.DIRECTORY_OUTPUT.FullName, "Medium.png")).Exists)
                 *  File.Delete(Path.Combine(ConfigFile.DIRECTORY_OUTPUT.FullName, "Medium.png"));
                 * if (new FileInfo(Path.Combine(ConfigFile.DIRECTORY_OUTPUT.FullName, "Heavy.png")).Exists)
                 *  File.Delete(Path.Combine(ConfigFile.DIRECTORY_OUTPUT.FullName, "Heavy.png"));
                 * if (new FileInfo(Path.Combine(ConfigFile.DIRECTORY_OUTPUT.FullName, "Assault.png")).Exists)
                 *  File.Delete(Path.Combine(ConfigFile.DIRECTORY_OUTPUT.FullName, "Assault.png"));
                 */

                //Bitmap textImage = GraphOps.CreateBitmapImage(textFile.FullName, toPDF);
                //if (toPDF)
                //    txtImage = textImage;
                //else
                //    pcbStats.Image = textImage;
            }
            catch (Exception exp)
            {
            }
        }
예제 #5
0
        public static async Task <PlayerStatT> SearchPlayer(string playerName, List <int> seasons, List <int> category, string email, string password)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
                                                   | SecurityProtocolType.Tls11
                                                   | SecurityProtocolType.Tls12
                                                   | SecurityProtocolType.Ssl3;
            ConfigFile.IncrementTaskStarted();
            string   fileNameA = playerName + ".txt";
            FileInfo fileName  = new FileInfo(Path.Combine(ConfigFile.DIRECTORY_OUTPUT.FullName, fileNameA));

            List <PlayerStatT> ThisPlayer = new List <PlayerStatT>();

            foreach (int thisSeason in seasons)
            {
                int    season          = thisSeason - 1;
                string BaseAddress     = "https://mwomercs.com/do/login";
                var    cookieContainer = new CookieContainer();
                Uri    uri             = new Uri("https://mwomercs.com/profile/leaderboards");
                var    handler         = new HttpClientHandler();
                handler.CookieContainer = cookieContainer;
                handler.CookieContainer.Add(uri, new System.Net.Cookie("leaderboard_season", season.ToString()));
                using (var client = new HttpClient(handler)
                {
                    BaseAddress = new Uri(BaseAddress)
                })
                {
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/xml"));
                    HttpResponseMessage risposta = await client.PostAsync(BaseAddress, new FormUrlEncodedContent(
                                                                              new[]
                    {
                        new KeyValuePair <string, string> ("email", email),
                        new KeyValuePair <string, string> ("password", password)
                    })
                                                                          );

                    string responseBodyAsText = await risposta.Content.ReadAsStringAsync();

                    string resp     = null;
                    int    lastPage = 0;
                    foreach (int thisCategory in category)
                    {
                        string address = "https://mwomercs.com/profile/leaderboards?type=" + thisCategory.ToString() + "&user="******"<tr class="))
                        {
                            statString = DataOps.SearchPlayerData(resp);
                        }
                        else
                        if (resp.ToUpper().Contains(playerName.ToUpper()))
                        {
                            statString = DataOps.SearchPlayerData(resp, playerName);
                        }
                        PlayerStatT actualPlayerStat = DataOps.ParsePlayerStat(statString);
                        actualPlayerStat.Season     = thisSeason;
                        actualPlayerStat.Category   = thisCategory;
                        actualPlayerStat.WebPage    = -666;
                        actualPlayerStat.WebAddress = address;

                        ConfigFile._Global.WaitOne();
                        ConfigFile.GLOBAL_PLAYER.Add(actualPlayerStat);
                        ConfigFile._Global.Release();
                    }
                }
            }
            ConfigFile.IncrementTaskFinished();
            return(new PlayerStatT());
        }