Skip to content

Commit

Permalink
Merge pull request #31 from Noitcereon/fix/fetchMeterDataFromAllMeter…
Browse files Browse the repository at this point in the history
…ingPoints

Fix: Fetch data from all meteringpoints instead of only some
  • Loading branch information
Noitcereon committed Jun 5, 2024
2 parents 3184095 + 8e0bef2 commit 14e1d76
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public ScreenOption fetchMeterData(){
LocalDate yesterday = LocalDate.now().minusDays(1);
LocalDate dayBeforeYesterDay = yesterday.minusDays(1);
return new ScreenOption("Fetch meterdata from yesterday (" + yesterday + ")", () -> {
Optional<List<MeteringPointApiDto>> meteringPoints = elOverblikApi.getMeteringPoints(false);
Optional<List<MeteringPointApiDto>> meteringPoints = elOverblikApi.getMeteringPoints(true);
if(meteringPoints.isEmpty()){
LOG.error("Failed to retrieve meteringsPoints from API, so can't fetch MeterData.");
throw new ElectricityConsolidatorRuntimeException("No metering points, so can't continue.");
Expand All @@ -73,7 +73,7 @@ public ScreenOption fetchMeterDataBasedOnLastFetchTime(){
LocalDate fromDate = latestFetchDate;
LocalDate toDate = LocalDate.now().minusDays(1);
return new ScreenOption("Fetch MeterData based on latest fetch date (from %s to %s)".formatted(fromDate, toDate), () -> {
Optional<List<MeteringPointApiDto>> meteringPoints = elOverblikApi.getMeteringPoints(false);
Optional<List<MeteringPointApiDto>> meteringPoints = elOverblikApi.getMeteringPoints(true);
if(meteringPoints.isEmpty()){
LOG.error("Failed to retrieve meteringsPoints from API, so can't fetch MeterData.");
throw new ElectricityConsolidatorRuntimeException("No metering points, so can't continue.");
Expand All @@ -93,7 +93,7 @@ public ScreenOption fetchMeterDataCustomPeriod(){
LocalDate dateFrom = LocalDate.parse(Screen.getScannerInstance().nextLine());
System.out.println("Enter dateTo in format YYYY-MM-DD");
LocalDate dateTo = LocalDate.parse(Screen.getScannerInstance().nextLine());
Optional<List<MeteringPointApiDto>> meteringPoints = elOverblikApi.getMeteringPoints(false);
Optional<List<MeteringPointApiDto>> meteringPoints = elOverblikApi.getMeteringPoints(true);
if(meteringPoints.isEmpty()){
LOG.error("Failed to retrieve meteringsPoints from API, so can't fetch MeterData.");
throw new ElectricityConsolidatorRuntimeException("No metering points, so can't continue.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@
@EloverblikApiModel
public record MeteringPointsRequest (MeteringPoints meteringPoints){
public static MeteringPointsRequest from(List<MeteringPointApiDto> meteringPointApiDtos) {
return from(meteringPointApiDtos, true);
}
public static MeteringPointsRequest from(List<MeteringPointApiDto> meteringPointApiDtos, boolean includeChildMeteringPoints) {
List<String> meteringPoints = new ArrayList<>();
for (MeteringPointApiDto item : meteringPointApiDtos){
meteringPoints.add(item.getMeteringPointId());
for (MeteringPointApiDto meteringPoint : meteringPointApiDtos){
meteringPoints.add(meteringPoint.getMeteringPointId());
if(meteringPoint.getChildMeteringPoints().isEmpty() || !includeChildMeteringPoints){
continue; // Don't try to add child metering points.
}
for (ChildMeteringPointDto childMeteringPoint : meteringPoint.getChildMeteringPoints()) {
meteringPoints.add(childMeteringPoint.getMeteringPointId());
}
}
return new MeteringPointsRequest(new MeteringPoints(meteringPoints));
}
Expand Down

0 comments on commit 14e1d76

Please sign in to comment.