ourenergy / eiep
A library for working with Electricity information exchange protocol files
Installs: 4 229
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=7.1.0
- league/csv: ^9.2
Requires (Dev)
- phpunit/phpunit: ^7.5
This package is auto-updated.
Last update: 2024-10-28 07:58:11 UTC
README
Electricity Information Exchange Protocol (EIEP)
A PHP library for working with the Electricity Authority's EIEP data files. Supports PHP 7.1+.
Uses league/csv for reading and writing CSV files.
Currently supported protocols and versions;
Installation
composer require ourenergy/eiep
Reading from a file
use Eiep\Eiep3\Report; use Eiep\Eiep3\DetailRecord; $report = new Report(); $report->streamFromFile("eiep3.csv", function(DetailRecord $record) { echo $record->getActiveEnergy() . PHP_EOL; });
Working with an existing stream
use Eiep\Eiep3\Report; use Eiep\Eiep3\DetailRecord; $report = new Report(); $handle = fopen("eiep3.csv", "r"); $report->readFromStream($handle, function(DetailRecord $record) { echo $record->getActiveEnergy() . PHP_EOL; });
Writing a new report
use Eiep\Eiep3\Report; use Eiep\Eiep3\DetailRecord; // Create the report $report = new Report(); $report ->setReportDate(new \DateTime("2019-01-01 00:00:00")) ->setUtilityType(Report::UTILITY_TYPE_ELECTRICITY) ->setFileStatus(Report::FILE_STATUS_REPLACEMENT) ->setNumRecords(1); // Create records $record = new DetailRecord(); $record ->setIcpIdentifier("1234567890") ->setStreamIdentifier("ABCDEFG") ->setReadingType(DetailRecord::READING_TYPE_FINAL) ->setDate(new \DateTime("2019-01-01 00:00:00")) ->setTradingPeriod(48) ->setActiveEnergy(1) ->setReactiveEnergy(2) ->setApparentEnergy(3) ->setFlowDirection(DetailRecord::FLOW_DIRECTION_EXTRACT); // Write everything to a file $records = [ $record ]; $report->writeRecords("eiep3.csv", $records);
Creating a write stream
use Eiep\Eiep3\Report; use Eiep\Eiep3\DetailRecord; // ... prepare your report and records as above ... // Create a writer $writer = $report->createWriter("eiep3.csv"); // Write one record $writer->insertOne($record->toArray()); // Write multiple records $rows = array_map(function (DetailRecord $record) { return $record->toArray(); }, $records); $writer->insertAll($rows);