Esempio n. 1
0
 public function testCsvParserIterSkip()
 {
     $file = __DIR__ . "/../examples/testdata.csv";
     $parser = new CsvParser();
     $allconv = new ObjectArrayConverter();
     $allconv->setIteratorSource($parser->openFile(new File($file)));
     $allrecords = new ArrayList($allconv);
     $conv = new ObjectArrayConverter();
     $conv->setIteratorSource($parser->openFile(new File($file)), 2);
     $records = new ArrayList($conv);
     $conv2 = new ObjectArrayConverter();
     $conv2->setIteratorSource($parser->openFile(new File($file)), 2, 4);
     $records2 = new ArrayList($conv2);
     $this->assertSame('Hihi', $records->first()->Col2);
     $this->assertSame('Bar', $records->last()->Col1);
     $this->assertSame('Hihi', $records2->first()->Col2);
     $this->assertSame('An', $records2->last()->Col1);
     $this->assertSame(5, $records->length());
     $this->assertSame(7, $allrecords->length());
     $this->assertSame(3, $records2->length());
 }
Esempio n. 2
0
// 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) {
    return in_array($r->timestamp->format('Y-m-d'), $dates);
})->groupBy(function (ObjectArray $r) {
    return $r->timestamp->format('Y-m-d H:00');
});
L::line("Filter for last day:", $watch->stop()->result());
/**