Skip to content

Commit

Permalink
fix count in pathway-category-figure. Closes #1403
Browse files Browse the repository at this point in the history
  • Loading branch information
AneMarlene committed Jun 16, 2024
1 parent c0a37de commit a3d5e94
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,20 @@ private List<BarChart> GetSpreadWaysIntroduction()

var barCharts = new List<BarChart>();

var uniqueIntroductionPathwaysPerSpecies = new List<string>();

var introductionPathwaysSpecies = _query.Select(y => new
{
introductionAndSpreadPathways = y.IntroductionAndSpreadPathways.Where(z => z.IntroductionSpread == AlienSpeciesAssessment2023IntroductionPathway.IntroductionSpread.Introduction).Select(z => z.Category).ToArray(),
id = y.Id
}).ToList();

foreach (var id in introductionPathwaysSpecies)
{
var uniquePathways = id.introductionAndSpreadPathways.Distinct().ToList();
uniqueIntroductionPathwaysPerSpecies.AddRange( uniquePathways );
};

foreach (var spreadWay in allMainSpreadWays)
{
var barChart = new BarChart()
Expand All @@ -292,7 +306,7 @@ private List<BarChart> GetSpreadWaysIntroduction()
Data = _unfilteredQuery.SelectMany(x => x.IntroductionAndSpreadPathways.Where(y => y.IntroductionSpread == AlienSpeciesAssessment2023IntroductionPathway.IntroductionSpread.Introduction && y.MainCategory == spreadWay)).DistinctBy(x => x.Category).Select(x => new BarChart.BarChartData()
{
Name = x.Category,
Count = _query.SelectMany(y => y.IntroductionAndSpreadPathways.DistinctBy(z => z.Category)).Where(z => z.Category == x.Category && z.IntroductionSpread == AlienSpeciesAssessment2023IntroductionPathway.IntroductionSpread.Introduction).Count()
Count = uniqueIntroductionPathwaysPerSpecies.Where(item => x.Category.Equals(item)).Count()
}).OrderBy(x => x.Name).ToList()
};
barCharts.Add(barChart);
Expand Down

0 comments on commit a3d5e94

Please sign in to comment.