Beispiel #1
0
        public async Task <UserStatisticsViewModel> GetUserStatistics(int userId)
        {
            var usersVisits = await _applicationDbContext.Visits
                              .Include(x => x.SightSeens)
                              .Include(x => x.Tour)
                              .ThenInclude(x => x.City)
                              .ThenInclude(x => x.Country)
                              .ThenInclude(x => x.Region)
                              .Where(x => x.UserId == userId && x.EndDate != null).ToListAsync();

            var distinctTourVisits = usersVisits.Distinct(new DistinctToursComparer());
            var toursVisited       = distinctTourVisits.Count();
            var sightsSeen         = distinctTourVisits.Aggregate(0, (sum, x) => sum += x.SightSeens != null ? x.SightSeens.Count() : 0, sum => sum);
            var visitsInfo         = usersVisits.Select(x =>
                                                        new VisitInfoViewModel {
                VisitId           = x.VisitId,
                DurationInSeconds = (int)(x.EndDate - x.StartDate).TotalSeconds,
                TourId            = x.TourId,
                TourTitle         = x.Tour.Title,
                City    = x.Tour.City.Name,
                Country = x.Tour.City.Country.Name,
                Region  = x.Tour.City.Country.Region.Name
            }).ToList();
            UserStatisticsViewModel result = new UserStatisticsViewModel {
                ToursVisited = toursVisited, SightsSeen = sightsSeen, Visits = visitsInfo
            };

            return(result);
        }
        public static UserStatisticsViewModel MapToUserStatisticsViewModel(
            this UserStatisticsDb dbEntity)
        {
            var viewModel = new UserStatisticsViewModel
            {
                PublicAskedQuestions    = dbEntity.PublicAskedQuestions,
                AnsweredQuestions       = dbEntity.AnsweredQuestions,
                PublicAnsweredQuestions = dbEntity.PublicAnsweredQuestions,
                PublicFavoriteQuestions = dbEntity.PublicFavoriteQuestions,
                CommentsWritten         = dbEntity.CommentsWritten,

                UserQuestionsShows   = dbEntity.UserQuestionsShows,
                UserQuestionsAnswers = dbEntity.UserQuestionsAnswers,

                QuestionsCommentsGot  = dbEntity.QuestionsCommentsGot,
                QuestionsLikesGot     = dbEntity.QuestionsLikesGot,
                QuestionsDislikesGot  = dbEntity.QuestionsDislikesGot,
                CommentsLikesGot      = dbEntity.CommentsLikesGot,
                CommentsDislikesGot   = dbEntity.CommentsDislikesGot,
                QuestionsLikesMade    = dbEntity.QuestionsLikesMade,
                QuestionsDislikesMade = dbEntity.QuestionsDislikesMade,
                CommentsLikesMade     = dbEntity.CommentsLikesMade,
                CommentsDislikesMade  = dbEntity.CommentsDislikesMade
            };

            return(viewModel);
        }
Beispiel #3
0
        public UserStatisticsViewModel GetUsersThatReadTheMost(int i)
        {
            var models = this.statisticsRepository.GetUsersThatReadMostNews(i);
            var list   = models.Select(ProjectToViewModel)
                         .ToList();
            var userStatisticsViewModel = new UserStatisticsViewModel(list);

            return(userStatisticsViewModel);
        }
        public ActionResult UserStatistics(string userId)
        {
            var viewModel = new UserStatisticsViewModel();
            viewModel.CommentsCount = this.statisticsServices.GetUserCommentsCount(userId);
            viewModel.TripsAsDriverCount = this.statisticsServices.GetUserTripsAsDriverCount(userId);
            viewModel.TripsAsPassengerCount = this.statisticsServices.GetUserTripsAsPassengerCount(userId);
            viewModel.TotalTrips = viewModel.TripsAsDriverCount + viewModel.TripsAsPassengerCount;

            return this.PartialView("~/Areas/UserProfile/Views/Profile/_UserStatisticsSectionPartial.cshtml", viewModel);
        }
        public ActionResult UserStatistics(int id, Period period = Period.month, string sortOrder = "NameAsc")
        {
            ViewBag.CurrentSort = sortOrder;

            var urls        = urlRepository.List().Where(x => x.ShowInStatistics == true).OrderBy(x => x.Name);
            var visitedUrls = new List <UrlViewModel>();

            foreach (var url in urls)
            {
                var logs    = logRepository.ListByUserAndUrl(id, url.Name, period);
                var history = histRepository.ListByUserAndUrl(id, url.Id, period);
                if (logs.Count() > 0 || history.Count() > 0)
                {
                    double totalDuration = 0;
                    foreach (var log in logs)
                    {
                        totalDuration += log.Duration;
                    }

                    var visitedUrl = new UrlViewModel()
                    {
                        Id                 = url.Id,
                        Name               = url.Name,
                        Hits               = logs.Count(),
                        HitsOld            = history.Count(),
                        Duration           = totalDuration / logs.Count(),
                        LatestVisitDate    = logs.Count() > 0 ? logs.Last().TimeStamp.ToString() : "",
                        LatestVisitDateOld = history.Count() > 0 ? history.Last().HistoryIdentifier.Date.ToString() : ""
                    };
                    visitedUrls.Add(visitedUrl);
                }
            }

            var sortedUrls = new List <UrlViewModel>();

            switch (sortOrder)
            {
            case "NameAsc":
                sortedUrls = visitedUrls.OrderBy(x => x.Name).ToList();
                break;

            case "LatestVisitDateDesc":
                sortedUrls = visitedUrls.OrderByDescending(x => x.LatestVisitDate).ToList();
                break;

            case "HitsDesc":
                sortedUrls = visitedUrls.OrderByDescending(x => x.Hits).ToList();
                break;

            case "DurationDesc":
                sortedUrls = visitedUrls.OrderByDescending(x => x.Duration).ToList();
                break;
            }

            var users = userRepository.List();

            var viewModel = new UserStatisticsViewModel()
            {
                Id          = id,
                Users       = users,
                Period      = period,
                VisitedUrls = sortedUrls
            };

            return(View(viewModel));
        }
        public ActionResult Statistics()
        {
            // permision check
            if (!RoleHelper.IsAdmin())
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, $"Permision denied"));
            }

            var result = new List <UserStatisticsViewModel>();

            for (var dateTime = DateTime.Now;
                 dateTime.Month != DateTime.Now.AddMonths(-3).Month;
                 dateTime = dateTime.AddDays(-1))
            {
                var newUserNumber =
                    this.Data.Users.All()
                    .Count(
                        user =>
                        user.RegisteredTime.Month == dateTime.Month && user.RegisteredTime.Day == dateTime.Day);

                var dateTimeLastDay = dateTime.AddDays(-1);

                var lastDayUserNumber =
                    (double)
                    this.Data.Users.All()
                    .Count(
                        user =>
                        user.RegisteredTime.Month == dateTimeLastDay.Month &&
                        user.RegisteredTime.Day == dateTimeLastDay.Day);

                double userIncreasingRatio;
                if (Math.Abs(lastDayUserNumber) < 1e-6)
                {
                    userIncreasingRatio = 0;
                }
                else
                {
                    userIncreasingRatio = (double)newUserNumber /
                                          (double)
                                          this.Data.Users.All()
                                          .Count(
                        user =>
                        user.RegisteredTime.Month == dateTimeLastDay.Month &&
                        user.RegisteredTime.Day == dateTimeLastDay.Day);

                    userIncreasingRatio = (userIncreasingRatio - 1.0) * 100;
                }

                var activeUserNumber = 1;

                var newActivities =
                    this.Data.Activity.All()
                    .Count(
                        activity =>
                        activity.PublishTime.Month == dateTime.Month && activity.PublishTime.Day == dateTime.Day);

                var newPosts =
                    this.Data.Tweets.All()
                    .Count(tweet => tweet.DatePosted.Month == dateTime.Month && tweet.DatePosted.Day == dateTime.Day);

                var newReplies =
                    this.Data.Reply.All()
                    .Count(
                        reply => reply.PublishTime.Month == dateTime.Month && reply.PublishTime.Day == dateTime.Day);

                var newPhotos =
                    this.Data.Photo.All()
                    .Count(photo => photo.DatePosted.Month == dateTime.Month && photo.DatePosted.Day == dateTime.Day);

                var userStatisticsViewModel = new UserStatisticsViewModel
                {
                    Date                = dateTime,
                    ActiveUserNumber    = activeUserNumber,
                    NewActivities       = newActivities,
                    NewPhotos           = newPhotos,
                    NewPosts            = newPosts,
                    NewReplies          = newReplies,
                    NewUserNumber       = newUserNumber,
                    UserIncreasingRatio = userIncreasingRatio
                };

                result.Add(userStatisticsViewModel);
            }

            return(View(result));
        }