-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
3,108 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/it/gov/innovazione/ndc/controller/SemanticAssetStatSample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package it.gov.innovazione.ndc.controller; | ||
|
||
import it.gov.innovazione.ndc.harvester.SemanticAssetType; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
@Data | ||
@Builder | ||
public class SemanticAssetStatSample { | ||
private final String resourceUri; | ||
private final SemanticAssetType resourceType; | ||
private final String rightHolder; | ||
private final boolean hasErrors; | ||
private final boolean hasWarnings; | ||
private final String statusType; | ||
private final int yearOfHarvest; | ||
} |
86 changes: 53 additions & 33 deletions
86
src/main/java/it/gov/innovazione/ndc/controller/SemanticAssetStats.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,65 @@ | ||
package it.gov.innovazione.ndc.controller; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.RoundingMode; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
@Data | ||
@Builder | ||
public class SemanticAssetStats { | ||
private final SemanticAssetTypeStats total; | ||
private final SemanticAssetTypeStats controlledVocabulary; | ||
private final SemanticAssetTypeStats ontology; | ||
private final SemanticAssetTypeStats schema; | ||
|
||
@Data | ||
@Builder | ||
public static class SemanticAssetTypeStats { | ||
private final long current; | ||
private final long lastYear; | ||
private final StatusStat status; | ||
|
||
public long getIncrementOverLastYear() { | ||
return current - lastYear; | ||
} | ||
|
||
public double getIncrementPercentageOverLastYear() { | ||
BigDecimal bigDecimal = BigDecimal.valueOf( | ||
lastYear == 0 | ||
? 0 | ||
: ((double) current - lastYear) / lastYear * 100); | ||
return bigDecimal.setScale(1, RoundingMode.HALF_UP).doubleValue(); | ||
} | ||
private final SemanticAssetTypeStats total; | ||
private final SemanticAssetTypeStats controlledVocabulary; | ||
private final SemanticAssetTypeStats ontology; | ||
private final SemanticAssetTypeStats schema; | ||
|
||
private static double round(double value) { | ||
BigDecimal bigDecimal = BigDecimal.valueOf(value); | ||
return bigDecimal.setScale(1, RoundingMode.HALF_UP).doubleValue(); | ||
} | ||
|
||
@Data | ||
@Builder | ||
public static class SemanticAssetTypeStats { | ||
private final long current; | ||
private final long lastYear; | ||
private final StatusStat status; | ||
|
||
public long getIncrementOverLastYear() { | ||
return current - lastYear; | ||
} | ||
|
||
public double getIncrementPercentageOverLastYear() { | ||
return round(lastYear == 0 ? 0 : ((double) current - lastYear) / lastYear * 100); | ||
} | ||
} | ||
|
||
@Builder | ||
public static class StatusStat { | ||
private final double archived; | ||
private final double published; | ||
private final double closedAccess; | ||
private final double draft; | ||
private final double unknown; | ||
|
||
public double getArchived() { | ||
return round(archived * 100); | ||
} | ||
|
||
public double getPublished() { | ||
return round(published * 100); | ||
} | ||
|
||
public double getClosedAccess() { | ||
return round(closedAccess * 100); | ||
} | ||
|
||
public double getDraft() { | ||
return round(draft * 100); | ||
} | ||
|
||
@Data | ||
@Builder | ||
public static class StatusStat { | ||
private final double archived; | ||
private final double published; | ||
private final double closedAccess; | ||
private final double draft; | ||
public double getUnknown() { | ||
return round(unknown * 100); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/it/gov/innovazione/ndc/controller/SemanticAssetsStatsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package it.gov.innovazione.ndc.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import it.gov.innovazione.ndc.harvester.service.SemanticContentStatsService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.time.LocalDate; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
public class SemanticAssetsStatsController { | ||
|
||
private final SemanticContentStatsService semanticContentStatsService; | ||
|
||
@Operation( | ||
tags = {"semantic-assets"}, | ||
summary = "Retrieves the statistics", | ||
description = "Retrieves the statistics of the semantic assets.", | ||
operationId = "getStats", | ||
responses = { | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "OK", | ||
content = { | ||
@Content( | ||
mediaType = "application/json", | ||
schema = @Schema(implementation = SemanticAssetStats.class)) | ||
}) | ||
}) | ||
@GetMapping( | ||
value = "semantic-assets/stats", | ||
produces = {"application/json"}) | ||
public SemanticAssetStats getStats(@RequestParam(name = "year", required = false) Integer year) { | ||
// get current year from system date | ||
if (year == null) { | ||
year = LocalDate.now().getYear(); | ||
} | ||
return semanticContentStatsService.getStats(year); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.