Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Baspa/energyzero-php-api
Browse files Browse the repository at this point in the history
  • Loading branch information
Baspa committed Aug 26, 2024
2 parents 67cf6fc + d5577d5 commit ff41ef9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/EnergyZero.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public function energyPrices(string $startDate, string $endDate, int $interval =
public function getAveragePriceForPeriod(string $startDate, string $endDate, ?bool $vat = null): float
{
$data = $this->energyPrices($startDate, $endDate, 4, $vat);

return $data['average'];
}

Expand All @@ -114,9 +115,10 @@ public function getLowestPriceForPeriod(string $startDate, string $endDate, ?boo
$data = $this->energyPrices($startDate, $endDate, 4, $vat);
$lowestPrice = min(array_column($data['Prices'], 'price'));
$lowestPriceIndex = array_search($lowestPrice, array_column($data['Prices'], 'price'));

return [
'price' => $lowestPrice,
'datetime' => $data['Prices'][$lowestPriceIndex]['readingDate']
'datetime' => $data['Prices'][$lowestPriceIndex]['readingDate'],
];
}

Expand All @@ -132,9 +134,10 @@ public function getHighestPriceForPeriod(string $startDate, string $endDate, ?bo
$data = $this->energyPrices($startDate, $endDate, 4, $vat);
$highestPrice = max(array_column($data['Prices'], 'price'));
$highestPriceIndex = array_search($highestPrice, array_column($data['Prices'], 'price'));

return [
'price' => $highestPrice,
'datetime' => $data['Prices'][$highestPriceIndex]['readingDate']
'datetime' => $data['Prices'][$highestPriceIndex]['readingDate'],
];
}

Expand Down Expand Up @@ -186,6 +189,7 @@ public function getPeakHours(string $startDate, string $endDate, int $topN = 5,
usort($prices, function ($a, $b) {
return $b['price'] <=> $a['price'];
});

return array_slice($prices, 0, $topN);
}

Expand All @@ -204,6 +208,7 @@ public function getValleyHours(string $startDate, string $endDate, int $topN = 5
usort($prices, function ($a, $b) {
return $a['price'] <=> $b['price'];
});

return array_slice($prices, 0, $topN);
}
}

0 comments on commit ff41ef9

Please sign in to comment.