timothepearce/laravel-time-series 问题修复 & 功能扩展

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

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

timothepearce/laravel-time-series

Composer 安装命令:

composer require timothepearce/laravel-time-series

包简介

Laravel Time Series provides an API to create and maintain projected data from you Eloquent models, and represent them as time-series.

README 文档

README

LogoLogo

Latest unstable Version Download count

Build your time series with ease

About

Laravel Time Series provides an API to projects data from your Eloquent models, and convert them to time series.

Documentation

The full documentation can be found here.

Usage

Installation

composer require timothepearce/laravel-time-series

Migrate the tables

php artisan migrate

Create a Projection

php artisan make:projection MyProjection

Make a model projectable

When you want to make your model projectable, you must add it the Projectable trait and define the $projections class attribute:

use App\Models\Projections\MyProjection;
use TimothePearce\TimeSeries\Projectable;

class MyProjectableModel extends Model
{
    use Projectable;

    protected array $projections = [
        MyProjection::class,
    ];
}

If you want to use a different date field from your Model instead of created_at then do the following :

  1. Make sure the field is casted to Carbon
use App\Models\Projections\MyProjection;
use TimothePearce\TimeSeries\Projectable;

class MyProjectableModel extends Model
{
    use Projectable;

    protected $casts = [
        'other_date_time' => 'datetime:Y-m-d H:00',
    ];

    protected array $projections = [
        MyProjection::class,
    ];
}
  1. Add the dateColumn field in your Projection
namespace App\Models\Projections;

use Illuminate\Database\Eloquent\Model;
use TimothePearce\TimeSeries\Contracts\ProjectionContract;
use TimothePearce\TimeSeries\Models\Projection;

class MyProjection extends Projection implements ProjectionContract
{
    /**
     * The projected periods.
     */
    public array $periods = [];

    public string $dateColumn = 'other_date_time';
....

Implement a Projection

When you're implementing a projection, follow theses three steps:

Query a Projection

A Projection is an Eloquent model and is queried the same way, but keep in mind that the projections are all stored in a single table. That means you'll have to use scope methods to get the correct projections regarding the period you defined earlier:

MyProjection::period('1 day')
    ->between(
        today()->subDay(), // start date
        today(), // end date
    )
    ->get();

Query a time series

To get a time series from a projection model, use the toTimeSeries method:

MyProjection::period('1 day')
    ->toTimeSeries(
        today()->subDay(),
        today(),
    );

Note that this method fill the missing projections between the given dates with the default content you defined earlier.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 5.36k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 95
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 95
  • Watchers: 1
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-02-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固