Skip to content

Commit

Permalink
Add __clone method, increase loss to 10 %
Browse files Browse the repository at this point in the history
  • Loading branch information
Holicz committed Mar 30, 2020
1 parent 9ea384d commit d35da25
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Adapter/PvgisAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

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';
private const API_URL = 'https://re.jrc.ec.europa.eu/api/pvcalc?peakpower=1&pvtechchoice=crystSi&mountingplace=building&loss=10&outputformat=json&angle=35&lat=%s&lon=%s';

/**
* Multiplier to change the PVGIS result in order to get desired production
Expand Down Expand Up @@ -60,7 +60,7 @@ private function parsePvgisResponse(string $response): ElectricityProduction
try {
$response = json_decode($response, true, 512, JSON_THROW_ON_ERROR);

$electricityProduction = new ElectricityProduction($this->multiplier * $response['outputs']['totals']['fixed']['E_m']);
$electricityProduction = new ElectricityProduction($this->multiplier * $response['outputs']['totals']['fixed']['E_y']);
foreach ($response['outputs']['monthly']['fixed'] as $month) {
$electricityProduction->addMonthlyProduction($month['month'], $this->multiplier * $month['E_m']);
}
Expand Down
10 changes: 10 additions & 0 deletions src/Model/ElectricityProduction.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ public function __construct(float $yearlyProduction)
$this->yearlyProduction = $yearlyProduction;
}

public function __clone()
{
$monthlyProductions = [];
foreach ($this->monthlyProductions as $monthlyProduction) {
$monthlyProductions[] = clone $monthlyProduction;
}

$this->monthlyProductions = $monthlyProductions;
}

public function addMonthlyProduction(int $month, float $production): self
{
$this->monthlyProductions[] = new MonthlyProduction($month, $production);
Expand Down

0 comments on commit d35da25

Please sign in to comment.