Skip to content

Commit

Permalink
Merge pull request #1444 from Artsdatabanken/fix/year-first-record
Browse files Browse the repository at this point in the history
Fix year first record
  • Loading branch information
matssa authored Jan 8, 2025
2 parents 17d0217 + d533178 commit b5277d6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
16 changes: 10 additions & 6 deletions Assessments.Frontend.Web/Infrastructure/DataRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public DataRepository(IAppCache appCache, IConfiguration configuration, IWebHost

public Task<IQueryable<T>> GetData<T>(string name)
{
return _appCache.GetOrAddAsync($"{nameof(DataRepository)}-{name}", DeserializeData);

async Task<IQueryable<T>> DeserializeData()
{
var fileName = Path.Combine(_environment.ContentRootPath, Constants.CacheFolder, name);
Expand Down Expand Up @@ -78,12 +80,14 @@ async Task<IQueryable<T>> DeserializeData()

return csv.GetRecords<T>().ToList().AsQueryable();
}

return _appCache.GetOrAddAsync($"{nameof(DataRepository)}-{name}", DeserializeData);
}

public Task<IQueryable<SpeciesAssessment2021>> GetSpeciesAssessments()
{
var speciesAssessments = _appCache.GetOrAddAsync(nameof(GetSpeciesAssessments), Get);

return speciesAssessments;

async Task<IQueryable<SpeciesAssessment2021>> Get()
{
return _options.Value.Species2021.TransformAssessments
Expand All @@ -93,12 +97,14 @@ async Task<IQueryable<SpeciesAssessment2021>> Get()
// returnerer modell som allerede er transformert
await GetData<SpeciesAssessment2021>(DataFilenames.Species2021);
}

return _appCache.GetOrAddAsync($"{nameof(GetSpeciesAssessments)}", Get);
}

public Task<IQueryable<AlienSpeciesAssessment2023>> GetAlienSpeciesAssessments()
{
var alienSpeciesAssessments = _appCache.GetOrAddAsync(nameof(GetAlienSpeciesAssessments), Get);

return alienSpeciesAssessments;

async Task<IQueryable<AlienSpeciesAssessment2023>> Get()
{
return _options.Value.AlienSpecies2023.TransformAssessments
Expand All @@ -108,8 +114,6 @@ async Task<IQueryable<AlienSpeciesAssessment2023>> Get()
// returnerer modell som allerede er transformert
await GetData<AlienSpeciesAssessment2023>(DataFilenames.AlienSpecies2023);
}

return _appCache.GetOrAddAsync($"{nameof(GetSpeciesAssessments)}", Get);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@
@foreach(var record in Model.Assessment.YearsFirstRecord.ObservedEstablishmentInNorway)
{
<tr>
<td>@record.recordType.DisplayName().ToLowerInvariant()</td>
<td><b class="only_mobile">@Constants.AlienSpeciesTables.FirstObsTableColumn2:</b>@record.year</td>
<td><b class="only_mobile">@Html.Raw(@Constants.AlienSpeciesTables.FirstObsTableColumn3):</b>@( record.isUncertaintyYear ? "ja" : "nei" )</td>
<td>@record.RecordType.DisplayName().ToLowerInvariant()</td>
<td><b class="only_mobile">@Constants.AlienSpeciesTables.FirstObsTableColumn2:</b>@record.Year</td>
<td><b class="only_mobile">@Html.Raw(@Constants.AlienSpeciesTables.FirstObsTableColumn3):</b>@( record.IsUncertaintyYear ? "ja" : "nei" )</td>
</tr>
}
</table>
Expand Down
2 changes: 1 addition & 1 deletion Assessments.Frontend.Web/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"TransformAssessments": false
},
"Species2021": {
"TransformAssessments": true
"TransformAssessments": false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<AlienSpeciesAssessment2023YearFirstRecordItem> 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<AlienSpeciesAssessment2023YearFirstRecordItem>();
}

else
{
var yearEstablishmentType = new List<(AlienSpeciesAssessment2023YearFirstRecordType, int, bool)>();
var yearEstablishmentType = new List<AlienSpeciesAssessment2023YearFirstRecordItem>();

foreach (var firstObservationProperty in riskAssessmentPropertiesFirstObservations)
{
Expand All @@ -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()
{
RecordType = establishmentTypeName,
Year = (int)yearFirstValue,
IsUncertaintyYear = isUncertaintyYearValue
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AlienSpeciesAssessment2023YearFirstRecordItem> ObservedEstablishmentInNorway { get; set; } = new();

public string Description { get; set; }
}

public class AlienSpeciesAssessment2023YearFirstRecordItem
{
public AlienSpeciesAssessment2023YearFirstRecordType RecordType { get; set; }

public int Year { get; set; }

public bool IsUncertaintyYear { get; set; }
}
}

0 comments on commit b5277d6

Please sign in to comment.