承接 dantleech/data-table 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

dantleech/data-table

最新稳定版本:0.3

Composer 安装命令:

composer require dantleech/data-table

包简介

Represent and analyze tabular data

README 文档

README

ABANDONED: Use Tabular instead.

Build Status Scrutinizer Code Quality

The cellular library provides an object oriented way of building, representing and analyzing tabular data.

Features:

  • Supports aggregate functions sum, avg, min, max and median.
  • Aggreate functions can applied to Table, Row and Column.
  • Supports cell groups.
  • Callbacks can be applied to cells on whole, or selected groups of Table, Row and Column instances.
  • Produce grouped tables with callbacks - analagous to SELECT bar, SUM(foo) FROM sometable GROUP BY bar
  • Fluent table builder

Note that this library is under development.

Creating

Col 1 Col 2 Col 3
12 14 4
12 14 4

Would be created as follows:

$table = Table::create();
$table->createAndAddRow()
    ->set('col1', 12)
    ->set('col2', 14)
    ->set('col3', 4);
$table->createAndAddRow()
    ->set('col1', 12)
    ->set('col2', 14)
    ->set('col3', 4)

Or without the builder:

$table = new Table(
     new Row(array(
         'col1' => new Cell(12),
         'col2' => new Cell(14),
         'col3' => new Cell(4),
     )),
     new Row(array(
         'col1' => new Cell(12),
         'col2' => new Cell(14),
         'col3' => new Cell(4),
     )),
 );

Retrieving cell values

You can retrieve values from Table, Row and Column instances as follows:

$table->getValues(); // return an array containg all cell values
$table->getRow(0)->getValues();
$table->getColumn('col1')->getValues();

Groups

You apply groups to cells:

$table->createAndAddRow()
    ->set('hello, 'vaue', array('group1'));

var_dump($table->getCells(array('group1'))); // dump all cells in group1

$table->mapValues(function ($value) {
    return 'goodbye';
}, array('group1')); // set the value of all cells in group1 to "goodbye"

Using the Calculator

The calculator allows you to apply certain calculations to values, Cell instances or any instance of CellularInterface:

$mean = Calculator::mean($table); // return the mean (average) value of the table

$median = Calculator::median($table->getRow(0)); // return the median value of the first row

$deviation = Calculator::deviation(
    Calculator::mean($table->getColumn('col1')),
    $table->getRow(0)->getCell('col1')
); // return the deviation of "col1" in the first row as a percentage from the average value of "col1"

Current functions:

  • sum: Return the sum of values
  • min: Return the minimum value
  • max: Return the maximum value
  • mean: Return the mean (average) value
  • median: Return the median value
  • deviation: Return the deviation as a percentage

Partitioning and Forking

Table and Row instances provide the following methods:

  • partition: Internally divide the collection of elements according to a given callback.
  • aggregate: Aggregate the partitions of a table back to a single partition.

This is useful for creating summaries from multiple tables or rows:

For example:

$table
    ->partition(function ($row) {
        return $row['class'];
    })
    ->partition(function ($table, $newInstance) use ($cols, &$newCols, $options, $functions) {
        $newInstance->createAndAddRow()
            ->set(
                'number', 
                Calculator::sum($table->getColumn('number'))
            );
    });

The callback is passed each partition in turn alongisde a new instance of the collection class. The callback's responsiblity is to add new rows to the new instance, the primary partition of which will become the new primary partition for the collection upon which the operation is performed.

The result will be anagous to the following SQL: SELECT SUM(number) FROM table GROUP BY class.

Sorting

Sorting can be achieved as follows:

$table->sort(function ($row1, $row2) {
    return $row1['col1'] > $row2['col1'];
});

Evaluating values

Values can be evaluated as follows:

$sum = $table->evaluate(function ($row, $lastValue) {
    $lastValue += $row['cell']->getValue();
}, 0); // evaluates the sum of the column "cell"

The callback is passed the element and the previous result. The initial result is given as the second argument to evaluate.

Setting Attributes

It is possible to set attributes on Cell and Cellular instances. This is useful when you need to store metadata about the source of the data before it was transformed into cellular form.

$table->setAttribute('foo', 'bar');
$table->getAttribute('foo');
$table->hasAttribute('foo');

Other methods

  • filter: Filter the results by a closure. Returns a new instance.
  • clear: Clear the collection

dantleech/data-table 适用场景与选型建议

dantleech/data-table 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.46k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2015 年 05 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 dantleech/data-table 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 2.46k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-05-16