stats of subcategoris in a category stats

#461
This commit is contained in:
Hamid Reza Mohammadi 2025-01-13 19:42:57 +03:30
parent 02af962acb
commit b36939f5c4
2 changed files with 32 additions and 9 deletions

View File

@ -1695,7 +1695,7 @@
<param name="term"></param>
<param name="poetId"></param>
<param name="catId"></param>
<param name="exceptPoetId"></param>
<param name="e"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.GanjoorController.GetGanjoorMetres(System.Boolean)">

View File

@ -586,21 +586,24 @@ namespace RMuseum.Services.Implementation
//آمار شعرهای زیربخشها
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;
string subCatsHtmlText = "";
bool skippedSomeCats = false;
foreach (var subCat in subCats)
{
if(subCat.Id == catId && subCatsHtmlText == "")
{
break;
}
List<int> 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()
@ -615,16 +618,31 @@ namespace RMuseum.Services.Implementation
.Select(g => new { g.Key.PoetId, Count = g.Count() })
.ToListAsync();
if (subCatCoupletCounts.Count != 1)
{
skippedSomeCats = true;
continue;
}
int subCatWholeCoupletsCount = subCatCoupletCounts[0].Count;
if (subCatWholeCoupletsCount == 0) continue;
if (subCatWholeCoupletsCount == 0)
{
skippedSomeCats = true;
continue;
}
if (subCatIndex % 2 == 0)
subCatsHtmlText += $"<tr class=\"e\">{Environment.NewLine}";
else
subCatsHtmlText += $"<tr>{Environment.NewLine}";
subCatsHtmlText += $"<td class=\"c1\">{(subCatIndex + 1).ToPersianNumbers()}</td>{Environment.NewLine}";
subCatsHtmlText += $"<td class=\"c2\"><a href=\"{subCat.FullUrl}\">{subCat.Title}</a></td>{Environment.NewLine}";
if(subCat.Id == catId)
{
subCatsHtmlText += $"<td class=\"c2\">بخش‌بندی نشده</td>{Environment.NewLine}";
}
else
{
subCatsHtmlText += $"<td class=\"c2\"><a href=\"{subCat.FullUrl}\">{subCat.Title}</a></td>{Environment.NewLine}";
}
subCatsHtmlText += $"<td class=\"c3\">{LanguageUtils.FormatMoney(subCatWholeCoupletsCount)}</td>{Environment.NewLine}";
subCatsHtmlText += $"<td class=\"c4\">{(subCatWholeCoupletsCount * 100.0 / wholeCoupletsCount).ToString("N2", new CultureInfo("fa-IR")).ToPersianNumbers()}</td>{Environment.NewLine}";
@ -634,7 +652,12 @@ namespace RMuseum.Services.Implementation
if (!string.IsNullOrEmpty(subCatsHtmlText))
{
htmlText += $"<p>آمار ابیات به تفکیک زیربخش‌های این قسمت به شرح زیر است (بخش‌هایی که در این جدول نیامده‌اند فاقد شعر بوده‌اند):</p>{Environment.NewLine}";
htmlText += $"<p>آمار ابیات به تفکیک زیربخش‌های این قسمت به شرح زیر است";
if(skippedSomeCats)
{
htmlText += " (بخش‌هایی که در این جدول نیامده‌اند فاقد شعر بوده‌اند)";
}
htmlText += $":</p>{Environment.NewLine}";
htmlText += $"<table>{Environment.NewLine}" +
$"<tr class=\"h\">{Environment.NewLine}" +
$"<td class=\"c1\">ردیف</td>{Environment.NewLine}" +