Skip to content

Commit

Permalink
Nasadenie do produkcie 5 + 75
Browse files Browse the repository at this point in the history
  • Loading branch information
developer committed Jun 23, 2024
1 parent 3aefd12 commit 58f5e08
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/Abstractions/ISparqlClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public interface ISparqlClient

Task<List<DcatDistribution>> GetDistributions(Uri datasetId, bool trace = false);

Task<Dictionary<Uri, bool>> GetDownloadQuality();
Task<Dictionary<string, bool>> GetDownloadQuality();
}
}
24 changes: 12 additions & 12 deletions src/Abstractions/SparqlClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,23 +211,23 @@ public async Task<List<DcatDistribution>> GetDistributions(Uri datasetId, bool t
return distributions;
}

public async Task<Dictionary<Uri, bool>> GetDownloadQuality()
public async Task<Dictionary<string, bool>> GetDownloadQuality()
{
string content = await GetContent(@"SELECT ?distribution ?value
WHERE {
?measurment a <http://www.w3.org/ns/dqv#QualityMeasurement>;
<http://www.w3.org/ns/dqv#isMeasurementOf> <https://data.gov.sk/def/observation/data-quality/metrics/metrikaDostupnostiDownloadURL>;
<http://schema.org/object> ?distribution;
<http://www.w3.org/ns/dqv#value> ?value.
}", false);
Dictionary<Uri, bool> quality = new Dictionary<Uri, bool>();
WHERE {
?measurment a <http://www.w3.org/ns/dqv#QualityMeasurement>;
<http://www.w3.org/ns/dqv#isMeasurementOf> <https://data.gov.sk/def/observation/data-quality/metrics/metrikaDostupnostiDownloadURL>;
<http://schema.org/object> ?distribution;
<http://www.w3.org/ns/dqv#value> ?value.
}", false);
Dictionary<string, bool> quality = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
foreach (JToken token in JObject.Parse(content)?["results"]?["bindings"] ?? Enumerable.Empty<JToken>())
{
string? key = token["item"]?["distribution"]?.ToString();
bool? value = token["item"]?["value"]?.Value<bool>() ?? false;
if (value.HasValue && Uri.TryCreate(key, UriKind.Absolute, out Uri? uri))
string? key = token["distribution"]?["value"]?.ToString();
bool value = token["value"]?["value"]?.Value<string>() == "true";
if (!string.IsNullOrEmpty(key))
{
quality[uri] = value.Value;
quality[key] = value;
}
}
return quality;
Expand Down
2 changes: 1 addition & 1 deletion src/WebApi/DistributionView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static async Task<DistributionView> MapFromRdf(Guid id, Guid? datasetId,
&& legTermsOfUse.DatabaseProtectedBySpecialRightsType is not null
&& legTermsOfUse.PersonalDataContainmentType is not null;

view.DownloadStatus = distributionRdf.DownloadUrl is not null ? qualityService.IsDownloadQualityGood(distributionRdf.DownloadUrl) : null;
view.DownloadStatus = distributionRdf.DownloadUrl is not null ? qualityService.IsDownloadQualityGood(distributionRdf.DownloadUrl.ToString()) : null;

if (fetchAllLanguages)
{
Expand Down
12 changes: 9 additions & 3 deletions src/WebApi/DownloadDataQualityService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace WebApi
{
public class DownloadDataQualityService
{
private Dictionary<Uri, bool>? status;
private Dictionary<string, bool>? status;

private readonly ISparqlClient client;

Expand All @@ -30,21 +30,27 @@ public async Task Load()
{
try
{
telemetryClient.TrackTrace("DownloadDataQualityService.Load");
status = await this.client.GetDownloadQuality();
telemetryClient.TrackTrace("DownloadDataQualityService.Loaded");
}
catch (Exception e)
{
telemetryClient.TrackException(e);
}
}

public bool? IsDownloadQualityGood(Uri distributionId)
public bool? IsDownloadQualityGood(string downloadUrl)
{
if (status == null)
{
return null;
}
return status.TryGetValue(distributionId, out bool isGood) && isGood;
if (status.TryGetValue(downloadUrl, out bool isGood))
{
return isGood;
}
return null;
}
}
}

0 comments on commit 58f5e08

Please sign in to comment.