-
Notifications
You must be signed in to change notification settings - Fork 3
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
15 changed files
with
495 additions
and
275 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
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
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
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
45 changes: 45 additions & 0 deletions
45
src/main/java/be/coronalert/statistics/StatisticsReport.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,45 @@ | ||
package be.coronalert.statistics; | ||
|
||
import be.coronalert.statistics.data.Result; | ||
import java.time.LocalDate; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class StatisticsReport { | ||
|
||
private Integer averageInfected; | ||
private Integer averageInfectedChangePercentage; | ||
private Integer averageHospitalised; | ||
private Integer averageHospitalisedChangePercentage; | ||
private Integer averageDeceased; | ||
private Integer averageDeceasedChangePercentage; | ||
private LocalDate startDate; | ||
private LocalDate endDate; | ||
|
||
|
||
/** | ||
* Creates the statisticsreport. | ||
*/ | ||
public StatisticsReport( | ||
LocalDate endDate, | ||
Result cases, | ||
Result hospitalisations, | ||
Result mortalities | ||
|
||
) { | ||
|
||
this.endDate = endDate; | ||
this.startDate = this.endDate.minusDays(6); | ||
|
||
this.averageDeceased = mortalities.getCurrentValue().intValue(); | ||
this.averageDeceasedChangePercentage = mortalities.getDifference(); | ||
|
||
this.averageHospitalised = hospitalisations.getCurrentValue().intValue(); | ||
this.averageHospitalisedChangePercentage = hospitalisations.getDifference(); | ||
|
||
this.averageInfected = cases.getCurrentValue().intValue(); | ||
this.averageInfectedChangePercentage = cases.getDifference(); | ||
|
||
} | ||
|
||
} |
77 changes: 77 additions & 0 deletions
77
src/main/java/be/coronalert/statistics/StatisticsRunner.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,77 @@ | ||
package be.coronalert.statistics; | ||
|
||
import be.coronalert.statistics.cases.CovidCasesPoller; | ||
import be.coronalert.statistics.config.StatisticsServiceConfig; | ||
import be.coronalert.statistics.hospitalisations.HospitalisationsPoller; | ||
import be.coronalert.statistics.mortality.MortalityPoller; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.time.LocalDate; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.ApplicationArguments; | ||
import org.springframework.boot.ApplicationRunner; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.stereotype.Component; | ||
import software.amazon.awssdk.core.sync.RequestBody; | ||
import software.amazon.awssdk.regions.Region; | ||
import software.amazon.awssdk.services.s3.S3Client; | ||
import software.amazon.awssdk.services.s3.model.PutObjectRequest; | ||
|
||
@Component | ||
@Order(1) | ||
public class StatisticsRunner implements ApplicationRunner { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(StatisticsRunner.class); | ||
|
||
private static final Region DEFAULT_REGION = Region.EU_CENTRAL_1; | ||
|
||
@Autowired | ||
private ConfigurableApplicationContext context; | ||
|
||
@Autowired | ||
private HospitalisationsPoller hospitalisationsPoller; | ||
|
||
@Autowired | ||
private CovidCasesPoller covidCasesPoller; | ||
|
||
@Autowired | ||
private MortalityPoller mortalityPoller; | ||
|
||
@Autowired | ||
private StatisticsServiceConfig statisticsServiceConfig; | ||
|
||
@Autowired | ||
private ObjectMapper objectMapper; | ||
|
||
@Override | ||
public void run(ApplicationArguments args) throws Exception { | ||
StatisticsReport statisticsReport = new StatisticsReport( | ||
LocalDate.now().minusDays(4), | ||
covidCasesPoller.pollResults(), | ||
hospitalisationsPoller.pollResults(), | ||
mortalityPoller.pollResults() | ||
); | ||
|
||
logger.info("statisticsReport = " + statisticsReport); | ||
|
||
PutObjectRequest putObjectRequest = PutObjectRequest | ||
.builder() | ||
.bucket(statisticsServiceConfig.getS3().getBucket()) | ||
.key(statisticsServiceConfig.getS3().getKey()) | ||
.contentType("application/json") | ||
.build(); | ||
|
||
RequestBody requestBody = RequestBody.fromString(objectMapper.writeValueAsString(statisticsReport)); | ||
|
||
S3Client s3Client = S3Client | ||
.builder() | ||
.region(DEFAULT_REGION) | ||
.build(); | ||
|
||
s3Client.putObject(putObjectRequest, requestBody); | ||
|
||
context.close(); | ||
} | ||
} |
Oops, something went wrong.