private void SetPercentage(Localization model, TranslationStatsViewModel vm)
        {
            int totalTermCount       = model.Terms.Count;
            int distinctEntriesCount = model.Entries.Select(x => new { x.TermId, x.Language }).Distinct().Count();
            int languageCount        = model.Entries.Select(x => x.Language).Distinct().Count();

            vm.TranslationPercentage = translationDomainService.CalculatePercentage(totalTermCount, distinctEntriesCount, languageCount);
        }
        private void SetContributors(Localization model, TranslationStatsViewModel vm)
        {
            IEnumerable <IGrouping <Guid, LocalizationEntry> > contributors = model.Entries.GroupBy(x => x.UserId);

            foreach (IGrouping <Guid, LocalizationEntry> contributorGroup in contributors)
            {
                ContributorViewModel contributor = new ContributorViewModel();
                UserProfile          profile     = GetCachedProfileByUserId(contributorGroup.Key);
                contributor.UserId        = contributorGroup.Key;
                contributor.AuthorName    = profile.Name;
                contributor.AuthorPicture = UrlFormatter.ProfileImage(contributorGroup.Key);
                contributor.EntryCount    = contributorGroup.Count();
                vm.Contributors.Add(contributor);
            }

            vm.Contributors = vm.Contributors.OrderByDescending(x => x.EntryCount).ToList();
        }
        public OperationResultVo GetStatsById(Guid currentUserId, Guid id)
        {
            try
            {
                Localization model = translationDomainService.GetById(id);

                if (model == null)
                {
                    return(new OperationResultVo("Translation Project not found!"));
                }

                TranslationStatsViewModel vm = mapper.Map <TranslationStatsViewModel>(model);

                vm.TermCount = model.Terms.Count;

                IEnumerable <IGrouping <SupportedLanguage, LocalizationEntry> > languages = model.Entries.GroupBy(x => x.Language);

                foreach (IGrouping <SupportedLanguage, LocalizationEntry> language in languages)
                {
                    TranslationStatsLanguageViewModel languageEntry = new TranslationStatsLanguageViewModel
                    {
                        Language   = language.Key,
                        EntryCount = language.Select(x => x.TermId).Distinct().Count(),
                        Percentage = translationDomainService.CalculatePercentage(vm.TermCount, language.Count(), 1)
                    };

                    vm.Languages.Add(languageEntry);
                }

                SetPercentage(model, vm);

                SetContributors(model, vm);

                SetGameViewModel(model.GameId, vm);

                SetPermissions(currentUserId, vm);

                return(new OperationResultVo <TranslationStatsViewModel>(vm));
            }
            catch (Exception ex)
            {
                return(new OperationResultVo(ex.Message));
            }
        }
Ejemplo n.º 4
0
        public IActionResult Export(Guid id)
        {
            OperationResultVo result = translationAppService.GetStatsById(CurrentUserId, id);

            if (result.Success)
            {
                OperationResultVo <TranslationStatsViewModel> castRestult = result as OperationResultVo <TranslationStatsViewModel>;

                TranslationStatsViewModel model = castRestult.Value;

                SetLocalization(model);
                SetAuthorDetails(model);

                return(View("Export", model));
            }
            else
            {
                return(null);
            }
        }