public function generateCustom($witness)
    {
        if (isset($this->custom[$witness->getSafeName()])) {
            return $this->custom[$witness->getSafeName()];
        }

        $history = CustomHistory::where('meta', $witness->getSafeName())->get()->groupBy(function($item) {
            return $item->created_at->format('Y-m-d');
        })->map(function ($row) {
            return round($row->filter(function($item) {
                return (! is_null($item->value));
            })->avg('value'), 2);
        });

        // Fill the array gaps - because the chart wont populate correctly without 0 values
        for($i=20; $i>=0; $i--) {
            $this->custom[$witness->getSafeName()]['day'][] = Carbon::now()->subDay($i)->format('d');

            if (isset($history[Carbon::now()->subDay($i)->format('Y-m-d')])) {
                $this->custom[$witness->getSafeName()]['count'][] = $history[Carbon::now()->subDay($i)->format('Y-m-d')];
            } else {
                $this->custom[$witness->getSafeName()]['count'][] = 0;
            }
        }

        return $this->custom[$witness->getSafeName()];
    }
public function generateCustom($witness)
    {
        if (isset($this->custom[$witness->getSafeName()])) {
            return $this->custom[$witness->getSafeName()];
        }

        $history = CustomHistory::where('meta', $witness->getSafeName())->get()->groupBy(function($item) {
            return $item->created_at->format('Y-m-d');
        })->map(function ($row) {
            return round($row->filter(function($item) {
                return (! is_null($item->value));
            })->avg('value'), 2);
        });

        // Fill the array gaps - because the chart wont populate correctly without 0 values
        for($i=20; $i>=0; $i--) {
            $this->custom[$witness->getSafeName()]['day'][] = Carbon::now()->subDay($i)->format('d');

            if (isset($history[Carbon::now()->subDay($i)->format('Y-m-d')])) {
                $this->custom[$witness->getSafeName()]['count'][] = $history[Carbon::now()->subDay($i)->format('Y-m-d')];
            } else {
                $this->custom[$witness->getSafeName()]['count'][] = 0;
            }
        }

        return $this->custom[$witness->getSafeName()];
    }
public function generateCustom ( $ witness ) { if ( isset ( $ this -> custom [ $ witness -> getSafeName ( ) ] ) ) { return $ this -> custom [ $ witness -> getSafeName ( ) ] ; } $ history = CustomHistory :: where ( 'meta' , $ witness -> getSafeName ( ) ) -> get ( ) -> groupBy ( function ( $ item ) { return $ item -> created_at -> format ( 'Y-m-d' ) ; } ) -> map ( function ( $ row ) { return round ( $ row -> filter ( function ( $ item ) { return ( ! is_null ( $ item -> value ) ) ; } ) -> avg ( 'value' ) , 2 ) ; } ) ; // Fill the array gaps - because the chart wont populate correctly without 0 values for ( $ i = 20 ; $ i >= 0 ; $ i -- ) { $ this -> custom [ $ witness -> getSafeName ( ) ] [ 'day' ] [ ] = Carbon :: now ( ) -> subDay ( $ i ) -> format ( 'd' ) ; if ( isset ( $ history [ Carbon :: now ( ) -> subDay ( $ i ) -> format ( 'Y-m-d' ) ] ) ) { $ this -> custom [ $ witness -> getSafeName ( ) ] [ 'count' ] [ ] = $ history [ Carbon :: now ( ) -> subDay ( $ i ) -> format ( 'Y-m-d' ) ] ; } else { $ this -> custom [ $ witness -> getSafeName ( ) ] [ 'count' ] [ ] = 0 ; } } return $ this -> custom [ $ witness -> getSafeName ( ) ] ; }
Get the witness data and transform it into the required format for our charts.

@param  \Eyewitness\Eye\Monitors\Custom  $witness
@return array
Get the witness data and transform it into the required format for our charts .