L::line("Where user is userfoo.", $watch->stop()->result(), ",", $subc->length(), "records"); // groupby $watch->start(); $grouped = $collection->groupBy(function (OA $r) { return $r->username; }); // count records in groups $temp = $grouped->select(function (AL $c, $key) { return array("key" => $key, "count" => $c->length()); }); L::vdl($temp); L::line("Grouped by username.", $watch->stop()->result()); // select $watch->start(); L::vdl($grouped['userfoo']->select(function (OA $r) { return $r->uri; })); L::line("Select uris from userfoo.", $watch->stop()->result()); echo "\n"; // sum $watch->start(); $sum = $collection->sum(function (OA $r) { return $r->bytes; }); L::line("Sum of bytes:", $sum, $watch->stop()->result()); // avg $watch->start(); $avg = $collection->avg(function (OA $r) { return $r->bytes; }); L::line("Avg of bytes:", $avg, $watch->stop()->result());
$columns[] = array(8, number_format($records->avg(function ($v) { return $v->outdoor->hudperc; }), 2) . "%"); $columns[] = array(6, number_format($records->max(function ($v) { return $v->outdoor->hudperc; }), 2) . "%"); echo columnline($columns); } // Last 15 minutes $date = clone $list->last()->timestamp; $date->modify("-15 minutes"); $lastminutes = $list->where(function (ObjectArray $o) use($date) { return $o->timestamp >= $date; }); // Create JSON $avg = array("date" => date('c'), "indoortemp" => $lastminutes->avg(function (ObjectArray $o) { return $o->indoor->tempc; }), "outdoortemp" => $lastminutes->avg(function (ObjectArray $o) { return $o->outdoor->tempc; }), "airhumidity" => $lastminutes->avg(function (ObjectArray $o) { return $o->outdoor->hudperc; }), "pressure" => $lastminutes->avg(function (ObjectArray $o) { return $o->indoor->pressurehpa; }), "brightness" => $lastminutes->avg(function (ObjectArray $o) { return $o->brightness->lux; })); echo "\n"; L::vdl($avg); echo "\n"; L::line("Finished. Total time:", $total->stop()->result()); echo "\n";