From 691a031fa79fabb0a94c87b774d0ec381a9078c9 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Thu, 30 Dec 2021 08:57:38 +0330 Subject: [PATCH] #268 improvements on missing rhthms finder API --- RMuseum/Controllers/GanjoorController.cs | 5 +++-- RMuseum/RMuseum.xml | 9 ++++++--- RMuseum/Services/IGanjoorService.cs | 3 ++- .../GanjoorService-Maintenance.cs | 13 +++++++++++-- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs index 338a0b17..8122595a 100644 --- a/RMuseum/Controllers/GanjoorController.cs +++ b/RMuseum/Controllers/GanjoorController.cs @@ -529,17 +529,18 @@ namespace RMuseum.Controllers /// Start Finding Missing Rhythms /// /// + /// /// [HttpPost] [Route("startfindingmissingrhythms")] [Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + SecurableItem.ModifyOperationShortName)] [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(bool))] [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] - public IActionResult StartFindingMissingRhythms(bool onlyPoemsWithRhymes) + public IActionResult StartFindingMissingRhythms(bool onlyPoemsWithRhymes = true, int poemsNum = 1000) { RServiceResult res = - _ganjoorService.StartFindingMissingRhythms(onlyPoemsWithRhymes); + _ganjoorService.StartFindingMissingRhythms(onlyPoemsWithRhymes, poemsNum); if (!string.IsNullOrEmpty(res.ExceptionString)) return BadRequest(res.ExceptionString); return Ok(res.Result); diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 9f33cc10..bb72aa7f 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -850,11 +850,12 @@ - + Start Finding Missing Rhythms + @@ -9929,11 +9930,12 @@ - + Start finding missing rhthms + @@ -11347,11 +11349,12 @@ - + Start finding missing rhthms + diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs index e671275c..0b827d81 100644 --- a/RMuseum/Services/IGanjoorService.cs +++ b/RMuseum/Services/IGanjoorService.cs @@ -561,8 +561,9 @@ namespace RMuseum.Services /// Start finding missing rhthms /// /// + /// /// - RServiceResult StartFindingMissingRhythms(bool onlyPoemsWithRhymes); + RServiceResult StartFindingMissingRhythms(bool onlyPoemsWithRhymes, int poemsNum = 1000); /// /// find poem rhythm diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Maintenance.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Maintenance.cs index c6a0074d..f441feb2 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Maintenance.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Maintenance.cs @@ -100,8 +100,9 @@ namespace RMuseum.Services.Implementation /// Start finding missing rhthms /// /// + /// /// - public RServiceResult StartFindingMissingRhythms(bool onlyPoemsWithRhymes) + public RServiceResult StartFindingMissingRhythms(bool onlyPoemsWithRhymes, int poemsNum = 1000) { _backgroundTaskQueue.QueueBackgroundWorkItem ( @@ -113,7 +114,15 @@ namespace RMuseum.Services.Implementation var job = (await jobProgressServiceEF.NewJob($"StartFindingMissingRhythms", "Query data")).Result; try { - var poemIds = await context.GanjoorPoems.AsNoTracking().Where(p => p.GanjoorMetreId == null && (onlyPoemsWithRhymes == false || !string.IsNullOrEmpty(p.RhymeLetters))).Select(p => p.Id).ToArrayAsync(); + var poemIds = await context.GanjoorPoems.AsNoTracking() + .Where(p => + p.GanjoorMetreId == null && (onlyPoemsWithRhymes == false || !string.IsNullOrEmpty(p.RhymeLetters)) + && + false == (context.GanjoorVerses.Where(v => v.PoemId == p.Id && (v.VersePosition == VersePosition.Paragraph || v.VersePosition == VersePosition.Single)).Any() ) + ) + .Take(poemsNum) + .Select(p => p.Id) + .ToArrayAsync(); await jobProgressServiceEF.UpdateJob(job.Id, 0, $"Total: {poemIds.Length}"); var metres = (await GetGanjoorMetres()).Result.Select(m => m.Rhythm).ToArray();