AI prompts
base on Generate metrics with ease and precision. ![Easy metrics banner](./art/banner.png)
<p align="center">
<a href="https://github.com/sakanjo/laravel-easy-metrics/actions"><img alt="Workflow status" src="https://img.shields.io/github/actions/workflow/status/sakanjo/laravel-easy-metrics/tests.yml?style=for-the-badge"></a>
<a href="https://laravel.com"><img alt="Laravel v10.x" src="https://img.shields.io/badge/Laravel-v10.x-FF2D20?style=for-the-badge&logo=laravel"></a>
<a href="https://php.net"><img alt="PHP 8.0" src="https://img.shields.io/badge/PHP-8.0-777BB4?style=for-the-badge&logo=php"></a>
</p>
<h1 align="center">🔥 Easy metrics</h1>
<p align="center">Easily create metrics for your application.</p>
> ✨ Help support the maintenance of this package by [sponsoring me](https://github.com/sponsors/sakanjo).
> Designed to work with **Laravel**, **Filament**, [Easy enum](https://github.com/sakanjo/laravel-easy-enum), and more.
![Preview](./art/preview.png)
## 🚀 Supported metrics
- **Bar** metric
- **Doughnut** metric
- **Line** metric
- **Pie** metric
- **Polar** metric
- **Trend** metric
- **Value** metric
Table of contents
=================
* [Install](#-install)
* [Usage](#-usage)
* [Value metric](#value-metric)
* [Doughnut metric](#doughnut-metric)
* [Trend metric](#trend-metric)
* [Other metrics](#other-metrics)
* [Ranges](#ranges)
* [Available custom ranges](#available-custom-ranges)
* [Growth rates](#growth-rates)
* [Using value metric](#using-value-metric)
* [Using trend metric](#using-trend-metric)
* [Using doughnut metric](#using-doughnut-metric)
* [Available growth rate types](#available-growth-rate-types)
* [Tips](#-tips)
* [using getLabel](#using-getLabel)
* [Practical examples](#-practical-examples)
* [Filamentphp v3 widgets](#filamentphp-v3-widgets)
* [Support the development](#-support-the-development)
* [Credits](#%EF%B8%8F-credits)
* [License](#-license)
## 📦 Install
```
composer require sakanjo/laravel-easy-metrics
```
## 🦄 Usage
### Value metric
```php
use SaKanjo\EasyMetrics\Metrics\Value;
use App\Models\User;
$data = Value::make(User::class)
->count();
```
#### Query types
The currently supported aggregate functions to calculate a given column compared to the previous time interval / range
##### Min
```php
Value::make(User::class)
->min('age');
```
##### Max
```php
Value::make(User::class)
->max('age');
```
##### Sum
```php
Value::make(User::class)
->sum('age');
```
##### Average
```php
Value::make(User::class)
->average('age');
```
##### Count
```php
Value::make(User::class)
->count();
```
### Doughnut metric
```php
use SaKanjo\EasyMetrics\Metrics\Doughnut;
use App\Models\User;
[$labels, $data] = Doughnut::make(User::class)
->count('gender');
```
#### Query types
The currently supported aggregate functions to calculate a given column compared to the previous time interval / range
##### Min
```php
Doughnut::make(User::class)
->min('age', 'gender');
```
##### Max
```php
Doughnut::make(User::class)
->max('age', 'gender');
```
##### Sum
```php
Doughnut::make(User::class)
->sum('age', 'gender');
```
##### Average
```php
Doughnut::make(User::class)
->average('age', 'gender');
```
##### Count
```php
Doughnut::make(User::class)
->count('gender');
```
### Trend metric
```php
use SaKanjo\EasyMetrics\Metrics\Trend;
use App\Models\User;
[$labels, $data] = Trend::make(User::class)
->countByMonths();
```
#### Query types
The currently supported aggregate functions to calculate a given column compared to the previous time interval / range
##### Min
```php
$trend->minByYears('age');
$trend->minByMonths('age');
$trend->minByWeeks('age');
$trend->minByDays('age');
$trend->minByHours('age');
$trend->minByMinutes('age');
```
##### Max
```php
$trend->maxByYears('age');
$trend->maxByMonths('age');
$trend->maxByWeeks('age');
$trend->maxByDays('age');
$trend->maxByHours('age');
$trend->maxByMinutes('age');
```
##### Sum
```php
$trend->sumByYears('age');
$trend->sumByMonths('age');
$trend->sumByWeeks('age');
$trend->sumByDays('age');
$trend->sumByHours('age');
$trend->sumByMinutes('age');
```
##### Average
```php
$trend->averageByYears('age');
$trend->averageByMonths('age');
$trend->averageByWeeks('age');
$trend->averageByDays('age');
$trend->averageByHours('age');
$trend->averageByMinutes('age');
```
##### Count
```php
$trend->countByYears();
$trend->countByMonths();
$trend->countByWeeks();
$trend->countByDays();
$trend->countByHours();
$trend->countByMinutes();
```
### Other metrics
- `Bar extends Trend`
- `Line extends Trend`
- `Doughnut extends Pie`
- `Polar extends Pie`
## Ranges
Every metric class contains a ranges method, that will determine the range of the results based on it's date column.
```php
use SaKanjo\EasyMetrics\Metrics\Trend;
use SaKanjo\EasyMetrics\Metrics\Enums\Range;
use App\Models\User;
Value::make(User::class)
->range(30)
->ranges([
15, 30, 365,
Range::TODAY, // Or 'TODAY'
]);
```
### Available custom ranges
- `Range::TODAY`
- `Range::YESTERDAY`
- `Range::MTD`
- `Range::QTD`
- `Range::YTD`
- `Range::ALL`
## Growth rates
Growth rate, expressed as both a **value** and a **percentage**, measures the change in a quantity over **time**, showing the speed of its expansion or contraction in both absolute and relative terms.
### Using **Value** metric
```php
use SaKanjo\EasyMetrics\Metrics\Value;
use SaKanjo\EasyMetrics\Enums\GrowthRateType;
use App\Models\User;
[$value, $growth] = Value::make(User::class)
->withGrowthRate()
->growthRateType(GrowthRateType::Value) // default is `Percentage`
->count();
```
### Using **Trend** metric
```php
use SaKanjo\EasyMetrics\Metrics\Trend;
use App\Models\User;
[$labels, $data, $growth] = Trend::make(User::class)
->withGrowthRate()
->countByYears();
```
### Using **Doughnut** metric
```php
use SaKanjo\EasyMetrics\Metrics\Doughnut;
use App\Models\User;
[$labels, $data, $growth] = Doughnut::make(User::class)
->withGrowthRate()
->count('gender');
```
### Available growth rate types
- `GrowthRateType::Value`
- `GrowthRateType::Percentage`
## 🔥 Tips
#### Using getLabel
You can use the `getLabel` method to customize the retreived data labels, for example:
```php
<?php
namespace App\Enums;
use SaKanjo\EasyEnum;
enum ExampleEnum: int
{
use EasyEnum; // Includes getLabel method
case Active = 0;
case Disabled = 1;
}
```
## 🔥 Practical examples
#### Filamentphp v3 widgets
```php
<?php
namespace App\Filament\Widgets\Admin;
use App\Models\User;
use Filament\Widgets\ChartWidget;
use SaKanjo\EasyMetrics\Metrics\Trend;
class UsersCountChart extends ChartWidget
{
protected static ?string $heading = 'Users count trend';
protected function getData(): array
{
[$labels, $data] = Trend::make(User::class)
->range($this->filter)
->rangesFromOptions($this->getFilters())
->countByMonths();
return [
'datasets' => [
[
'label' => 'Users',
'data' => $data,
],
],
'labels' => $labels,
];
}
protected function getType(): string
{
return 'line';
}
protected function getFilters(): ?array
{
return [
15 => '15 Months',
30 => '30 Months',
60 => '60 Months',
];
}
}
```
## 💖 Support the development
**Do you like this project? Support it by donating**
Click the ["💖 Sponsor"](https://github.com/sponsors/sakanjo) at the top of this repo.
## ©️ Credits
- [Salah Kanjo](https://github.com/sakanjo)
- [All Contributors](../../contributors)
## 📄 License
[MIT License](https://github.com/sakanjo/laravel-easy-metrics/blob/master/LICENSE) © 2023-PRESENT [Salah Kanjo](https://github.com/sakanjo)
", Assign "at most 3 tags" to the expected json: {"id":"3979","tags":[]} "only from the tags list I provide: [{"id":77,"name":"3d"},{"id":89,"name":"agent"},{"id":17,"name":"ai"},{"id":54,"name":"algorithm"},{"id":24,"name":"api"},{"id":44,"name":"authentication"},{"id":3,"name":"aws"},{"id":27,"name":"backend"},{"id":60,"name":"benchmark"},{"id":72,"name":"best-practices"},{"id":39,"name":"bitcoin"},{"id":37,"name":"blockchain"},{"id":1,"name":"blog"},{"id":45,"name":"bundler"},{"id":58,"name":"cache"},{"id":21,"name":"chat"},{"id":49,"name":"cicd"},{"id":4,"name":"cli"},{"id":64,"name":"cloud-native"},{"id":48,"name":"cms"},{"id":61,"name":"compiler"},{"id":68,"name":"containerization"},{"id":92,"name":"crm"},{"id":34,"name":"data"},{"id":47,"name":"database"},{"id":8,"name":"declarative-gui "},{"id":9,"name":"deploy-tool"},{"id":53,"name":"desktop-app"},{"id":6,"name":"dev-exp-lib"},{"id":59,"name":"dev-tool"},{"id":13,"name":"ecommerce"},{"id":26,"name":"editor"},{"id":66,"name":"emulator"},{"id":62,"name":"filesystem"},{"id":80,"name":"finance"},{"id":15,"name":"firmware"},{"id":73,"name":"for-fun"},{"id":2,"name":"framework"},{"id":11,"name":"frontend"},{"id":22,"name":"game"},{"id":81,"name":"game-engine "},{"id":23,"name":"graphql"},{"id":84,"name":"gui"},{"id":91,"name":"http"},{"id":5,"name":"http-client"},{"id":51,"name":"iac"},{"id":30,"name":"ide"},{"id":78,"name":"iot"},{"id":40,"name":"json"},{"id":83,"name":"julian"},{"id":38,"name":"k8s"},{"id":31,"name":"language"},{"id":10,"name":"learning-resource"},{"id":33,"name":"lib"},{"id":41,"name":"linter"},{"id":28,"name":"lms"},{"id":16,"name":"logging"},{"id":76,"name":"low-code"},{"id":90,"name":"message-queue"},{"id":42,"name":"mobile-app"},{"id":18,"name":"monitoring"},{"id":36,"name":"networking"},{"id":7,"name":"node-version"},{"id":55,"name":"nosql"},{"id":57,"name":"observability"},{"id":46,"name":"orm"},{"id":52,"name":"os"},{"id":14,"name":"parser"},{"id":74,"name":"react"},{"id":82,"name":"real-time"},{"id":56,"name":"robot"},{"id":65,"name":"runtime"},{"id":32,"name":"sdk"},{"id":71,"name":"search"},{"id":63,"name":"secrets"},{"id":25,"name":"security"},{"id":85,"name":"server"},{"id":86,"name":"serverless"},{"id":70,"name":"storage"},{"id":75,"name":"system-design"},{"id":79,"name":"terminal"},{"id":29,"name":"testing"},{"id":12,"name":"ui"},{"id":50,"name":"ux"},{"id":88,"name":"video"},{"id":20,"name":"web-app"},{"id":35,"name":"web-server"},{"id":43,"name":"webassembly"},{"id":69,"name":"workflow"},{"id":87,"name":"yaml"}]" returns me the "expected json"