/// <summary> /// Get the list of number of successful login and list of number of failed login per month /// Divide number of successful login by the number of total login attempts /// The avgLogin will be sorted in reverse chronological order /// It will get the data of recent 12 month according to the business rules. /// </summary> /// <returns>avgLogin</returns> public IDictionary <string, double> GetAverageSuccessfulLogin() { int numOfMonth = BusinessRuleConstants.GetAverageSuccessfulLogin_NumOfMonth; IDictionary <int, long> successLogin = _dashboardService.CountSuccessfulLogin(numOfMonth); IDictionary <int, long> failedLogin = _dashboardService.CountFailedLogin(numOfMonth); IDictionary <string, double> avgLogin = new Dictionary <string, double>(); int monthToday = DateTime.Today.Month; // Calculate average successful login per month for (int i = 1; i < numOfMonth + 1; i++) { double avgSuccessfulLogin = 0; if (successLogin.ContainsKey(monthToday)) // checks there is logged in user in the month { double numSuccessfulLogin = 0; double numFailedLogin = 0; numSuccessfulLogin = successLogin[monthToday]; if (failedLogin.ContainsKey(monthToday)) // checks there is failed logged attempt in the month { numFailedLogin = failedLogin[monthToday]; } double totalLoginAttempt = numSuccessfulLogin + numFailedLogin; avgSuccessfulLogin = numSuccessfulLogin / totalLoginAttempt; } avgLogin.Add(dateFormatConverter[monthToday], avgSuccessfulLogin * 100); // percentage monthToday--; if (monthToday == 0) { monthToday = 12; } } return(avgLogin); }
static void Main(string[] args) { DashboardManager manager = new DashboardManager(url, database); DashboardService service = new DashboardService(); IDictionary <int, long> get = service.CountSuccessfulLogin(24); IDictionary <int, long> get2 = service.CountFailedLogin(12); //IList<Double> get3 = manager.GetAverageSuccessfulLogin(); IDictionary <int, long> get4 = service.CountSuccessfulLogin(1); IDictionary <string, long> temp11 = manager.GetSuccessfulLoggedInUsers(); foreach (var s in temp11) { Console.WriteLine(s); } /** * Console.WriteLine("succesufl"); * foreach (var s in get) * { * Console.WriteLine(s.Key + "," + s.Value); * } * Console.WriteLine("failed login"); * foreach (var s in get2) * { * Console.WriteLine(s.Key + "," + s.Value); * } * Console.WriteLine("Avg successful login"); * foreach (var s in get3) * { * Console.WriteLine(s.Key + "," + s.Value); * } **/ //ICollection<DateTime> list = service.CountAverageSessionDuration(1, 2019); //for (int i = 0; i < list.Count(); i++) //{ // Console.WriteLine("Print:" + list.ElementAt(i)); //} long sum = service.CountUniqueLoggedInUsers(1, 2019); Console.WriteLine("sum:" + sum); //IDictionary<string, long> something3 = service.CountMostUsedFiveFeature(2); Console.WriteLine("hi"); Console.ReadKey(); }