Esempio n. 1
0
 public function testLineIterator()
 {
     $iterator = new LineIterator(new File(__DIR__ . "/../examples/testdata.txt"));
     $c = $iterator->count();
     $conv = new Converter();
     $conv->setIteratorSource($iterator, $c - 500);
     $list = new ArrayList($conv);
     $this->assertSame(500, $list->length());
     $conv2 = new Converter();
     $conv2->setIteratorSource($iterator, 0, 499);
     $list2 = new ArrayList($conv2);
     $this->assertSame(500, $list2->length());
 }
Esempio n. 2
0
 public function testIntersectExpect()
 {
     $test1 = array(array("a" => "foo", "b" => "bar", "c" => "foobar"), array("a" => "foo", "b" => "bar", "c" => "barfoo"));
     $test2 = array(array("a" => "foo", "b" => "bar", "c" => "foobar"), array("a" => "helloworld", "b" => "bar", "c" => "barfoo"));
     $expectedin = array(array("a" => "foo", "b" => "bar", "c" => "foobar"));
     $expectedex = array(array("a" => "foo", "b" => "bar", "c" => "barfoo"), array("a" => "helloworld", "b" => "bar", "c" => "barfoo"));
     $list1 = \PerrysLambda\ArrayList::asObjectArray($test1);
     $list2 = \PerrysLambda\ArrayList::asObjectArray($test2);
     $this->assertEquals($expectedin, $list1->intersect($list2)->serialize());
     $this->assertEquals($expectedex, $list1->except($list2)->serialize());
 }
Esempio n. 3
0
 * fuehrt einige Benchmarks durch.
 */
include __DIR__ . "/examples-utils.php";
// Lambda classes
use PerrysLambda\ObjectArray as OA;
use PerrysLambda\ArrayList as AL;
// Stopwatch
$total = new Stopwatch();
$watch = new Stopwatch();
$total->start();
// Memory usage on start
echo "\n";
L::line("Begin.");
// Basic example
$watch->start();
$test = new AL(array(1, 2, 3, 4, 5, 6, 7, 8, 9));
L::vdl($test->where(function ($v) {
    return $v > 5;
})->toArray());
L::line("Select values greater than X from simple array", $watch->stop()->result());
echo "\n";
// Parse JSON (testdata)
L::line("Filesize of JSON is", number_format(filesize(__DIR__ . "/testdata.json") / 1024, 2), "KB");
$watch->start();
$data = json_decode(file_get_contents(__DIR__ . "/testdata.json"), true);
L::line("Loaded data from JSON file.", $watch->stop()->result(), ",", count($data), "records");
// Load JSON data into lambda
$watch->start();
$collection = AL::asObjectArray($data);
// ArrayList<ObjectArray>
L::line("Data imported into Lambda.", $watch->stop()->result(), ",", $collection->length(), "records");
Esempio n. 4
0
 /**
  * Constructor
  * @param \PerrysLambda\IO\DirectoryConverter $dirconv
  */
 public function __construct(DirectoryConverter $dirconv)
 {
     $dirconv->setItemtype($this->getFileClassType());
     parent::__construct($dirconv);
 }
Esempio n. 5
0
$conv = new Converter();
$conv->setRowConverter(new Serializer($rowser, $rowdeser));
// Field converters (string to number or datetime)
$conv->setFieldConverter('timestamp', new SerDateTime("Y-m-d\\TH:i:s.uO", new \DateTimeZone("Europe/Berlin")));
// Read testdata line by line
$iterator = new LineIterator(new File(__DIR__ . "/testdata.txt"));
// Load only last 500 records
$c = $iterator->count();
$conv->setIteratorSource($iterator);
L::line("Converter created:", $watch->stop()->result());
/**
 * Create list and filter / group
 */
// Create list
$watch->start();
$list = new ArrayList($conv);
L::line("Data imported:", $watch->stop()->result());
// Stats
echo "\n";
L::line($list->length(), "records");
L::line("First record:", $list->first()->timestamp->format('Y-m-d H:i:s'));
L::line("Last record:", $list->last()->timestamp->format('Y-m-d H:i:s'));
echo "\n";
// Only the newest day, group by hour
$watch->start();
$dates = $list->distinct(function ($v) {
    return $v->timestamp->format('Y-m-d');
})->take(-2)->select(function ($v) {
    return $v->timestamp->format('Y-m-d');
});
$hours = $list->where(function (ObjectArray $r) use($list, $dates) {