diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Mundex.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Mundex.cs index 0fb34220..f220a598 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Mundex.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Mundex.cs @@ -1,7 +1,6 @@ using DNTPersianUtils.Core; using Microsoft.EntityFrameworkCore; using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using RMuseum.DbContext; using RMuseum.Models.Ganjoor; using RSecurityBackend.Models.Generic; @@ -98,6 +97,75 @@ namespace RMuseum.Services.Implementation await _UpdatePageHtmlText(context, editingUserId, dbPage, "به روزرسانی خودکار صفحهٔ نمایهٔ موسیقی", htmlText); } + private async Task _UpdateMundexByPoetPage(Guid editingUserId, RMuseumDbContext context, LongRunningJobProgressServiceEF jobProgressServiceEF, RLongRunningJobStatus job) + { + var poemMusicTracks = + await context.GanjoorPoemMusicTracks.Include(m => m.Poem).ThenInclude(p => p.Cat) + .Where(m => + m.Approved) + .ToListAsync(); + + var dbPage = await context.GanjoorPages.Where(p => p.FullUrl == "/mundex/bypoet").SingleAsync(); + + + string htmlText = $"

در این صفحه فهرست اشعار استفاده شده در آلبومهای موسیقی را با استفاده از اطلاعات جمع‌آوری شده در این پروژه به تفکیک شاعر و به ترتیب نزولی تعداد اشعار مرتبط گرد آورده‌ایم." + + $" تا تاریخ {LanguageUtils.FormatDate(DateTime.Now)} ارتباط {poemMusicTracks.GroupBy(m => m.PoemId).Count().ToPersianNumbers()} شعر از {poemMusicTracks.GroupBy(m => m.Poem.Cat.PoetId).Count().ToPersianNumbers()} شاعر با {poemMusicTracks.Count.ToPersianNumbers()} قطعهٔ موسیقی در پایگاه گنجور ثبت و تأیید شده است.

{Environment.NewLine}"; + htmlText += $"

جهت مشاهدهٔ این اطلاعات به تفکیک هنرمندان (بدون اطلاعات مجموعهٔ گلها، سایت اسپاتیفای و اجراهای خصوصی) این صفحه را ببینید.

{Environment.NewLine}"; + htmlText += $"

جهت کمک به تکمیل این مجموعه این مطلب را مطالعه بفرمایید و این فیلم را مشاهده کنید.

{Environment.NewLine}"; + + var poetIdsAndTrackCounts = poemMusicTracks.GroupBy(m => new { m.Poem.Cat.PoetId }) + .Select(g => new { PoetId = g.Key.PoetId, TrackCount = g.Count() }) + .OrderByDescending(g => g.TrackCount) + .ToList(); + using (HttpClient httpClient = new HttpClient()) + for (int nPoetIndex = 0; nPoetIndex < poetIdsAndTrackCounts.Count; nPoetIndex++) + { + var poetIdAndTrackCount = poetIdsAndTrackCounts[nPoetIndex]; + + var tracks = poemMusicTracks. + Where(m => m.Poem.Cat.PoetId == poetIdAndTrackCount.PoetId) + .OrderBy(m => m.PoemId) + .ToList(); + if (tracks.Count != poetIdAndTrackCount.TrackCount) + continue;//!!! a weird situration I cannot figure out now! + var poet = await context.GanjoorPoets.Where(p => p.Id == poetIdAndTrackCount.PoetId).AsNoTracking().SingleAsync(); + var poetCat = await context.GanjoorCategories.Where(c => c.PoetId == poetIdAndTrackCount.PoetId && c.ParentId == null).AsNoTracking().SingleAsync(); + + htmlText += $"


{Environment.NewLine}"; + htmlText += $"

{nPoetIndex+1}. {poet.Nickname}

{Environment.NewLine}"; + htmlText += $"
 
{Environment.NewLine}"; + htmlText += $"
\"{poet.Nickname}\"
{Environment.NewLine}"; + htmlText += $"
{poet.Nickname} ({tracks.Count.ToPersianNumbers()} قطعه)
{Environment.NewLine}" + + $"
 
{Environment.NewLine}"; + + htmlText += $"
    {Environment.NewLine}"; + + foreach (var song in tracks) + { + htmlText += $"
  1. {Environment.NewLine}"; + var poem = await context.GanjoorPoems.AsNoTracking().Where(p => p.Id == song.PoemId).SingleAsync(); + htmlText += $"{poem.FullTitle} در "; + + if(song.TrackType == PoemMusicTrackType.Golha) + { + htmlText += "گلها » "; + } + else + { + htmlText += $"{song.ArtistName} » "; + } + + htmlText += $"{song.AlbumName.ToPersianNumbers()} » {song.TrackName.ToPersianNumbers()}

  2. {Environment.NewLine}"; + } + + htmlText += $"
{Environment.NewLine}"; + } + + + await _UpdatePageHtmlText(context, editingUserId, dbPage, "به روزرسانی خودکار صفحهٔ شاعران به روایت آهنگها", htmlText); + } + + /// /// start updating stats page /// @@ -119,9 +187,8 @@ namespace RMuseum.Services.Implementation { await _UpdateMundexPage(editingUserId, context, jobProgressServiceEF, job); - await jobProgressServiceEF.UpdateJob(job.Id, 50, "Mundex by poet page"); - + await _UpdateMundexByPoetPage(editingUserId, context, jobProgressServiceEF, job); await jobProgressServiceEF.UpdateJob(job.Id, 100, "", true); }