cstuder/parse-valueholder

PHP value holder objects for `parse-hydrodaten` and `parse-swissmetnet`

v0.2.1 2023-02-09 14:01 UTC

This package is auto-updated.

Last update: 2024-05-09 16:55:56 UTC


README

PHPUnit tests

PHP value holder objects for parse-hydrodaten and parse-swissmetnet

This simple library provides immutable typed value holder objects (DTO) with the readonly fields timestamp, location, parameter and value.

Also provides a iterable row object containing an array of values and some simple statistic methods, along with a CSV parser.

Example

Installation: composer require cstuder/parse-valueholder

$data = new \cstuder\ParseValueholder\Value(
  $timestamp,
  $locationString,
  $parameterString,
  $value
);

echo $data->timestamp;
echo $data->location;
echo $data->parameter;
echo $data->value;

Row of values

$row = new \cstuder\ParseValueholder\Row([
  $value1,
  $value2
]);

$row->append($value3);

foreach($row as $value) {
  var_dump($value);
}

CSV Parser

A simple CSV parser to parse CSV files without header, in the format timestamp, location, parameter, value, i.e.:

1675281000,BER,tt,5.7

Delimiters, enclosure and escape characters are configurable.

All values are cast to float.

Parses either from a file or from a string:

$row = \cstuder\ParseValueholder\Utils\CsvParser::parseFile($filename);

$row2 = \cstuder\ParseValueholder\Utils\CsvParser::parseString("1675281000,BER,tt,5.7\n1675281600,BER,tt,5.8");

Testing

Run composer test to execute the PHPUnit test suite.

Releasing

  1. Add changes to the changelog.
  2. Create a new tag vX.X.X.
  3. Push.

License

MIT.

Author

Christian Studer cstuder@existenz.ch, Bureau für digitale Existenz.