Skip to content

Commit

Permalink
Merge pull request #1446 from Artsdatabanken/test
Browse files Browse the repository at this point in the history
Ny master til prod
  • Loading branch information
matssa authored Jan 8, 2025
2 parents 7df6b14 + 9a2b904 commit d896a16
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 20 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 @@ -468,15 +468,15 @@
</tr>
<tr is-visible="assessment.MedianLifetimeNumericalEstimationGrowthRate != 0">
<td>@Constants.AlienSpeciesTables.GrowthRate (&lambda;) </td>
<td>@assessment.MedianLifetimeNumericalEstimationGrowthRate.ToString("N0")</td>
<td>@assessment.MedianLifetimeNumericalEstimationGrowthRate.ToString("G")</td>
</tr>
<tr is-visible="assessment.MedianLifetimeNumericalEstimationEnvironmentalVariance != null">
<td>@Constants.AlienSpeciesTables.EnvironmentVar (&sigma;<sub>e</sub><sup>2</sup>) </td>
<td>@assessment.MedianLifetimeNumericalEstimationEnvironmentalVariance?.ToString("N0")</td>
<td>@assessment.MedianLifetimeNumericalEstimationEnvironmentalVariance?.ToString("G")</td>
</tr>
<tr is-visible="assessment.MedianLifetimeNumericalEstimationDemographicVariance != null">
<td>@Constants.AlienSpeciesTables.DemographicVar (&sigma;<sub>d</sub><sup>2</sup>) </td>
<td>@assessment.MedianLifetimeNumericalEstimationDemographicVariance?.ToString("N0")</td>
<td>@assessment.MedianLifetimeNumericalEstimationDemographicVariance?.ToString("G")</td>
</tr>
<tr is-visible="assessment.MedianLifetimeNumericalEstimationCarryingCapacity != null">
<td>@Constants.AlienSpeciesTables.CarryingCapasity</td>
Expand Down
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
4 changes: 2 additions & 2 deletions Assessments.Frontend.Web/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<link rel="stylesheet" href="~/css/accordions.css" asp-append-version="true">
<link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css?family=Material+Icons|Material+Icons+Outlined" rel="stylesheet">
<script src="~/js/cookies.js" asp-append-version="true"></script>
<script src="~/js/cookies.js" asp-append-version="true"></script>
</head>

<body>
Expand Down Expand Up @@ -50,7 +50,7 @@
bruksmønstera til enkeltbrukarar eller annan informasjon som vil kunne krenkje personvernet.
</p>
<p>
Artsdatabanken får brukarstatistikk frå Google Analytics.
Artsdatabanken får brukarstatistikk frå Google Analytics og Microsoft Clarity.
Det medfører at bruken din av nettsidene våre, inklusiv IP-adressa di,
kan bli overført til Google, men vi nyttar Google Analytics sin anonymiseringsfunksjon som sørgjer
for at dei siste siffera i brukaren si IP-adresse blir maskert ved innsamling. IP-maskeringa skjer så snart dataa er mottekne av Google Analytics sitt innsamlingsverk,
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
}
}
}
7 changes: 7 additions & 0 deletions Assessments.Frontend.Web/wwwroot/js/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ var cookieDurationString = cookieDuration.toUTCString(); // setCookie uses this
m.parentNode.insertBefore(a, m);

})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
(function(c,l,a,r,i,t,y){
c[a] = c[a] || function () { (c[a].q = c[a].q || []).push(arguments) };
t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
})(window, document, "clarity", "script", "oizcojljrc");

// expand read more
function learnAboutCookies() {
Expand Down Expand Up @@ -92,6 +97,7 @@ function hasAcceptedCookies() {
ga('create', 'UA-74815937-4', { 'cookieExpires': cookieDurationSeconds, 'cookieUpdate': 'false', 'cookieFlags': 'Secure' });
ga('send', 'pageview');
themeCookie();
window.clarity('consent');
location.reload();
}
}
Expand All @@ -103,6 +109,7 @@ function hasRejectedCookies() {
sessionStorage['acceptedcookies'] = acceptedcookies;
document.getElementById('heyCookie').style.display = "none";
// TODO: SHOULD LOOP THRU AND DELETE ALL COOKIES.
window.clarity('consent', false);
}
}

Expand Down
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 d896a16

Please sign in to comment.