Exemple #1
0
        public void Deserialize(BinaryAPIReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            HostOsuId   = reader.ReadLong();
            Name        = reader.ReadString();
            Acronym     = reader.ReadString();
            Thread      = reader.ReadString();
            CountryCode = reader.ReadString();
            Start       = reader.ReadDate();
            End         = reader.ReadDate();
            RankMin     = reader.ReadLong();
            RankMax     = reader.ReadLong();

            int teams = reader.ReadInt();

            for (int i = 0; i < teams; i++)
            {
                GlobalStatsTeam team = new GlobalStatsTeam();
                team.Deserialize(reader);

                Teams.Add(team);
            }
        }
Exemple #2
0
        public static GlobalStatsTournament FromTSVFile(string file)
        {
            if (!File.Exists(file))
            {
                return(null);
            }

            GlobalStatsTournament tourney = new GlobalStatsTournament();

            bool teamSearch = false;

            using (StreamReader reader = new StreamReader(file))
            {
                while (!reader.EndOfStream)
                {
                    string line = reader.ReadLine();

                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }

                    string[] split = line.Split('\t');

                    if (split.Length < 4)
                    {
                        Console.WriteLine("Line too short: " + line);
                        return(null);
                    }

                    if (!teamSearch)
                    {
                        tourney.HostOsuId = GetInt(split[0]);

                        tourney.Name        = split[1];
                        tourney.Acronym     = split[2];
                        tourney.Thread      = split[3];
                        tourney.CountryCode = split[4];

                        tourney.Start = GetDate(split[5]);
                        tourney.End   = GetDate(split[6]);

                        tourney.RankMin = GetInt(split[7]);
                        tourney.RankMax = GetInt(split[8]);

                        if (tourney.HostOsuId == -1)
                        {
                            Console.WriteLine("Failed to read host id");
                            return(null);
                        }

                        teamSearch = true;
                        continue;
                    }

                    GlobalStatsTeam team = new GlobalStatsTeam();
                    team.Placement = GetInt(split[1]);
                    team.Name      = split[0];

                    for (int i = 2; i < split.Length; i++)
                    {
                        team.OsuUserIds.Add(GetLong(split[i]));
                    }

                    tourney.Teams.Add(team);
                }
            }

            return(tourney);

            int GetInt(string value)
            {
                if (int.TryParse(value, out int result))
                {
                    return(result);
                }

                return(-1);
            }

            long GetLong(string value)
            {
                if (long.TryParse(value, out long result))
                {
                    return(result);
                }

                return(-1);
            }

            DateTime GetDate(string value)
            {
                string[]      dateAndHourSplit = value.Split(' ');
                string[]      dateSplit        = dateAndHourSplit[0].Split('.');
                List <string> hourSplit        = dateAndHourSplit[1].Split(':').ToList();

                if (hourSplit[hourSplit.Count - 1].Contains('.', StringComparison.CurrentCultureIgnoreCase))
                {
                    string[] msSplit = hourSplit[hourSplit.Count - 1].Split('.');
                    hourSplit.RemoveAt(hourSplit.Count - 1);

                    hourSplit.AddRange(msSplit);
                }
                else
                {
                    hourSplit.Add("0");
                }

                DateTime date = new DateTime(GetInt(dateSplit[0]), GetInt(dateSplit[1]), GetInt(dateSplit[2]), GetInt(hourSplit[0]), GetInt(hourSplit[1]), GetInt(hourSplit[2]), GetInt(hourSplit[3]));

                return(date);
            }
        }