Tuesday, February 28, 2017

Laravel for generating time specific reports

So I have an application and need to show some reports based on the time frame.

So the reports will be based on an event happened - success rate and am using MongoDB.

So these will be my report parameters.

Status                 | Total | Success | Failed | Success %

<5 Min                    50        40       10
>5 min <15 min            --        --       --
>15 min <hour             --        --       -- 

So my question is how to find all the records, which take less than 5 mins, count the total, count the failed, and count the success.

My query is given below, so based on the date range, first I have to sort down the records, after that, I have no idea how to find the difference between created_at and updated_at having status success and the time difference is less than 5 min, 5 to 15 and so on.

//convert the date to ISO to search in mongo
$from   = Carbon::createFromFormat('Y-m-d', '2017-02-20');
$to     = Carbon::createFromFormat('Y-m-d', '2017-02-21');

//select the sutiable app
$query  = MyCollection::where('app_id', '12345');

//refine the results to the only selected date range. 
//tried whereBetween here, but not seems to be working, 
//hence used chained where

$filter_dates = $query->where('created_at', '>=', $from)
        ->where('created_at', '<=', $to);


//Here I have to select the records like where created_at 
//and updated_at difference is like <5 mins, then next to 
//>5 min and <15 mins and so on. I am struck here.

$filter_by_time = $filter_dates->

Also please let me know if there is a better approach to achieve what am doing.




via Arun Code

Advertisement