public void WorkingStatistics(User user) { Console.Clear(); //var allWorkingAc = user.ListOfActivities.OfType<Working>().ToList(); var allWorkingAc = user.WorkingActivities; if (!ValidationHelpers.CheckIfListIsEmpty(allWorkingAc, "working statistics")) { return; } var totalWorkingHours = allWorkingAc.Sum(hours => hours.TrackedTime.Minutes); var averageWorking = allWorkingAc.Average(min => min.TrackedTime.Minutes); var homeWorking = allWorkingAc.Where(working => working.WorkingFrom == WorkingFrom.Home) .Sum(hours => hours.TrackedTime.Hours); var officeWorking = allWorkingAc.Where(working => working.WorkingFrom == WorkingFrom.Offce) .Sum(hours => hours.TrackedTime.Hours); // Favourite type int home = allWorkingAc.Where(x => x.WorkingFrom == WorkingFrom.Home).Count(); int office = allWorkingAc.Where(x => x.WorkingFrom == WorkingFrom.Offce).Count(); var workingDictionary = new Dictionary <WorkingFrom, int>() { { WorkingFrom.Home, home }, { WorkingFrom.Offce, office }, }; var favoritetype = workingDictionary.FirstOrDefault(type => type.Value == workingDictionary.Values.Max()).Key.ToString(); StringBuilder sb = new StringBuilder(); sb.Append($"Total working hours: {totalWorkingHours}\n") .Append($"Average time spent working: {averageWorking} min.\n") .Append($"Home worknig hours: {homeWorking}\n") .Append($"Office working hours {officeWorking}\n") .Append($"Favourite type: {favoritetype}\n"); Console.WriteLine(sb.ToString()); }
public void ReadingStatistics(User user) { Console.Clear(); //var allReadingAc = user.ListOfActivities.OfType<Reading>().ToList(); //var allReadingAc = user.ListOfActivities.Where(ac => ac.ActivityType == ActivityType.Reading).ToList(); var allReadingAc = user.ReadingActivities; if (!ValidationHelpers.CheckIfListIsEmpty(allReadingAc, "reading statistics")) { return; } var totalaReadingHours = allReadingAc.Sum(hours => hours.TrackedTime.Minutes); var averageReading = allReadingAc.Average(min => min.TrackedTime.Minutes); var totalPages = allReadingAc.Sum(pages => pages.Pages); // Favourite type int bellesLetters = allReadingAc.Where(x => x.BookType == BookType.BellesLettres).Count(); int fiction = allReadingAc.Where(x => x.BookType == BookType.Fiction).Count(); int profesionlLit = allReadingAc.Where(x => x.BookType == BookType.ProfessionalLiterature).Count(); var readingDictionary = new Dictionary <BookType, int>() { { BookType.BellesLettres, bellesLetters }, { BookType.Fiction, fiction }, { BookType.ProfessionalLiterature, profesionlLit }, }; var favoritetype = readingDictionary.FirstOrDefault(type => type.Value == readingDictionary.Values.Max()).Key.ToString(); StringBuilder sb = new StringBuilder(); sb.Append($"Total reading hours: {totalaReadingHours}\n") .Append($"Average time spent reading: {averageReading} min\n") .Append($"Total number of read pages: {totalPages}\n") .Append($"Favourite type: {favoritetype}\n"); Console.WriteLine(sb.ToString()); }
public void OtherHobbiesStatistics(User user) { Console.Clear(); var allOtherHobbies = user.ListOfActivities.OfType <OtherHobbies>().ToList(); if (!ValidationHelpers.CheckIfListIsEmpty(allOtherHobbies, "other hobbies statistics")) { return; } var totalOtherHobbiesHours = allOtherHobbies.Sum(hours => hours.TrackedTime.Minutes); var namesOfHobbies = allOtherHobbies.Select(names => names.HobbyName).ToList(); Console.WriteLine($"Total hours spent in your hobbies: {totalOtherHobbiesHours}"); Console.WriteLine("Your hobbies:"); foreach (var hobby in namesOfHobbies.Distinct()) { Console.WriteLine($"-{hobby}"); } }
public void ExercisingStatistics(User user) { Console.Clear(); //var allExercisingAc = user.ListOfActivities.OfType<Exercising>().ToList(); var allExercisingAc = user.ExercisingActivities; if (!ValidationHelpers.CheckIfListIsEmpty(allExercisingAc, "exercising statistics")) { return; } var totalalExercisingHours = allExercisingAc.Sum(hours => hours.TrackedTime.Minutes); var averageExercising = allExercisingAc.Average(min => min.TrackedTime.Minutes); // Favourite type int running = allExercisingAc.Where(x => x.ExercisingType == ExercisingType.Running).Count(); int general = allExercisingAc.Where(x => x.ExercisingType == ExercisingType.General).Count(); int sport = allExercisingAc.Where(x => x.ExercisingType == ExercisingType.Sport).Count(); var exercisingDictionary = new Dictionary <ExercisingType, int>() { { ExercisingType.Running, running }, { ExercisingType.General, general }, { ExercisingType.Sport, sport }, }; var favoritetype = exercisingDictionary.FirstOrDefault(type => type.Value == exercisingDictionary.Values.Max()).Key.ToString(); StringBuilder sb = new StringBuilder(); sb.Append($"Total exercising hours: {totalalExercisingHours}\n") .Append($"Average time spent exercising: {averageExercising} min.\n") .Append($"Favourite type: {favoritetype}\n"); Console.WriteLine(sb.ToString()); }
static void Main(string[] args) { //UserData(); while (true) { int userChoice = menus.LogInMenu(); Console.Clear(); switch (userChoice) { case 1: Console.Write("Enter username: "******"Enter password: "******"Enter the folowing to register:"); Console.WriteLine("First name:"); string firstName = Console.ReadLine(); Console.WriteLine("Last name:"); string lastName = Console.ReadLine(); Console.WriteLine("Age:"); int age = ValidationHelpers.ParseNumber(Console.ReadLine(), 120); Console.WriteLine("Username:"******"Password:"******"You succesfully registered!", ConsoleColor.Green); currentUser = user; if (currentUser == null) { continue; } break; case 3: Environment.Exit(0); break; } if (currentUser == null) { continue; } bool isLoggedIn = true; while (isLoggedIn) { Console.WriteLine($"Hi {currentUser.FirstName} choose one of the following?"); int choice = menus.MainMenu(); ActivityType currentActivity = (ActivityType)choice; Console.Clear(); switch (choice) { case 1: case 2: case 3: case 4: appServices.TrackingTime(currentActivity, currentUser, userService); break; case 5: if (!ValidationHelpers.CheckIfListIsEmpty(currentUser.ListOfActivities, "statistics")) { continue; } int statisticsMenu = menus.StatisticsMenu(); userService.SeeStatistics(currentUser, statisticsMenu); break; case 6: int accountMenu = menus.AccountMenu(); if (userService.AccountSettings(currentUser.Id, accountMenu, currentUser)) { isLoggedIn = !isLoggedIn; } break; case 7: isLoggedIn = !isLoggedIn; break; default: break; } } } }
static void Main(string[] args) { UsersList(); //_menu.HomeScreen(); while (true) { int menuChoice = _menu.LogInMenu(); switch (menuChoice) { case 1: Console.WriteLine("Enter username: "******"Enter password: "******"Enter your First Name: "); string firstName = Console.ReadLine(); Console.WriteLine("Enter your Last Name: "); string lastName = Console.ReadLine(); Console.WriteLine("Enter your userName: "******"Enter your password: "******"Enter your age: "); int age = ValidationHelpers.TryParseNumber(Console.ReadLine(), 120); var user = new User(firstName, lastName, nameUser, userPassword, age); _currentUser = _userService.Register(user); if (_currentUser == null) { MessageHelpers.Message("Unsuccesful registration please try again", ConsoleColor.Red); Thread.Sleep(1500); continue; } MessageHelpers.Message("You succesfully registered!", ConsoleColor.Green); break; case 3: Environment.Exit(0); break; } bool isLoggedIn = true; while (isLoggedIn) { Console.WriteLine($"Hi {_currentUser.FirstName} choose one of the following?"); int choice = _menu.MainMenu(); ActivityType currentActivity = (ActivityType)choice; Console.Clear(); switch (choice) { case 1: case 2: case 3: case 4: _activityServices.TrackingTime(currentActivity, _currentUser); break; case 5: if (!ValidationHelpers.CheckIfListIsEmpty(_currentUser.ListOfActivities, "statistics")) { continue; } int statisticsMenu = _menu.StatisticsMenu(); _userService.UserStatistics(_currentUser, statisticsMenu); break; case 6: int accountMenu = _menu.AccountMenu(); if (_userService.AccountSettings(_currentUser.Id, accountMenu, _currentUser)) { isLoggedIn = !isLoggedIn; } break; case 7: isLoggedIn = !isLoggedIn; break; default: break; } } } }