public void ResolveExcess_AddsExcessToHighestCounter(double initial, double expected, double lowest) { var counter1 = new CounterStatistics { Percent = initial }; var counter2 = new CounterStatistics { Percent = lowest }; var counters = new List <CounterStatistics> { counter1, counter2 }; new CounterManager().ResolveExcess(counters); Assert.Equal(expected, counter1.Percent); Assert.Equal(lowest, counter2.Percent); var counter3 = new CounterStatistics { Percent = initial }; var counter4 = new CounterStatistics { Percent = lowest }; counters = new List <CounterStatistics> { counter4, counter3 }; new CounterManager().ResolveExcess(counters); Assert.Equal(expected, counter3.Percent); Assert.Equal(lowest, counter4.Percent); }
public void DisplaysPollStatitstics() { var pollId = 1; var counter1 = new Counter { Name = "One", Count = 2 }; var counter2 = new Counter { Name = "Two", Count = 1 }; var counterStats1 = new CounterStatistics { Name = "One", Count = 2, Percent = 60 }; var counterStats2 = new CounterStatistics { Name = "Two", Count = 1, Percent = 40 }; var counterStats = new List <CounterStatistics> { counterStats1, counterStats2 }; var poll = new VotingPoll { Title = "title", Description = "desc", Counters = new List <Counter> { counter1, counter2 } }; _mockPersistance.Setup(x => x.GetPoll(pollId)).Returns(poll); _mockCounterManager.Setup(x => x.GetStatistics(poll.Counters)).Returns(counterStats); var interactor = new StatisticsInteractor( _mockPersistance.Object, _mockCounterManager.Object); var pollStatistics = interactor.GetStatistics(pollId); Assert.Equal(poll.Title, pollStatistics.Title); Assert.Equal(poll.Description, pollStatistics.Description); var stats1 = pollStatistics.Counters[0]; Assert.Equal(counterStats1.Name, stats1.Name); Assert.Equal(counterStats1.Count, stats1.Count); Assert.Equal(counterStats1.Percent, stats1.Percent); var stats2 = pollStatistics.Counters[1]; Assert.Equal(counterStats2.Name, stats2.Name); Assert.Equal(counterStats2.Count, stats2.Count); Assert.Equal(counterStats2.Percent, stats2.Percent); _mockCounterManager.Verify(x => x.ResolveExcess(counterStats), Times.Once); }
public void ResolveExcess_DoesntAddExcessIfTotalPercentIs100() { var counter1 = new CounterStatistics { Percent = 80 }; var counter2 = new CounterStatistics { Percent = 20 }; var counters = new List <CounterStatistics> { counter1, counter2 }; new CounterManager().ResolveExcess(counters); Assert.Equal(80, counter1.Percent); Assert.Equal(20, counter2.Percent); }
public void ResolveExcess_DoesntAddExcessWhenAllCountersAreEqual() { var counter1 = new CounterStatistics { Percent = 33.33 }; var counter2 = new CounterStatistics { Percent = 33.33 }; var counter3 = new CounterStatistics { Percent = 33.33 }; var counters = new List <CounterStatistics> { counter1, counter2, counter3 }; new CounterManager().ResolveExcess(counters); Assert.Equal(33.33, counter1.Percent); Assert.Equal(33.33, counter2.Percent); Assert.Equal(33.33, counter3.Percent); }
public void ResolveExcess_AddsToLowestCounterWhenMoreThanOneHighestCounters(double initial, double expected, double highest) { var counter1 = new CounterStatistics { Percent = highest }; var counter2 = new CounterStatistics { Percent = highest }; var counter3 = new CounterStatistics { Percent = initial }; var counters = new List <CounterStatistics> { counter1, counter2, counter3 }; new CounterManager().ResolveExcess(counters); Assert.Equal(highest, counter1.Percent); Assert.Equal(highest, counter2.Percent); Assert.Equal(expected, counter3.Percent); }
public void ResolveExcess_DoesntAddExcesswhenAllCountersAreEqual(double percent) { var counter1 = new CounterStatistics { Percent = percent }; var counter2 = new CounterStatistics { Percent = percent }; var counter3 = new CounterStatistics { Percent = percent }; var counters = new List <CounterStatistics> { counter1, counter2, counter3 }; new CounterManager().ResolveExcess(counters); Equal(percent, counter1.Percent); Equal(percent, counter2.Percent); Equal(percent, counter3.Percent); }
// GET: Home public ActionResult Home() { if (TempData["Access"] == null) { CountVisitors(); } var info = new DirectoryInfo(Server.MapPath("~/AllContent/home-images")); ViewBag.ImageHome = info.GetFiles().OrderByDescending(t => t.CreationTime).ToList(); var model = new OptionModel { Option = OptionList() }; //Get newest book by library var topNewBookFromHoaLac = _dbContext.SP_OPAC_GET_NEW_ITEMS(true, 0, 10, 81).ToList(); var topNewBookFromDetect = _dbContext.SP_OPAC_GET_NEW_ITEMS(true, 0, 10, 20).ToList(); var topNewBookFromFSBHaNoi = _dbContext.SP_OPAC_GET_NEW_ITEMS(true, 0, 10, 111).ToList(); var topNewBookFromDaNang = _dbContext.SP_OPAC_GET_NEW_ITEMS(true, 0, 10, 24).ToList(); var mostUsedBook = _dbContext.FPT_SP_OPAC_GET_MOST_USE_ITEMS().ToList(); //DateTime for counter var today = DateTime.Today.ToString("dd/MM/yyyy"); var yesterday = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.AddDays(-1).Day) .ToString("dd/MM/yyyy"); var thisMonth = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).ToString("dd/MM/yyyy"); var lastMonth = DateTime.Now.Month == 1 ? new DateTime(DateTime.Now.AddYears(-1).Year, 12, 1).ToString("dd/MM/yyyy") : new DateTime(DateTime.Now.Year, DateTime.Now.AddMonths(-1).Month, 1).ToString("dd/MM/yyyy"); foreach (var item in topNewBookFromHoaLac) { item.Content = RemoveSpecialCharacter(item.Content); } foreach (var item in topNewBookFromDetect) { item.Content = RemoveSpecialCharacter(item.Content); } foreach (var item in topNewBookFromFSBHaNoi) { item.Content = RemoveSpecialCharacter(item.Content); } foreach (var item in topNewBookFromDaNang) { item.Content = RemoveSpecialCharacter(item.Content); } foreach (var item in mostUsedBook) { item.Content = RemoveSpecialCharacter(item.Content); } //Pass newest books to view ViewBag.TopNewBookFromHoaLac = topNewBookFromHoaLac; ViewBag.TopNewBookFromDetect = topNewBookFromDetect; ViewBag.TopNewBookFromFSBHaNoi = topNewBookFromFSBHaNoi; ViewBag.TopNewBookFromDaNang = topNewBookFromDaNang; ViewBag.MostUsedBook = mostUsedBook; CounterStatistics counter = GetCounterStatistics(); ViewBag.CounterStatistics = counter; ViewBag.Total = counter.GetTotal(); //TypeID = 1 : News, 2 : Notification ViewBag.News = _dbContext.NOTICE_STORE.Where(t => t.TypeID == 1).OrderByDescending(t => t.CreateTime).Take(4).ToList(); ViewBag.FullNews = _dbContext.NOTICE_STORE.Where(t => t.TypeID == 1).OrderByDescending(t => t.CreateTime).ToList(); ViewBag.Notification = _dbContext.NOTICE_STORE.Where(t => t.TypeID == 2).OrderByDescending(t => t.CreateTime) .Take(4).ToList(); ViewBag.FullNotification = _dbContext.NOTICE_STORE.Where(t => t.TypeID == 2).OrderByDescending(t => t.CreateTime).ToList(); //Pass date for counter to view ViewBag.Today = today; ViewBag.Yesterday = yesterday; ViewBag.ThisMonth = thisMonth; ViewBag.LastMonth = lastMonth; TempData["CountResultList"] = 0; TempData["Flag"] = null; return View(model); }
//Get data of counter visitor private CounterStatistics GetCounterStatistics() { var statisticsList = _dbContext.SYS_COUNTER.ToList(); int countToday = 0; int countYesterday = 0; int countThisWeek = 0; int countLastWeek = 0; int countThisMonth = 0; int countLastMonth = 0; DateTime today = DateTime.Now.Date; DateTime yesterday = today.AddDays(-1); DateTime startCurrentWeekDate = DateTime.Today.AddDays(-1 * (int) DateTime.Today.DayOfWeek).AddDays(1); DateTime endCurrentWeekDate = startCurrentWeekDate.AddDays(7).AddSeconds(-1); DateTime startLastWeekDate = startCurrentWeekDate.AddDays(-7); DateTime endLastWeekDate = startLastWeekDate.AddDays(7).AddSeconds(-1); DateTime startCurrentMonth = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); DateTime endCurrentMonth = startCurrentMonth.AddMonths(1).AddSeconds(-1); DateTime startLastMonth; DateTime endLastMonth; if (DateTime.Now.Month == 1) { startLastMonth = new DateTime(DateTime.Now.AddYears(-1).Year, 12, 1); endLastMonth = new DateTime(DateTime.Now.AddYears(-1).Year, DateTime.Now.Month, 1); } else { startLastMonth = new DateTime(DateTime.Now.Year, DateTime.Now.AddMonths(-1).Month, 1); endLastMonth = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddSeconds(-1); } foreach (var item in statisticsList) { if (item.AccessedDate.Date == today.Date) { countToday += Convert.ToInt32(item.AccessedTime); } if (item.AccessedDate.Date == yesterday.Date) { countYesterday += Convert.ToInt32(item.AccessedTime); } if (BetweenTime(item.AccessedDate, startCurrentWeekDate, endCurrentWeekDate)) { countThisWeek += Convert.ToInt32(item.AccessedTime); } if (BetweenTime(item.AccessedDate, startLastWeekDate, endLastWeekDate)) { countLastWeek += Convert.ToInt32(item.AccessedTime); } if (BetweenTime(item.AccessedDate, startCurrentMonth, endCurrentMonth)) { countThisMonth += Convert.ToInt32(item.AccessedTime); } if (BetweenTime(item.AccessedDate, startLastMonth, endLastMonth)) { countLastMonth += Convert.ToInt32(item.AccessedTime); } } CounterStatistics counterStatistics = new CounterStatistics() { Today = countToday, Yesterday = countYesterday, ThisWeek = countThisWeek, LastWeek = countLastWeek, ThisMonth = countThisMonth, LastMonth = countLastMonth }; return counterStatistics; }