Skip to content

Commit

Permalink
Add multiplier
Browse files Browse the repository at this point in the history
  • Loading branch information
Holicz committed Mar 30, 2020
1 parent ed29b57 commit 9ea384d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
"minimum-stability": "stable",
"require": {
"php": "^7.4",
"ext-json": "*",
"holicz/simple-exception": "^1.1",
"thecodingmachine/safe": "^1.1"
"thecodingmachine/safe": "1.1"
},
"require-dev": {
"phpstan/phpstan": "^0.12.18",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions src/Adapter/PvgisAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ final class PvgisAdapter
{
private const API_URL = 'https://re.jrc.ec.europa.eu/api/pvcalc?peakpower=1&pvtechchoice=crystSi&mountingplace=building&loss=1&outputformat=json&angle=35&lat=%s&lon=%s';

/**
* Multiplier to change the PVGIS result in order to get desired production
*/
private float $multiplier;

public function __construct(float $multiplier = 1.0)
{
$this->multiplier = $multiplier;
}

/**
* @param string $latitude
* @param string $longitude
Expand Down Expand Up @@ -43,15 +53,16 @@ public function getPvgisData(string $latitude, string $longitude): ElectricityPr
* @return ElectricityProduction
*
* @throws InvalidResponseFormatException
* @throws StringsException
*/
private function parsePvgisResponse(string $response): ElectricityProduction
{
try {
$response = json_decode($response, true, 512, JSON_THROW_ON_ERROR);

$electricityProduction = new ElectricityProduction($response['outputs']['totals']['fixed']['E_m']);
$electricityProduction = new ElectricityProduction($this->multiplier * $response['outputs']['totals']['fixed']['E_m']);
foreach ($response['outputs']['monthly']['fixed'] as $month) {
$electricityProduction->addMonthlyProduction($month['month'], $month['E_m']);
$electricityProduction->addMonthlyProduction($month['month'], $this->multiplier * $month['E_m']);
}
} catch (Exception $e) {
throw new InvalidResponseFormatException(['response' => $response]);
Expand Down

0 comments on commit 9ea384d

Please sign in to comment.