From 04d2c5e9dc6d045076d97967b3095f9c706f8aa2 Mon Sep 17 00:00:00 2001 From: Eirik Date: Mon, 6 Jan 2025 11:37:36 +0100 Subject: [PATCH 1/3] Fix yearfirstrecord #1430 --- .../Infrastructure/DataRepository.cs | 12 ++++++++---- .../2023/AssessmentPartials/_KnowMore.cshtml | 6 +++--- .../appsettings.Development.json | 2 +- .../AlienSpeciesAssessment2023ProfileHelper.cs | 13 +++++++++---- .../AlienSpeciesAssessment2023YearFirstRecord.cs | 10 +++++++++- 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/Assessments.Frontend.Web/Infrastructure/DataRepository.cs b/Assessments.Frontend.Web/Infrastructure/DataRepository.cs index 6e84c2174..0f9c00bfb 100644 --- a/Assessments.Frontend.Web/Infrastructure/DataRepository.cs +++ b/Assessments.Frontend.Web/Infrastructure/DataRepository.cs @@ -84,6 +84,10 @@ async Task> DeserializeData() public Task> GetSpeciesAssessments() { + var speciesAssessments = _appCache.GetOrAddAsync(nameof(GetSpeciesAssessments), Get); + + return speciesAssessments; + async Task> Get() { return _options.Value.Species2021.TransformAssessments @@ -93,12 +97,14 @@ async Task> Get() // returnerer modell som allerede er transformert await GetData(DataFilenames.Species2021); } - - return _appCache.GetOrAddAsync($"{nameof(GetSpeciesAssessments)}", Get); } public Task> GetAlienSpeciesAssessments() { + var alienSpeciesAssessments = _appCache.GetOrAddAsync(nameof(GetAlienSpeciesAssessments), Get); + + return alienSpeciesAssessments; + async Task> Get() { return _options.Value.AlienSpecies2023.TransformAssessments @@ -108,8 +114,6 @@ async Task> Get() // returnerer modell som allerede er transformert await GetData(DataFilenames.AlienSpecies2023); } - - return _appCache.GetOrAddAsync($"{nameof(GetSpeciesAssessments)}", Get); } } } \ No newline at end of file diff --git a/Assessments.Frontend.Web/Views/AlienSpecies/2023/AssessmentPartials/_KnowMore.cshtml b/Assessments.Frontend.Web/Views/AlienSpecies/2023/AssessmentPartials/_KnowMore.cshtml index d23727e69..55e56d1f0 100644 --- a/Assessments.Frontend.Web/Views/AlienSpecies/2023/AssessmentPartials/_KnowMore.cshtml +++ b/Assessments.Frontend.Web/Views/AlienSpecies/2023/AssessmentPartials/_KnowMore.cshtml @@ -97,9 +97,9 @@ @foreach(var record in Model.Assessment.YearsFirstRecord.ObservedEstablishmentInNorway) { - @record.recordType.DisplayName().ToLowerInvariant() - @Constants.AlienSpeciesTables.FirstObsTableColumn2:@record.year - @Html.Raw(@Constants.AlienSpeciesTables.FirstObsTableColumn3):@( record.isUncertaintyYear ? "ja" : "nei" ) + @record.Item1.DisplayName().ToLowerInvariant() + @Constants.AlienSpeciesTables.FirstObsTableColumn2:@record.Item2 + @Html.Raw(@Constants.AlienSpeciesTables.FirstObsTableColumn3):@( record.Item3 ? "ja" : "nei" ) } diff --git a/Assessments.Frontend.Web/appsettings.Development.json b/Assessments.Frontend.Web/appsettings.Development.json index 127e01e2d..a6faa6101 100644 --- a/Assessments.Frontend.Web/appsettings.Development.json +++ b/Assessments.Frontend.Web/appsettings.Development.json @@ -14,7 +14,7 @@ "TransformAssessments": false }, "Species2021": { - "TransformAssessments": true + "TransformAssessments": false } } } diff --git a/Assessments.Mapping/AlienSpecies/Helpers/AlienSpeciesAssessment2023ProfileHelper.cs b/Assessments.Mapping/AlienSpecies/Helpers/AlienSpeciesAssessment2023ProfileHelper.cs index bc9fa8650..fd50d9e50 100644 --- a/Assessments.Mapping/AlienSpecies/Helpers/AlienSpeciesAssessment2023ProfileHelper.cs +++ b/Assessments.Mapping/AlienSpecies/Helpers/AlienSpeciesAssessment2023ProfileHelper.cs @@ -804,16 +804,16 @@ internal static string GetMedianLifetimeEstimationMethod(string category, string } - internal static List<(AlienSpeciesAssessment2023YearFirstRecordType, int, bool)> GetYearsFirstObserved(RiskAssessment riskAssessment, string establishmentCategory) + internal static List GetYearsFirstObserved(RiskAssessment riskAssessment, string establishmentCategory) { if (establishmentCategory is "A") //species not yet in Norway cannot have observations in Norway { - return new List<(AlienSpeciesAssessment2023YearFirstRecordType, int, bool)>(); + return new List(); } else { - var yearEstablishmentType = new List<(AlienSpeciesAssessment2023YearFirstRecordType, int, bool)>(); + var yearEstablishmentType = new List(); foreach (var firstObservationProperty in riskAssessmentPropertiesFirstObservations) { @@ -834,7 +834,12 @@ internal static string GetMedianLifetimeEstimationMethod(string category, string }; var firstObservationUncertaintyProperty = riskAssessmentProperties.Where(x => x.Name == firstObservationProperty.Name + "Insecure").Single(); bool isUncertaintyYearValue = (bool)firstObservationUncertaintyProperty.GetValue(riskAssessment); - yearEstablishmentType.Add((establishmentTypeName, (int)yearFirstValue, isUncertaintyYearValue)); + yearEstablishmentType.Add(new AlienSpeciesAssessment2023YearFirstRecordItem() + { + Item1 = establishmentTypeName, + Item2 = (int)yearFirstValue, + Item3 = isUncertaintyYearValue + }); } } diff --git a/Assessments.Mapping/AlienSpecies/Model/AlienSpeciesAssessment2023YearFirstRecord.cs b/Assessments.Mapping/AlienSpecies/Model/AlienSpeciesAssessment2023YearFirstRecord.cs index f45d89154..3525f208a 100644 --- a/Assessments.Mapping/AlienSpecies/Model/AlienSpeciesAssessment2023YearFirstRecord.cs +++ b/Assessments.Mapping/AlienSpecies/Model/AlienSpeciesAssessment2023YearFirstRecord.cs @@ -5,9 +5,17 @@ namespace Assessments.Mapping.AlienSpecies.Model { public class AlienSpeciesAssessment2023YearFirstRecord { - public List<(AlienSpeciesAssessment2023YearFirstRecordType recordType, int year, bool isUncertaintyYear)> ObservedEstablishmentInNorway { get; set; } = new(); + public List ObservedEstablishmentInNorway { get; set; } = new(); public string Description { get; set; } + } + + public class AlienSpeciesAssessment2023YearFirstRecordItem + { + public AlienSpeciesAssessment2023YearFirstRecordType Item1 { get; set; } + + public int Item2 { get; set; } + public bool Item3 { get; set; } } } \ No newline at end of file From 9054ab5412d4626a7428f2bae2a0b11c42c956ca Mon Sep 17 00:00:00 2001 From: Eirik Date: Tue, 7 Jan 2025 10:44:42 +0100 Subject: [PATCH 2/3] Adjust names --- .../AlienSpecies/2023/AssessmentPartials/_KnowMore.cshtml | 6 +++--- .../Helpers/AlienSpeciesAssessment2023ProfileHelper.cs | 6 +++--- .../Model/AlienSpeciesAssessment2023YearFirstRecord.cs | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Assessments.Frontend.Web/Views/AlienSpecies/2023/AssessmentPartials/_KnowMore.cshtml b/Assessments.Frontend.Web/Views/AlienSpecies/2023/AssessmentPartials/_KnowMore.cshtml index 55e56d1f0..7c90920a0 100644 --- a/Assessments.Frontend.Web/Views/AlienSpecies/2023/AssessmentPartials/_KnowMore.cshtml +++ b/Assessments.Frontend.Web/Views/AlienSpecies/2023/AssessmentPartials/_KnowMore.cshtml @@ -97,9 +97,9 @@ @foreach(var record in Model.Assessment.YearsFirstRecord.ObservedEstablishmentInNorway) { - @record.Item1.DisplayName().ToLowerInvariant() - @Constants.AlienSpeciesTables.FirstObsTableColumn2:@record.Item2 - @Html.Raw(@Constants.AlienSpeciesTables.FirstObsTableColumn3):@( record.Item3 ? "ja" : "nei" ) + @record.RecordType.DisplayName().ToLowerInvariant() + @Constants.AlienSpeciesTables.FirstObsTableColumn2:@record.Year + @Html.Raw(@Constants.AlienSpeciesTables.FirstObsTableColumn3):@( record.IsUncertaintyYear ? "ja" : "nei" ) } diff --git a/Assessments.Mapping/AlienSpecies/Helpers/AlienSpeciesAssessment2023ProfileHelper.cs b/Assessments.Mapping/AlienSpecies/Helpers/AlienSpeciesAssessment2023ProfileHelper.cs index fd50d9e50..f5bb4b03c 100644 --- a/Assessments.Mapping/AlienSpecies/Helpers/AlienSpeciesAssessment2023ProfileHelper.cs +++ b/Assessments.Mapping/AlienSpecies/Helpers/AlienSpeciesAssessment2023ProfileHelper.cs @@ -836,9 +836,9 @@ internal static List GetYearsFirs bool isUncertaintyYearValue = (bool)firstObservationUncertaintyProperty.GetValue(riskAssessment); yearEstablishmentType.Add(new AlienSpeciesAssessment2023YearFirstRecordItem() { - Item1 = establishmentTypeName, - Item2 = (int)yearFirstValue, - Item3 = isUncertaintyYearValue + RecordType = establishmentTypeName, + Year = (int)yearFirstValue, + IsUncertaintyYear = isUncertaintyYearValue }); } } diff --git a/Assessments.Mapping/AlienSpecies/Model/AlienSpeciesAssessment2023YearFirstRecord.cs b/Assessments.Mapping/AlienSpecies/Model/AlienSpeciesAssessment2023YearFirstRecord.cs index 3525f208a..1e2c115f4 100644 --- a/Assessments.Mapping/AlienSpecies/Model/AlienSpeciesAssessment2023YearFirstRecord.cs +++ b/Assessments.Mapping/AlienSpecies/Model/AlienSpeciesAssessment2023YearFirstRecord.cs @@ -12,10 +12,10 @@ public class AlienSpeciesAssessment2023YearFirstRecord public class AlienSpeciesAssessment2023YearFirstRecordItem { - public AlienSpeciesAssessment2023YearFirstRecordType Item1 { get; set; } + public AlienSpeciesAssessment2023YearFirstRecordType RecordType { get; set; } - public int Item2 { get; set; } + public int Year { get; set; } - public bool Item3 { get; set; } + public bool IsUncertaintyYear { get; set; } } } \ No newline at end of file From d533178e37040ec50cef775e09a42b698c493a84 Mon Sep 17 00:00:00 2001 From: Eirik Date: Wed, 8 Jan 2025 09:38:52 +0100 Subject: [PATCH 3/3] Move local function --- Assessments.Frontend.Web/Infrastructure/DataRepository.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Assessments.Frontend.Web/Infrastructure/DataRepository.cs b/Assessments.Frontend.Web/Infrastructure/DataRepository.cs index 0f9c00bfb..892644c76 100644 --- a/Assessments.Frontend.Web/Infrastructure/DataRepository.cs +++ b/Assessments.Frontend.Web/Infrastructure/DataRepository.cs @@ -46,6 +46,8 @@ public DataRepository(IAppCache appCache, IConfiguration configuration, IWebHost public Task> GetData(string name) { + return _appCache.GetOrAddAsync($"{nameof(DataRepository)}-{name}", DeserializeData); + async Task> DeserializeData() { var fileName = Path.Combine(_environment.ContentRootPath, Constants.CacheFolder, name); @@ -78,8 +80,6 @@ async Task> DeserializeData() return csv.GetRecords().ToList().AsQueryable(); } - - return _appCache.GetOrAddAsync($"{nameof(DataRepository)}-{name}", DeserializeData); } public Task> GetSpeciesAssessments()