Skip to content

Commit

Permalink
Add support for selecting radiation database
Browse files Browse the repository at this point in the history
  • Loading branch information
drmax-lukasholeczy committed Mar 21, 2022
1 parent 3529c0a commit 3520ec9
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ composer require holicz/pvgis

use holicz\PVGIS\PVGIS;
use holicz\PVGIS\Adapter\PvgisAdapter;
use holicz\PVGIS\Enum\Database;

$latitude = '50.0898689';
$longitude = '14.4000936';
Expand All @@ -23,7 +24,8 @@ $electricityProduction = $pvgis->getElectricityProduction(
$latitude,
$longitude,
35, // Solar panels angle (not required)
CardinalDirection::SOUTH // Solar panels azimuth (not required)
CardinalDirection::SOUTH, // Solar panels azimuth (not required)
Database::SARAH // Name of the radiation database (not required)
);

// Yearly sum of production
Expand Down
10 changes: 10 additions & 0 deletions src/Adapter/UrlBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function build(): string
$this->buildGPSCoordinates();
$this->buildAngle();
$this->buildAzimuth();
$this->buildDatabase();

return $this->url;
}
Expand All @@ -51,4 +52,13 @@ private function buildAzimuth(): void

$this->url .= sprintf('&aspect=%d', $this->request->getAzimuth());
}

private function buildDatabase(): void
{
if ($this->request->getDatabase() === null) {
return;
}

$this->url .= sprintf('&raddatabase=%s', $this->request->getDatabase());
}
}
15 changes: 15 additions & 0 deletions src/Enum/Database.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace holicz\PVGIS\Enum;

final class Database
{
public const SARAH = 'PVGIS-SARAH';
public const NSRDB = 'PVGIS-NSRDB';
public const ERA5 = 'PVGIS-ERA5';
public const COSMO = 'PVGIS-COSMO';
/** @deprecated */
public const CMSAF = 'PVGIS-CMSAF';
}
15 changes: 14 additions & 1 deletion src/Model/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@ final class Request
private string $longitude;
private ?int $angle;
private ?int $azimuth;
private ?string $database;

public function __construct(
string $latitude,
string $longitude,
?int $angle = null,
?int $azimuth = null
?int $azimuth = null,
?string $database = null
) {
$this->latitude = $latitude;
$this->longitude = $longitude;
$this->angle = $angle;
$this->azimuth = $azimuth;
$this->database = $database;
}

public function getLatitude(): string
Expand Down Expand Up @@ -55,4 +58,14 @@ public function getAzimuth(): ?int
{
return $this->azimuth;
}

public function setDatabase(?string $database): void
{
$this->database = $database;
}

public function getDatabase(): ?string
{
return $this->database;
}
}
5 changes: 3 additions & 2 deletions src/PVGIS.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ public function getElectricityProduction(
string $latitude,
string $longitude,
?int $angle = null,
?int $azimuth = null
?int $azimuth = null,
?string $database = null
): ElectricityProduction {
$request = new Request($latitude, $longitude, $angle, $azimuth);
$request = new Request($latitude, $longitude, $angle, $azimuth, $database);

return $this->pvgisAdapter->getPvgisData($request);
}
Expand Down

0 comments on commit 3520ec9

Please sign in to comment.