diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Maintenance.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Maintenance.cs index 9b913241..4f947e23 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Maintenance.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Maintenance.cs @@ -746,11 +746,13 @@ namespace RMuseum.Services.Implementation v => v.PoemId == section.PoemId && ( - v.SectionIndex1 == section.Index || - v.SectionIndex2 == section.Index || - v.SectionIndex3 == section.Index || - v.SectionIndex4 == section.Index - ) + (section.VerseType == VersePoemSectionType.First && v.SectionIndex1 == section.Index) + || + (section.VerseType == VersePoemSectionType.Second && v.SectionIndex2 == section.Index) + || + (section.VerseType == VersePoemSectionType.Third && v.SectionIndex3 == section.Index) + || + (section.VerseType == VersePoemSectionType.Forth && v.SectionIndex4 == section.Index)) && (v.VersePosition == VersePosition.Left || v.VersePosition == VersePosition.CenteredVerse1) ).CountAsync(); diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Stats.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Stats.cs index fed8ccc5..77e8eb2b 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Stats.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Stats.cs @@ -33,6 +33,13 @@ namespace RMuseum.Services.Implementation public int Count { get; set; } } + internal class SectionCoupletCount + { + public int CoupletCount { get; set; } + + public int Count { get; set; } + } + /// /// IGanjoorService implementation /// @@ -71,11 +78,12 @@ namespace RMuseum.Services.Implementation var wholePoemSections = await context.GanjoorPoemSections.Include(v => v.Poem).ThenInclude(p => p.Cat).ThenInclude(c => c.Poet).AsNoTracking() .Where(s => s.PoetId == poet.Id && (string.IsNullOrEmpty(s.Language) || s.Language == "fa-IR") && s.Poem.Cat.Poet.Published && s.SectionType == PoemSectionType.WholePoem) - .Select(s => new { s.PoemId, s.Index, s.GanjoorMetreId, Versetype = s.VerseType }) + .Select(s => new { s.PoemId, s.Index, s.GanjoorMetreId, s.VerseType }) .ToListAsync(); Dictionary metreCounts = new Dictionary(); int secondMetreCoupletCount = 0; + Dictionary coupletCounts = new Dictionary(); foreach (var section in wholePoemSections) { int coupletCount = await context.GanjoorVerses.AsNoTracking() @@ -85,15 +93,26 @@ namespace RMuseum.Services.Implementation (v.VersePosition == VersePosition.Right || v.VersePosition == VersePosition.CenteredVerse1) && ( - (section.Versetype == VersePoemSectionType.First && v.SectionIndex1 == section.Index) + (section.VerseType == VersePoemSectionType.First && v.SectionIndex1 == section.Index) || - (section.Versetype == VersePoemSectionType.Second && v.SectionIndex2 == section.Index) + (section.VerseType == VersePoemSectionType.Second && v.SectionIndex2 == section.Index) || - (section.Versetype == VersePoemSectionType.Third && v.SectionIndex3 == section.Index) + (section.VerseType == VersePoemSectionType.Third && v.SectionIndex3 == section.Index) || - (section.Versetype == VersePoemSectionType.Forth && v.SectionIndex4 == section.Index) + (section.VerseType == VersePoemSectionType.Forth && v.SectionIndex4 == section.Index) ) - ).CountAsync(); + ).CountAsync();//GanjoorPoemSection.CoupletsCount added later + + if (coupletCounts.TryGetValue(coupletCount, out int groupedCoupletCount)) + { + groupedCoupletCount++; + } + else + { + groupedCoupletCount = 1; + } + coupletCounts[coupletCount] = groupedCoupletCount; + var metreId = section.GanjoorMetreId == null ? 0 : (int)section.GanjoorMetreId; if (metreCounts.TryGetValue(metreId, out int sectionCoupletCount)) { @@ -104,7 +123,7 @@ namespace RMuseum.Services.Implementation sectionCoupletCount = coupletCount; } metreCounts[metreId] = sectionCoupletCount; - if (metreId != 0 && section.Versetype != VersePoemSectionType.First) + if (metreId != 0 && section.VerseType != VersePoemSectionType.First) { secondMetreCoupletCount += coupletCount; } @@ -306,6 +325,44 @@ namespace RMuseum.Services.Implementation htmlText += $"{Environment.NewLine}"; + List coupletCountsList = new List(); + foreach (var coupletCount in coupletCounts) + { + coupletCountsList.Add(new SectionCoupletCount() { CoupletCount = coupletCount.Key, Count = coupletCount.Value }); + } + coupletCountsList.Sort((a, b) => b.Count - a.Count); + if(coupletCountsList.Count > 0 ) + { + htmlText += $"

آمار فراوانی تعداد ابیات اشعار {poet.Nickname} به شرح زیر است (این آمار برای مثنوی‌ها که بخش‌بندی آنها ممکن است به سلیقهٔ گردآورنده صورت گرفته باشد):

{Environment.NewLine}"; + + htmlText += $"{Environment.NewLine}" + + $"{Environment.NewLine}" + + $"{Environment.NewLine}" + + $"{Environment.NewLine}" + + $"{Environment.NewLine}" + + $"{Environment.NewLine}" + + $"{Environment.NewLine}"; + + for (int i = 0; i < coupletCountsList.Count; i++) + { + if (coupletCountsList[i].Count == 0) continue; + if (i % 2 == 0) + htmlText += $"{Environment.NewLine}"; + else + htmlText += $"{Environment.NewLine}"; + + htmlText += $"{Environment.NewLine}"; + htmlText += $"{Environment.NewLine}"; + htmlText += $"{Environment.NewLine}"; + htmlText += $"{Environment.NewLine}"; + + htmlText += $"{Environment.NewLine}"; + } + htmlText += $"
ردیفتعداد ابیات شعرفراوانیدرصد از کل
{(i + 1).ToPersianNumbers()}{coupletCountsList[i].CoupletCount.ToPersianNumbers()}{LanguageUtils.FormatMoney(coupletCountsList[i].Count)}{(coupletCountsList[i].Count * 100.0 / wholeCoupletsCount).ToString("N2", new CultureInfo("fa-IR")).ToPersianNumbers()}
{Environment.NewLine}"; + } + + + await _UpdatePageHtmlText(context, editingUserId, dbPage, "به روزرسانی خودکار صفحهٔ آمار وزنها", htmlText);