TimeBucket Process

This example shows the usage of TimeBucket process

orderDateamount
2018-10-01 100
2018-10-12 300
2018-10-23 200
2018-10-28 100
2018-11-03 300
2018-11-14 300
2018-11-16 400
2018-11-25 500
2018-12-03 200
2018-12-14 100
2018-12-17 200
2018-12-23 400

->pipe(new TimeBucket(array(
    "orderDate"=>"month"
)))
orderDateamount
2018-10 100
2018-10 300
2018-10 200
2018-10 100
2018-11 300
2018-11 300
2018-11 400
2018-11 500
2018-12 200
2018-12 100
2018-12 200
2018-12 400

->pipe(new Group(array(
    "by"=>"orderDate",
    "sum"=>"amount"
)))
orderDateamount
2018-10 700
2018-11 1,500
2018-12 900

The example demonstrates usage of TimeBucket process. The TimeBucket work on the datetime date and time column to put those date time into a separate bucket for example week, month or year. This process normally is used with Group process to provide grouping.

->pipe(new TimeBucket(array(
    "orderDate"=>"month"
)))
->pipe(new Group(array(
    "by"=>"orderDate",
    "sum"=>"amount"
)))
<?php
require_once "MyReport.php";

$report = new MyReport;
$report->run()->render();
<?php
//Step 1: Load KoolReport
require_once "../../../load.koolreport.php";

use \koolreport\processes\ColumnMeta;
use \koolreport\processes\TimeBucket;
use \koolreport\processes\Group;

//Step 2: Creating Report class
class MyReport extends \koolreport\KoolReport
{
    protected function settings()
    {
        return array(
            "dataSources"=>array(
                "data"=>array(
                    "class"=>'\koolreport\datasources\ArrayDataSource',
                    "dataFormat"=>"table",
                    "data"=>array(
                        array("orderDate","amount"),
                        array("2018-10-01",100),
                        array("2018-10-12",300),
                        array("2018-10-23",200),
                        array("2018-10-28",100),
                        array("2018-11-03",300),
                        array("2018-11-14",300),
                        array("2018-11-16",400),
                        array("2018-11-25",500),
                        array("2018-12-03",200),
                        array("2018-12-14",100),
                        array("2018-12-17",200),
                        array("2018-12-23",400),
                    )
                )
            )
        );
    }
    protected function setup()
    {
        //Prepare data
        $this->src("data")
        ->pipe(new ColumnMeta(array(
            "income"=>array(
                "type"=>"number",
                "prefix"=>"$"
            )
        )))
        ->saveTo($source);

        //Save orginal data
        $source->pipe($this->dataStore("origin"));
        
        //Pipe through process to get result
        $source->pipe(new TimeBucket(array(
            "orderDate"=>"month"
        )))->saveTo($result)
        ->pipe($this->dataStore("result"));
    
        $result->pipe(new Group(array(
            "by"=>"orderDate",
            "sum"=>"amount"
        )))
        ->pipe($this->dataStore("result_further"));
    }
}
<?php
    use \koolreport\widgets\koolphp\Table;
?>
<div class="report-content">
    <div class="text-center">
        <h1>TimeBucket Process</h1>
        <p class="lead">This example shows the usage of TimeBucket process</p>
    </div>
    
    <?php
    Table::create(array(
        "dataSource"=>$this->dataStore("origin"),
        "cssClass"=>array(
            "table"=>"table-bordered table-striped table-hover"
        )
    ));
    ?>

<i class="fa fa-arrow-down" style="font-size:24px;"></i>
<pre style="font-weight:bold"><code>
->pipe(new TimeBucket(array(
    "orderDate"=>"month"
)))
</code></pre>
<i class="fa fa-arrow-down" style="font-size:24px;"></i>

    <div style="margin-top:20px;">
    <?php
    Table::create(array(
        "dataSource"=>$this->dataStore("result"),
        "cssClass"=>array(
            "table"=>"table-bordered table-striped table-hover"
        )
    ));
    ?>
    </div>

<i class="fa fa-arrow-down" style="font-size:24px;"></i>
<pre style="font-weight:bold"><code>
->pipe(new Group(array(
    "by"=>"orderDate",
    "sum"=>"amount"
)))
</code></pre>
<i class="fa fa-arrow-down" style="font-size:24px;"></i>

    <div style="margin-top:20px;">
    <?php
    Table::create(array(
        "dataSource"=>$this->dataStore("result_further"),
        "cssClass"=>array(
            "table"=>"table-bordered table-striped table-hover"
        )
    ));
    ?>
    </div>



</div>

What People Are Saying

"KoolReport helps me very much in creating data report for my corporate! Keep up your good work!"
-- Alain Melsens

"The first use of your product. I was impressed by its easiness and powerfulness. This product is a great and amazing."
-- Dr. Lew Choy Onn

"Fantastic framework for reporting!"
-- Greg Schneider

Download KoolReport Get KoolReport Pro