Skip to content

Commit

Permalink
Replace fillEmptyData by fillMissingData
Browse files Browse the repository at this point in the history
Set fillMissingData as global method
Add groupBy methods for between period
Fix some bugs
Update README.md
  • Loading branch information
eliseekn committed Oct 28, 2023
1 parent b79cb98 commit a1d1f90
Show file tree
Hide file tree
Showing 18 changed files with 527 additions and 158 deletions.
3 changes: 3 additions & 0 deletions .idea/codeception.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/laravel-metrics.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/markdown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/phpspec.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to `laravel-metrics` will be documented in this file

## 2.7.0

- Replace fillEmptyData by fillMissingData
- Set fillMissingData as global method
- Add groupBy methods for between period
- Fix some bugs

## 2.6.1

- Add Combined periods and aggregates methods
Expand Down
87 changes: 75 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,6 @@ LaravelMetrics::query(...)
->forYear(int $year)
```

**Note :** Make sure to employ the 'fillEmptyDates' method when utilizing the 'between' period to automatically populate any missing dates with a default value. For example:

```php
LaravelMetrics::query(...)
->count()
->between(Carbon::now()->subDays(10)->format('Y-m-d'), Carbon::now()->format('Y-m-d'))
->fillEmptyDates()
->trends();
```

### Types of aggregates
```php
LaravelMetrics::query(...)
Expand All @@ -186,7 +176,7 @@ Combining different time periods and data aggregates can enhance your overall ex

```php
LaravelMetrics::query(...)
->sumByMonth()
->sumByYear()
->trends();

LaravelMetrics::query(...)
Expand All @@ -197,12 +187,85 @@ LaravelMetrics::query(...)

LaravelMetrics::query(...)
->countBetween([Carbon::now()->subDays(10)->format('Y-m-d'), Carbon::now()->format('Y-m-d')])
->fillEmptyDates()
->trends();

...
```

Possible combinations :

```php
LaravelMetrics::query(...)
->countByMonth(...) //or
->countByYear(...) //or
->countByDay(...) //or
->countByWeek(...) //or
->sumByMonth(...) //or
->sumByYear(...) //or
->sumByDay(...) //or
->sumByWeek(...) //or
->averageByMonth(...) //or
->averageByYear(...) //or
->averageByDay(...) //or
->averageByWeek(...) //or
->maxByMonth(...) //or
->maxByYear(...) //or
->maxByDay(...) //or
->maxByWeek(...) //or
->minByMonth(...) //or
->minByYear(...) //or
->minByDay(...) //or
->minByWeek(...) //or
->countBetween(...) //or
->sumBetween(...) //or
->averageBetween(...) //or
->maxBetween(...) //or
->minBetween(...)
```

### Fill missing data with default value
You can fill missing data with default value with the global method ```fillMissingData```, especially for trends. For example :

```php
LaravelMetrics::query(...)
->countBetween([Carbon::now()->subDays(10)->format('Y-m-d'), Carbon::now()->format('Y-m-d')])
->fillMissingData()
->trends();

LaravelMetrics::query(...)
->sumByYear(count: 5)
->fillMissingData()
->trends();

...
```

**Note :** For custom ```labelColumn```definition, you must define a ```missingDataLabel```. For example :

```php
LaravelMetrics::query(...)
->countByMonth(count: 12)
->forYear(now()->year)
->labelColumn('status')
->fillMissingData(missingDataLabels: [
'pending',
'delivered',
'cancelled'
])
->trends();
```

### Group period (only when using ```between``` method)
You can group period by days, months, weeks or years when using the ```between``` method. For example :

```php
LaravelMetrics::query(...)
->countBetween([Carbon::now()->subDays(10)->format('Y-m-d'), Carbon::now()->format('Y-m-d')])
->fillMissingData()
->groupByMonth()
->trends();
```

## Translations

Days and months names are automatically translated using `config(app.locale)` except 'week' period.
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"nesbot/carbon": "^2.69"
},
"require-dev": {
"laravel/pint": "^1.13",
"phpunit/phpunit": "^9.6"
},
"autoload": {
Expand Down
68 changes: 67 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a1d1f90

Please sign in to comment.