KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Empty Datastore #892

Open Giulia Fois opened this topic on on May 27, 2019 - 2 comments

Giulia Fois commented on May 27, 2019

Hello, I'm trying to process and visualize my data in an exportable report. This is the my data processing (in the setup() function):

 $dsSetting = array(
	        'filePath' => dirname(__FILE__)."/csv/".$this->params["csv"],
	        'fieldSeparator' => ','
	    );
	    
	    
	    $src = new \koolreport\datasources\CSVDataSource($dsSetting, $this);
	    
	    $src->pipe(new Custom(function($row) {
	        $row["ts_from"] = str_replace(" UTC+00:00","", $row["ts_from"]);
	        return $row;
	    }))
	    ->pipe(new DateTimeFormat(array(
	        "ts_from" => array(
	            "from" => "d-m-Y H:i:s",
	            "to" => "d-M"
	        )
	    )))
	    ->pipe(new Filter(array(
	       array("sensor", "=", "geiger"),
	       array("avg", "!=", null),
	       array("min", "!=", null),
	       array("max", "!=", null)
	    )))
	    ->pipe(new Custom(function($row) {
	        $row["ts_from"] = array("v" => (int)$this->geiger_idx, "f" => $row["ts_from"]);
	        $this->geiger_idx ++ ;
	        return $row;
	    }))
	    ->pipe(new OnlyColumn(
	        array("ts_from", "avg", "min", "max", "qi")
	        ))
	    ->pipe(new AggregatedColumn(array(
	        "min_measure" => array("min", "min"),
	        "max_measure" => array("max", "max"),
	        "avg_measure" => array("avg", "avg"),
	        "qi" =>  array("avg", "qi")
	    )))
	    ->pipe($this->dataStore("csv_data_geiger"));

(printing rows in my Custom function works, so I'm sure data is correctly extracted from the csv file).

However, when I try to print my dataStore as follows (in my view file):

echo $this->dataStore('csv_data_geiger')->toJson();

it gives me the following result:

{"meta":{"columns":[]},"data":[]}

It turns out my dataStore is empty. What is the reason of that? Thank you!

KoolReport commented on May 27, 2019

The reason is that the datasource $src is not registered with report so when you call run(), it does not know that source to start pipe data. There are two solutions:

  1. You can specify the source settings in setting() function as we normally do and use $this->src("source_name")
  2. In the setup() function, in the last line ( after piping the dataStore) you call $src->start();. This will initiate the source piping process.

Hope that helps.

Giulia Fois commented on May 28, 2019

Thank you so much, the second solution worked perfectly :)

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed
solved

None