diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Stats.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Stats.cs index a2a15a7b..6bf77263 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Stats.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Stats.cs @@ -583,6 +583,71 @@ namespace RMuseum.Services.Implementation } htmlText += $"{Environment.NewLine}"; + + + //آمار شعرهای زیربخشها + string subCatsHtmlText = ""; + var subCats = await context.GanjoorCategories.AsNoTracking().Where(c => c.ParentId == catId).ToListAsync(); + subCats.Add(await context.GanjoorCategories.AsNoTracking().Where(c => c.Id == catId).SingleAsync()); + int subCatIndex = 0; + foreach (var subCat in subCats) + { + List subcatIdList = [subCat.Id]; + if(subCat.Id != catId) + { + await _populateCategoryChildren(context, subCat.Id, subcatIdList); + } + else + { + subCat.Title = "بخش‌بندی نشده"; + } + + var subCatCoupletCounts = + await context.GanjoorVerses.Include(v => v.Poem).ThenInclude(p => p.Cat).ThenInclude(c => c.Poet).AsNoTracking() + .Where(v => + v.Poem.Cat.Poet.Published + && + (v.VersePosition == VersePosition.Right || v.VersePosition == VersePosition.CenteredVerse1) + && + subcatIdList.Contains(v.Poem.CatId) + ) + .GroupBy(v => new { v.Poem.Cat.PoetId }) + .Select(g => new { g.Key.PoetId, Count = g.Count() }) + .ToListAsync(); + if (subCatCoupletCounts.Count != 1) + continue; + int subCatWholeCoupletsCount = subCatCoupletCounts[0].Count; + if (subCatWholeCoupletsCount == 0) continue; + if (subCatIndex % 2 == 0) + subCatsHtmlText += $"{Environment.NewLine}"; + else + subCatsHtmlText += $"{Environment.NewLine}"; + + subCatsHtmlText += $"{(subCatIndex + 1).ToPersianNumbers()}{Environment.NewLine}"; + subCatsHtmlText += $"{subCat.Title}{Environment.NewLine}"; + subCatsHtmlText += $"{LanguageUtils.FormatMoney(subCatWholeCoupletsCount)}{Environment.NewLine}"; + subCatsHtmlText += $"{(subCatWholeCoupletsCount * 100.0 / wholeCoupletsCount).ToString("N2", new CultureInfo("fa-IR")).ToPersianNumbers()}{Environment.NewLine}"; + + subCatsHtmlText += $"{Environment.NewLine}"; + subCatIndex++; + } + + if (!string.IsNullOrEmpty(subCatsHtmlText)) + { + htmlText += $"

آمار ابیات به تفکیک زیربخش‌های این قسمت به شرح زیر است (بخش‌هایی که در این جدول نیامده‌اند فاقد شعر بوده‌اند):

{Environment.NewLine}"; + htmlText += $"{Environment.NewLine}" + + $"{Environment.NewLine}" + + $"{Environment.NewLine}" + + $"{Environment.NewLine}" + + $"{Environment.NewLine}" + + $"{Environment.NewLine}" + + $"{Environment.NewLine}"; + htmlText += subCatsHtmlText; + htmlText += $"
ردیفبخشتعداد ابیاتدرصد از کل
{Environment.NewLine}"; + } + + + htmlText += $"{Environment.NewLine}";