Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,8 @@ protected static int calculateAvailEnergy(Integer[] quarterHourlyProduction, Int
int dailyEndIndex = DelayCharge.getAsZonedDateTime(targetMinute, clock).get(MINUTE_OF_DAY) / 15;

// Relevant quarter hours
int endIndex = dailyEndIndex - dailyStartIndex;
int endIndex = Math.min(dailyEndIndex - dailyStartIndex,
Math.min(quarterHourlyProduction.length, quarterHourlyConsumption.length));

float productionEnergyTotal = 0;
float consumptionEnergyTotal = 0;
Expand All @@ -558,7 +559,7 @@ protected static int calculateAvailEnergy(Integer[] quarterHourlyProduction, Int
* Summarize and calculate every quarterly power, if there is more than one
* quarter hour left
*/
if (endIndex > 0) {
if (endIndex > 1) {
List<Integer> productionList = Arrays.asList(quarterHourlyProduction).subList(1, endIndex);
List<Integer> consumptionList = Arrays.asList(quarterHourlyConsumption).subList(1, endIndex);

Expand All @@ -576,8 +577,12 @@ protected static int calculateAvailEnergy(Integer[] quarterHourlyProduction, Int
// Add energy of the first index separately to ignore the already passed energy
float timeOfQuarterLeft = ChronoUnit.SECONDS.between(now, predictionStartQuarterHour.plusMinutes(15)) / 60.0f
/ 60.0f;
var currentProduction = quarterHourlyProduction[0] == null ? 0 : quarterHourlyProduction[0];
var currentConsumption = quarterHourlyConsumption[0] == null ? 0 : quarterHourlyConsumption[0];
var currentProduction = quarterHourlyProduction.length > 0 && quarterHourlyProduction[0] != null
? quarterHourlyProduction[0]
: 0;
var currentConsumption = quarterHourlyConsumption.length > 0 && quarterHourlyConsumption[0] != null
? quarterHourlyConsumption[0]
: 0;
float leftProdEnergy = timeOfQuarterLeft * currentProduction;
float leftConsEnergy = timeOfQuarterLeft * currentConsumption;

Expand Down