Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                DeserializeMatch lobbyData = JsonConvert.DeserializeObject <DeserializeMatch>(MatchDataJsonString());



                PointsResult     pointsResult = new PointsResult();
                RemyngtonGeneral match        = new RemyngtonGeneral();

                if (Tournament.CustomTeams)
                {
                    string jsonString = GetJsonStringFromFile(Tournament.TeamlistLink);
                    match.teamList = JsonConvert.DeserializeObject <DeserializeTeams>(jsonString);
                }

                Console.WriteLine(match.teamList);

                int teamType = Convert.ToInt32(lobbyData.games[0].team_type);
                if (teamType == 0) // Head to head = 0, Tag Co-op = 1, Team vs = 2, Tag Team vs = 3
                {
                    teamVS = false;
                }
                else
                {
                    teamVS = true;
                }

                match.ReadTotalPlayers(MatchDataJsonString());
                match.CalculateAccuracies(lobbyData);
                match.CalculateMaxcombo(lobbyData);
                match.CalculateMisscount(lobbyData);
                match.CalculateScore(lobbyData);
                Console.WriteLine(PlayerTracker);
                DisplaySimplyfiedPoints(match.GetSimplifiedPoints(RemyngtonGeneral.pointHistory));

                Console.WriteLine(PlayerTracker);
                if (lobbyData.match.end_time != null) //if the match has ended
                {
                    ArchiveMatch(RemyngtonGeneral.pointHistory, lobbyData.match.match_id, lobbyData.match.name);
                }

                PlayerTracker = new Dictionary <string, double>(); //clears values from playertracker
            }
            catch (JsonSerializationException)
            {
                Response.Redirect("Default.aspx");
            }
        }
Ejemplo n.º 2
0
        public Dictionary <string, double> ReadCurrentMapPlayers(string jsonString, int mapnumber)
        {
            Dictionary <string, double> currentMapPlayers = new Dictionary <string, double>();
            DeserializeMatch            lobbyData         = JsonConvert.DeserializeObject <DeserializeMatch>(jsonString);

            for (int playerNumber = 0; playerNumber < lobbyData.games[mapnumber].scores.Count(); playerNumber++) //in the selected map (game) it looks through each player who played in that map
            {
                //optimization possibility, track which users have already been added and don't request their names if they have already been added to reduce api requests.
                var userID = lobbyData.games[mapnumber].scores[playerNumber].user_id;

                try
                {
                    currentMapPlayers.Add(userID, 0); //adds userID to the list, afterwards this list will be used to fill the About.Players list with Usernames
                                                      //Players.Add(new KeyValuePair<string, double>(userID, 0));
                }
                catch (System.ArgumentException)
                {
                    //if the player already exists in the list, this exception will get thrown
                }
            }

            return(currentMapPlayers);
        }
Ejemplo n.º 3
0
        public void CalculateAccuracies(DeserializeMatch lobbyData)
        {
            //About.Players = About.PlayerTracker.ToList();

            //double[,] Accuracies = new double[About.PlayerTracker.Count, lobbyData.games.Count()]; // (Player | Score/Mapnumber)
            for (int Mapnumber = 0; Mapnumber < lobbyData.games.Count(); Mapnumber++)
            {
                List <KeyValuePair <string, double> > accs     = new List <KeyValuePair <string, double> >();
                List <KeyValuePair <string, double> > teamAccs = new List <KeyValuePair <string, double> >();

                /* Inaccuray points work like follows:
                 * misscount * 3
                 * 50 count * 2
                 * 100 count *1
                 * sum of those is inaccuracy points. Done to make the acc value absolute and not exponential (diff from 95 to 100 bigger than 70 to 75), makes relativ points calculation easier
                 */
                List <KeyValuePair <string, double> > InaccuracyPointsBlue = new List <KeyValuePair <string, double> >();
                List <KeyValuePair <string, double> > InaccuracyPointsRed  = new List <KeyValuePair <string, double> >();
                //calculate players
                for (int Player = 0; Player < About.PlayerTracker.Count; Player++)
                {
                    try
                    {
                        var countmiss = Convert.ToDouble(lobbyData.games[Mapnumber].scores[Player].countmiss);
                        var count50   = Convert.ToDouble(lobbyData.games[Mapnumber].scores[Player].count50);
                        var count100  = Convert.ToDouble(lobbyData.games[Mapnumber].scores[Player].count100);
                        var count300  = Convert.ToDouble(lobbyData.games[Mapnumber].scores[Player].count300);

                        var objectsCount = countmiss + count50 + count100 + count300;
                        var acc          = ((count300 * 3) + count100 + (count50 * 0.5)) / (objectsCount * 3); //calculates acc as percentage

                        //Accuracies[Player, Mapnumber] = acc;
                        string userID = lobbyData.games[Mapnumber].scores[Player].user_id;

                        if (Tournament.CustomTeams)
                        {
                            for (int i = 0; i < teamList.Teams.Length; i++)
                            {
                                if (teamList.Teams[i].Player1 == userID || teamList.Teams[i].Player2 == userID)
                                {
                                    teamList.Teams[i].TeamScore += acc;
                                }
                            }
                        }
                        else
                        {
                            accs.Add(new KeyValuePair <string, double>(userID, acc));
                        }
                        //for relative scoring shenanigens
                        //if (About.teamVS)
                        //{
                        //    var inaccuracyPoints = (countmiss * 3) + (count50 * 2) + count100;
                        //    if(lobbyData.games[Mapnumber].scores[Player].team == "1")
                        //    {
                        //        InaccuracyPointsBlue.Add(new KeyValuePair<string, double>(userID, inaccuracyPoints));
                        //    }
                        //    else
                        //    {
                        //        InaccuracyPointsRed.Add(new KeyValuePair<string, double>(userID, inaccuracyPoints));
                        //    }
                        //}
                        //else
                        //{
                        //    accs.Add(new KeyValuePair<string, double>(userID, acc));
                        //}
                    }
                    catch (Exception)
                    {
                        //Accuracies[Player, Mapnumber] = 0; //accuracies may not be needed, calculation still needs to get done in other categories.
                    }
                }
                //here the scoring type gets determined, needs to still be implemented in scores/maxcombo/misscount
                foreach (var team in teamList.Teams)
                {
                    teamAccs.Add(new KeyValuePair <string, double>(team.Teamname, team.TeamScore));
                }
                List <KeyValuePair <string, double> > points;
                if (Tournament.CustomTeams)
                {
                    points = PointCalculation.CalculatePointsAbsolute(teamAccs, true, (int)Category.Score).ToList(); //gets the points of each player for that specific map and puts that in the pointHistory object
                }
                else
                {
                    points = PointCalculation.CalculatePointsAbsolute(accs, true, (int)Category.Score).ToList(); //gets the points of each player for that specific map and puts that in the pointHistory object
                }

                if (Tournament.CustomTeams)
                {
                    for (int i = 0; i < points.Count; i++)
                    {
                        pointHistory.map[Mapnumber].users[i].accPoints = points[i].Value.ToString();
                    }
                }
                else
                {
                    if (About.teamVS)
                    {
                        double blue = 0;
                        double red  = 0;
                        foreach (var score in InaccuracyPointsBlue)
                        {
                            blue += score.Value;
                        }
                        foreach (var score in InaccuracyPointsRed)
                        {
                            red += score.Value;
                        }
                        if (blue > red) //this is to make sure that the first value is always the bigger one (in case of misscount and acc its the smaller one)
                        {
                            PointCalculation.CalculatePointsRelative(red, blue);
                        }
                        else
                        {
                            PointCalculation.CalculatePointsRelative(blue, red);
                        }
                    }
                    else
                    {
                        for (int i = 0; i < points.Count; i++)
                        {
                            pointHistory.map[Mapnumber].users[i].accPoints = points[i].Value.ToString();
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public void CalculateMisscount(DeserializeMatch lobbyData)
        {
            //double[,] Misscounts = new double[About.PlayerTracker.Count, lobbyData.games.Count()]; // (Player | Score/Mapnumber)
            for (int Mapnumber = 0; Mapnumber < lobbyData.games.Count(); Mapnumber++)
            {
                List <KeyValuePair <string, double> > misses     = new List <KeyValuePair <string, double> >();
                List <KeyValuePair <string, double> > teamMisses = new List <KeyValuePair <string, double> >();
                //calculate players
                for (int Player = 0; Player < About.PlayerTracker.Count; Player++)
                {
                    try
                    {
                        //Scores[Player, Mapnumber] = Convert.ToDouble(lobbyData.games[Mapnumber].scores[Player].score);
                        var misscount = Convert.ToDouble(lobbyData.games[Mapnumber].scores[Player].score);

                        string userID = lobbyData.games[Mapnumber].scores[Player].user_id;



                        if (Tournament.CustomTeams)
                        {
                            for (int i = 0; i < teamList.Teams.Length; i++)
                            {
                                if (teamList.Teams[i].Player1 == userID || teamList.Teams[i].Player2 == userID)
                                {
                                    teamList.Teams[i].TeamScore += misscount;
                                }
                            }
                        }
                        else
                        {
                            misses.Add(new KeyValuePair <string, double>(userID, misscount));
                        }
                    }
                    catch (Exception)
                    {
                        //Scores[Player, Mapnumber] = 0;
                    }
                }

                foreach (var team in teamList.Teams)
                {
                    teamMisses.Add(new KeyValuePair <string, double>(team.Teamname, team.TeamScore));
                }

                List <KeyValuePair <string, double> > points;
                if (Tournament.CustomTeams)
                {
                    points = PointCalculation.CalculatePointsAbsolute(teamMisses, false, (int)Category.Score).ToList(); //gets the points of each player for that specific map and puts that in the pointHistory object
                }
                else
                {
                    points = PointCalculation.CalculatePointsAbsolute(misses, false, (int)Category.Score).ToList(); //gets the points of each player for that specific map and puts that in the pointHistory object
                }

                if (Tournament.CustomTeams)
                {
                    for (int i = 0; i < points.Count; i++)
                    {
                        pointHistory.map[Mapnumber].users[i].countmissPoints = points[i].Value.ToString();
                    }
                }
                else
                {
                    if (About.teamVS)
                    {
                        double blue = 0;
                        double red  = 0;
                        foreach (var score in misses)
                        {
                            blue += score.Value;
                        }
                        foreach (var score in misses)
                        {
                            red += score.Value;
                        }
                        if (blue > red) //this is to make sure that the first value is always the bigger one (in case of misscount and acc its the smaller one)
                        {
                            PointCalculation.CalculatePointsRelative(red, blue);
                        }
                        else
                        {
                            PointCalculation.CalculatePointsRelative(blue, red);
                        }
                    }
                    else
                    {
                        for (int i = 0; i < points.Count; i++)
                        {
                            pointHistory.map[Mapnumber].users[i].countmissPoints = points[i].Value.ToString();
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public void ReadTotalPlayers(string jsonString)
        {
            DeserializeMatch lobbyData = JsonConvert.DeserializeObject <DeserializeMatch>(jsonString);

            List <KeyValuePair <string, double> > Players = new List <KeyValuePair <string, double> >(); //only temporarily used for optimazation purposes

            for (int gameNumber = 0; gameNumber < lobbyData.games.Count(); gameNumber++)                 // loops through each map (game)
            {
                Map map = new Map();
                map.beatmap_id = lobbyData.games[gameNumber].beatmap_id;


                if (Tournament.CustomTeams)
                {
                    foreach (var team in teamList.Teams)
                    {
                        try
                        {
                            User Team = new User();
                            Team.user_id = team.Teamname;
                            map.users.Add(Team);
                            About.PlayerTracker.Add(team.Teamname, 0);
                            Console.WriteLine(About.PlayerTracker);
                        }
                        catch (System.ArgumentException)
                        {
                            //gets caught if team already exists in Playertracker
                        }
                    }
                }
                else
                {
                    Dictionary <string, string> usersDictionary = new Dictionary <string, string>();

                    for (int playerNumber = 0; playerNumber < lobbyData.games[gameNumber].scores.Count(); playerNumber++) //in the selected map (game) it looks through each player who played in that map
                    {
                        var userID = lobbyData.games[gameNumber].scores[playerNumber].user_id;
                        try
                        {
                            if (!usersDictionary.Keys.Contains(userID)) //if the user ID does not exist in the list yet
                            {
                                var    userJsonString = "https://osu.ppy.sh/api/get_user?k=0db10863146202c12ca6f6987c98f1ec9d629421&u=" + userID;
                                var    jsonStringUser = new WebClient().DownloadString(userJsonString); //downloads the json data of the user
                                JArray userJsonArray  = JArray.Parse(jsonStringUser);
                                var    userName       = (string)userJsonArray[0].SelectToken("username");

                                usersDictionary.Add(userID, userName);
                            }

                            //these 3 codelines need to happen before adding the users to the playertracker, because that will throw an exception if the user already exists and thus skip the rest of the try block
                            User user = new User();
                            user.user_id = userID;
                            map.users.Add(user);

                            About.PlayerTracker.Add(userID, 0); //adds userID to the list, afterwards this list will be used to fill the About.Players list with Usernames


                            //Players.Add(new KeyValuePair<string, double>(userID, 0)); f
                        }
                        catch (System.ArgumentException)
                        {
                            //if the player already exists in the list, this exception will get thrown
                        }
                    }
                    userList = usersDictionary;
                }
                pointHistory.map.Add(map);
            }

            //converts userID to username
            //foreach (KeyValuePair<string, double> player in Players)
            //{
            //    var userJsonString = "https://osu.ppy.sh/api/get_user?k=0db10863146202c12ca6f6987c98f1ec9d629421&u=" + player.Key;
            //    var jsonStringUser = new WebClient().DownloadString(userJsonString); //downloads the json data of the user
            //    JArray userJsonArray = JArray.Parse(jsonStringUser);
            //    var userName = (string)userJsonArray[0].SelectToken("username");

            //    About.Players.Add(new KeyValuePair<string, double>(userName, 0)); //adds player to the dictionary where all players of a match are stored

            //}
        }