2017 © Pedro Peláez
 

library statistics

Vault component dedicated to store internal system statistics.

image

spiral/statistics

Vault component dedicated to store internal system statistics.

  • Thursday, April 27, 2017
  • by wolfy-j
  • Repository
  • 4 Watchers
  • 1 Stars
  • 4 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

statistics

Statistics module. Allows to track internal events, extract them for charts., (*1)

Latest Stable Version Total Downloads Scrutinizer Code Quality Coverage Status Build Status, (*2)

Installation

composer require spiral/statistics
spiral register spiral/statistics

Usage

How to add event to statistics

You can both track a single event or a batch of events, (*3)

/**
 * @var \Spiral\Statistics\Track $track
 */
$track->event('event name 1', 1, $datetime);
//OR
$track->events([
    'event name 2' => 2,
    'event name 3' => 3
],
    $datetime
);

$datetime is optional \DateTimeInterface variable, "now" is by default, (*4)

How to get events for a given period of time

/**
 * @var \Spiral\Statistics\Extract $extract
 * @var \Spiral\Statistics\Extract\RangeInterface $range
 * @var \Spiral\Statistics\Extract\Events $events
 *
 * $range is a grouping level, you can use one of supported ones, they are placed in
 * `\Spiral\Statistics\Extract\Range` namespace.
 */
$events = $extract->events($startDatetime, $endDatetime, $range, ['event name 1', 'event name 2']);

$startDatetime and $endDatetime will be swapped if $endDatetime is less than $startDatetime., (*5)

As a result, you can receive an array of \Spiral\Statistics\Extract\Events\Row objects, one row represents one range period., (*6)

/** @var \Spiral\Statistics\Extract\Events\Row $row */
foreach ($events->getRows() as $row) {
    echo $row->getLabel();  // is a period label
    echo $row->getEvents(); // contains all summarized events

    //For month range output will be like:
    //Label: 'Jan, 2017'
    //Events: ['event name1 ' => 1, 'event name2 ' => 2]
}

How to use fetched events

You can use fetched rows data as you wish, but we have included \Spiral\Statistics\Extract\DatasetInterface that can be useful if you're going to draw charts. The main idea is to use \Spiral\Statistics\Extract\Events and convert presented data in a special way. Here's an AbstractDataset class that implements DatasetInterface:, (*7)

<?php

namespace Spiral\Statistics\Extract\Dataset;

use Spiral\Statistics\Extract\DatasetInterface;
use Spiral\Statistics\Extract\Events;

abstract class AbstractDataset implements DatasetInterface
{
    /** @var Events\Row[] */
    protected $raw = [];

    /** @var array */
    protected $data = [];

    /**
     * {@inheritdoc}
     */
    public function setData(Events $events)
    {
        $this->raw = $events->getRows();
        $this->convert();
    }

    /**
     * Convert chart data if required.
     */
    abstract protected function convert();
}

```php <?php, (*8)

namespace Spiral\Statistics\Extract;, (*9)

interface DatasetInterface { /** * Set chart dataset data. Best place to convert it for current chart format. * * @param Events $events */ public function setData(Events $events);, (*10)

/**
 * Pack data to chart usage.
 *
 * @return array
 */
public function pack(): array;

}, (*11)


This package contains 2 dataset implementations for [Chart.js](https://chartjs.org) and for [Google Charts](https://developers.google.com/chart/). ```php /** * @var \Spiral\Statistics\Extract\Events $events */ $dataset = new \Spiral\Statistics\Extract\Dataset\ChartJsDataset([ 'event1' => [ 'label' => 'event one', ], 'event2' => [ 'label' => 'event two', ], ]); $dataset->setData($events); print_r($dataset->pack());

The Versions

27/04 2017

dev-master

9999999-dev

Vault component dedicated to store internal system statistics.

  Sources   Download

The Requires

 

The Development Requires

by Valentin V / vvval

27/04 2017

v1.0.0

1.0.0.0

Vault component dedicated to store internal system statistics.

  Sources   Download

The Requires

 

The Development Requires

by Valentin V / vvval

27/04 2017

dev-feature/v2

dev-feature/v2

Vault component dedicated to store internal system statistics.

  Sources   Download

The Requires

 

The Development Requires

by Valentin V / vvval

19/04 2017

v0.2.3

0.2.3.0

Vault component dedicated to store internal system statistics.

  Sources   Download

The Requires

 

The Development Requires

by Valentin V / vvval

05/04 2017

v0.2.2

0.2.2.0

Vault component dedicated to store internal system statistics.

  Sources   Download

The Requires

 

The Development Requires

by Valentin V / vvval

04/04 2017

v0.2.0

0.2.0.0

Vault component dedicated to store internal system statistics.

  Sources   Download

The Requires

 

The Development Requires

by Valentin V / vvval

04/04 2017

dev-feature/chart.js

dev-feature/chart.js

Vault component dedicated to store internal system statistics.

  Sources   Download

The Requires

 

The Development Requires

by Valentin V / vvval

10/03 2017

v0.1.4

0.1.4.0

Vault component dedicated to store internal system statistics.

  Sources   Download

The Requires

 

The Development Requires

by Valentin V / vvval

10/03 2017

v0.1.0

0.1.0.0

Vault component dedicated to store internal system statistics.

  Sources   Download

The Requires

 

The Development Requires

by Valentin V / vvval