예제 #1
0
        static void AnalyseStats()
        {
            List <User> users = DataBase.GetUsers();

            Console.WriteLine($"Total Statistics: {users.Count}");

            PropertyInfo[] properties = typeof(Stats).GetProperties();
            foreach (PropertyInfo property in properties)
            {
                object max = users.Max(x => property.GetValue(x.Statistics));
                object min = users.Min(x => property.GetValue(x.Statistics));

                Console.WriteLine($"{property.Name}:");
                Console.WriteLine($"  Highest: {max}");

                if (property.PropertyType == typeof(uint))
                {
                    object avg = users.Average(x => (uint)property.GetValue(x.Statistics));
                    Console.WriteLine($"  Average: {avg}");
                }
                else if (property.PropertyType == typeof(DateTime))
                {
                    double avg = users.Average(x => ((DateTime)property.GetValue(x.Statistics)).Ticks);
                    Console.WriteLine($"  Average: {new DateTime((long)avg)}");
                }
                else if (property.PropertyType == typeof(TimeSpan))
                {
                    double avg = users.Average(x => ((TimeSpan)property.GetValue(x.Statistics)).Ticks);
                    Console.WriteLine($"  Average: {new TimeSpan((long)avg)}");
                }

                Console.WriteLine($"  Lowest:  {min}");
            }
        }
예제 #2
0
        static void PrintUsers()
        {
            int count = 0;

            foreach (User user in DataBase.GetUsers())
            {
                Console.WriteLine($"User {++count}:");
                Console.WriteLine($"  ID:        {user.ID.ToID().ToUpper()}");
                Console.WriteLine($"  Name:      {user.Name}");
                Console.WriteLine($"  LoginInfo: {user.LoginInfo.ToID().ToUpper()}");
                Console.WriteLine("  Statistics:");

                foreach (var property in user.Statistics.GetType().GetProperties())
                {
                    string value = property.GetValue(user.Statistics).ToString();
                    value = value.PadLeft(30 - property.Name.Length + value.Length);
                    Console.WriteLine($"    {property.Name}: {value}");
                }
            }
        }