Skip to content

Commit

Permalink
Merge pull request #1373 from Artsdatabanken/feature/speciesGroupsSta…
Browse files Browse the repository at this point in the history
…tistics

Feature/species groups statistics
  • Loading branch information
AneMarlene authored Jan 17, 2024
2 parents f98c310 + ebeaed6 commit 7ad8d1d
Show file tree
Hide file tree
Showing 28 changed files with 1,123 additions and 585 deletions.
21 changes: 8 additions & 13 deletions Assessments.Frontend.Web/Controllers/RedlistController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@ public RedlistController(ArtskartApiService artskartApiService)
public IActionResult RodlisteForArter() => View("Species/Rodlisteforarter");

private static readonly Dictionary<string, JObject> _resourceCache = new();
private static readonly Dictionary<string, string> _allAreas = Constants.AllAreas;
private static readonly Dictionary<string, string> _allCriterias = Constants.AllCriterias;
private static readonly Dictionary<string, string> _allEuropeanPopulationPercentages = Constants.AllEuropeanPopulationPercentages;
private readonly ArtskartApiService _artskartApiService;


[Route("2021")]
public async Task<IActionResult> Index2021([FromQueryAttribute] RL2021ViewModel viewModel, int? page, bool export)
{
Expand Down Expand Up @@ -73,8 +69,6 @@ public async Task<IActionResult> Index2021([FromQueryAttribute] RL2021ViewModel

var query = await DataRepository.GetSpeciesAssessments();

ViewBag.AllTaxonRanks = Helpers.GetAllTaxonRanks();

// Søk
if (!string.IsNullOrEmpty(viewModel.Name))
{
Expand All @@ -99,8 +93,6 @@ public async Task<IActionResult> Index2021([FromQueryAttribute] RL2021ViewModel
// Filter

// Areas
ViewBag.AllAreas = _allAreas;

if (viewModel.Area?.Any() == true)
query = query.Where(x => viewModel.Area.Contains(x.AssessmentArea));

Expand All @@ -111,14 +103,18 @@ public async Task<IActionResult> Index2021([FromQueryAttribute] RL2021ViewModel
query = query.Where(x => !string.IsNullOrEmpty(x.Category) && viewModel.Category.Any(y => x.Category.Contains(y)));

// Criterias
ViewBag.AllCriterias = _allCriterias;

if (viewModel.Criterias?.Any() == true)
query = query.Where(x => !string.IsNullOrEmpty(x.CriteriaSummarized) && viewModel.Criterias.Any(y => x.CriteriaSummarized.Contains(y)));

// Habitat
if (viewModel.Habitats?.Any() == true)
query = query.Where(x => viewModel.Habitats.Any(y => x.MainHabitat.Contains(y)));
{
// The model names are not compatible with enum naming rules. We need to consider this.
if (viewModel.Habitats.Contains("Fastmark"))
query = query.Where(x => viewModel.Habitats.Any(y => x.MainHabitat.Contains(y) || x.MainHabitat.Contains("Semi-naturlig fastmark")));
else
query = query.Where(x => viewModel.Habitats.Any(y => x.MainHabitat.Contains(y)));
}

// Regions
ViewBag.AllRegions = Helpers.GetRegionsDict();
Expand All @@ -144,7 +140,6 @@ public async Task<IActionResult> Index2021([FromQueryAttribute] RL2021ViewModel
query = query.Where(x => viewModel.TaxonRank.Contains(x.TaxonRank));

// European population percentages
ViewBag.AllEuroPop = _allEuropeanPopulationPercentages;
string[] chosenEuropeanPopulation = Helpers.FindEuropeanPopProcentages(viewModel.EuroPop);

if (chosenEuropeanPopulation?.Any() == true)
Expand Down Expand Up @@ -454,4 +449,4 @@ private static async Task<JObject> GetResource(string resourcePath)
return jObject;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Assessments.Frontend.Web.Models;
using System;
using System.Linq;
using Assessments.Frontend.Web.Infrastructure;
using static Assessments.Frontend.Web.Infrastructure.FilterHelpers;

namespace Assessments.Frontend.Web.Infrastructure.AlienSpecies
{
public class FilterHelpers : IFilter<AlienSpeciesListParameters>
public class AlienSpeciesFilterHelpers : IFilter<AlienSpeciesListParameters>
{
public string IGetActiveFilters(string filterType, AlienSpeciesListParameters parameters)
{
Expand All @@ -26,7 +28,7 @@ public string[] IGetActiveSelectionElement(AlienSpeciesListParameters parameters
return GetActiveSelectionElement(parameters);
}

public string IGetChipText(string filter, Filter.FilterItem[] filterItems)
public string IGetChipText(string filter, FilterItem[] filterItems)
{
return GetChipText(filter, filterItems);
}
Expand Down Expand Up @@ -230,11 +232,11 @@ public static string[] GetActiveSelectionElement(AlienSpeciesListParameters para
return selectionlist;
}

public static string GetChipText(string filter, Filter.FilterItem[] filterItems)
public static string GetChipText(string filter, FilterItem[] filterItems)
{
for (int i = 0; i < filterItems.Length; i++)
{
Filter.FilterItem item = filterItems[i];
FilterItem item = filterItems[i];
if (item.NameShort == filter)
{
return item.Name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using static Assessments.Frontend.Web.Infrastructure.FilterHelpers;

namespace Assessments.Frontend.Web.Infrastructure.AlienSpecies
{
public class AlienSpeciesHelpers
{
public static Filter.FilterItem GetSpeciesGroup(Filter.FilterItem[] speciesGroups, string speciesGroupName)
public static FilterItem GetSpeciesGroup(FilterItem[] speciesGroups, string speciesGroupName)
{
foreach (var speciesGroup in speciesGroups)
{
Expand Down Expand Up @@ -38,7 +39,7 @@ public static string GetSpeciesGroupByShortName(string shortName)

foreach (var species in speciesGroups)
{
Filter.FilterItem speciesGroup = species;
FilterItem speciesGroup = species;
if (speciesGroup.NameShort == shortName)
{
return speciesGroup.Name;
Expand Down
Loading

0 comments on commit 7ad8d1d

Please sign in to comment.