-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathDemand.php
executable file
·52 lines (44 loc) · 1.67 KB
/
Demand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace KateMorley\Grid\State;
/** Represents details of demand. */
class Demand extends Map {
public const DEMAND = 'demand';
public const FOSSILS = 'fossils';
public const RENEWABLES = 'renewables';
public const OTHERS = 'others';
public const TRANSFERS = 'transfers';
public const KEYS = [
self::DEMAND => 'Demand',
self::FOSSILS => 'Fossil fuels',
self::RENEWABLES => 'Renewables',
self::OTHERS => 'Other sources',
self::TRANSFERS => 'Transfers'
];
private float $generation;
/**
* Constructs a new instance.
*
* @param Types $types Details of power generation by type
* @param Transfers $transfers Details of transfers
*/
public function __construct(Types $types, Transfers $transfers) {
$fossils = round($types->get(Types::FOSSILS), 1);
$renewables = round($types->get(Types::RENEWABLES), 1);
$others = round($types->get(Types::OTHERS), 1);
$transfers = round($transfers->getTotal(), 1);
$this->generation = $fossils + $renewables + $others;
$this->map[self::DEMAND] = $this->generation + $transfers;
$this->map[self::FOSSILS] = $fossils;
$this->map[self::RENEWABLES] = $renewables;
$this->map[self::OTHERS] = $others;
$this->map[self::TRANSFERS] = $transfers;
}
/**
* Returns the total power generation. This differs from calling getTotal() on
* a Generation instance as return value is calculated from values that have
* already been rounded, and hence is suitable for display in equations.
*/
public function getGeneration(): float {
return $this->generation;
}
}