white-frame/statistics 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

white-frame/statistics

最新稳定版本:1.0

Composer 安装命令:

composer require white-frame/statistics

包简介

Tools for extracting statistics from a sql table

README 文档

README

Allows you to extract a Illuminate\Support\Collection of statistics about a set of dated Eloquent rows.

Features

  • Based on Carbon : for easy date management and for an easy integration with Eloquent
  • A simple Cache : for avoiding useless dupliated database queries
  • Custom interval and steps : allows you to change dates (start, end) and the steps (yearly, monthly, daily, hourly)
  • Return a Collection : a Illuminate\Support\Collection is returned for a simpler statistics handling
  • Indicator based : for a simple and comprehensive way of querying statistics datas

Installation

Install it with composer :

composer require ifnot/statistics

Usage

1 : Instanciate a Statistics object from a eloquent query :

use Ifnot\Statistics\Statistics;

// Get all validated sales (you can also take all with Sale::query())
$validSales = Sale::whereNotNull('validated_at');

// Put our sales into a Statistics object
$statistics = Statistics::of($validSales);

2 : Specify the date column and the interval for filtering datas :

use Ifnot\Statistics\Interval;

// If we want to build statistics about validation date of sales (it can be also of the creation date, 
// in this case we will use the eloquent created_at ...) 
$statistics->date('validated_at');

// Set the interval, the params :
// 1 : the interval, check the constants Interval::$DAILY, Interval::$MONTHLY etc ... or use the string "daily", "monthly" instead
// 2 : the start date with carbon
// 3 : the end date with carbon
$statistics->interval(Interval::$DAILY, Carbon::createFromFormat('Y-m-d', '2016-01-01'), Carbon::now())

3 : Add indicators :

// We want to count the sales with shipping and without shipping
$statistics->indicator('with_shipping', function($row) {
 return $row->shipping ? 1 : 0;
});
$statistics->indicator('without_shipping', function($row) {
 return $row->shipping ? 0 : 1;
});

// And count the sales with more than 500.00 € amount
$statistics->indicator('expensive_bough', function($row) {
 if($row->amount > 500.00) {
  return 1;
 } else {
  return 0;
 }
});

4 : Handle datas :

$collection = $statistics->make();

// Use a foreach if you want to loop on each dates
foreach($collection as $date => $values) {
 echo $date ' : ' . $values->expensive_bough;
}

// Use Collection methods for statistics
$collection->sum('with_shipping'); // Count the shipping
$collection->avg('with_shipping'); // Average shpping sales on each days on the interval (if you selected daily)
$collection->min('with_shipping'); // Minimum daily shipping on the interval
$collection->max('with_shipping');

// etc ...

Full Documentation

... Work here

white-frame/statistics 适用场景与选型建议

white-frame/statistics 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 378 次下载、GitHub Stars 达 13, 最近一次更新时间为 2015 年 11 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 white-frame/statistics 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 white-frame/statistics 我们能提供哪些服务?
定制开发 / 二次开发

基于 white-frame/statistics 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 378
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 13
  • 点击次数: 16
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 13
  • Watchers: 2
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: WTFPL
  • 更新时间: 2015-11-10