From 75a3b4c2fc58807c1a094b8e3619b1680845b9f4 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Fri, 29 Apr 2022 14:35:40 +0430 Subject: [PATCH] docs: #308 fix for counting languages couplets --- .../GanjoorService-Stats.cs | 38 +++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Stats.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Stats.cs index 3d062739..ee297cc9 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Stats.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Stats.cs @@ -145,16 +145,28 @@ namespace RMuseum.Services.Implementation .GroupBy(v => new { v.Poem.Language }) .Select(g => new LanguageCoupletCount() { Language = g.Key.Language, Count = g.Count() }) .ToListAsync(); + var fa = langaugesCoupletsCountsUnprocessed.Where(l => l.Language == "fa-IR").SingleOrDefault(); + if(fa == null) + { + fa = new LanguageCoupletCount() + { + Language = "fa-IR", + Count = 0 + }; + langaugesCoupletsCountsUnprocessed.Add + ( + fa + ); + } foreach (var langaugesCoupletsCount in langaugesCoupletsCountsUnprocessed) { if (string.IsNullOrEmpty(langaugesCoupletsCount.Language)) { - langaugesCoupletsCount.Language = "fa-IR"; + fa.Count += langaugesCoupletsCount.Count; } } var langaugesCoupletsCounts = langaugesCoupletsCountsUnprocessed - .GroupBy(l => l.Language) - .Select(g => new { Language = g.Key, Count = g.Count() }) + .Where(l => !string.IsNullOrEmpty(l.Language) ) .ToList(); langaugesCoupletsCounts.Sort((a, b) => b.Count - a.Count); @@ -280,16 +292,28 @@ namespace RMuseum.Services.Implementation .GroupBy(v => new { v.Poem.Language }) .Select(g => new LanguageCoupletCount() { Language = g.Key.Language, Count = g.Count() }) .ToListAsync(); + var fa = langaugesCoupletsCountsUnprocessed.Where(l => l.Language == "fa-IR").SingleOrDefault(); + if (fa == null) + { + fa = new LanguageCoupletCount() + { + Language = "fa-IR", + Count = 0 + }; + langaugesCoupletsCountsUnprocessed.Add + ( + fa + ); + } foreach (var langaugesCoupletsCount in langaugesCoupletsCountsUnprocessed) { - if(string.IsNullOrEmpty(langaugesCoupletsCount.Language)) + if (string.IsNullOrEmpty(langaugesCoupletsCount.Language)) { - langaugesCoupletsCount.Language = "fa-IR"; + fa.Count += langaugesCoupletsCount.Count; } } var langaugesCoupletsCounts = langaugesCoupletsCountsUnprocessed - .GroupBy(l => l.Language) - .Select(g => new { Language = g.Key, Count = g.Count() }) + .Where(l => !string.IsNullOrEmpty(l.Language)) .ToList(); langaugesCoupletsCounts.Sort((a, b) => b.Count - a.Count);