Flowframe / laravel-trend

Generate trends for your models. Easily generate charts or reports.
MIT License
606 stars 64 forks source link

dates in between excluding weekends or selected weekdays #54

Open hasajacykacperek opened 4 months ago

hasajacykacperek commented 4 months ago

Can the author add an exclude option to the between function so that I can enter which days of the week (weekends) are excluded from the data? The trend is a good form of data collection, but I don't know how I could exclude non-working days from my chart.

Zrzut ekranu 2024-02-27 o 21 16 06 Zrzut ekranu 2024-02-27 o 21 16 19

seansch commented 4 months ago

I'm curious about this as well, I have daily data that isn't updated on the weekends so my charts looks similar to yours.

seansch commented 4 months ago

I realized that Trend::model returns a Laravel collection and can be filtered, so I used a filter like this:

$data = $data->filter(function ($item) {
    return $item->aggregate > 0;
})->values();

Make sure you add values() to the end of your filter so it re-indexes the array keys(I fought with that for a while).

TwilightDuck commented 3 months ago

You can use the ::query() function to add SQL WHERE clause to filter out the weekends. DAYOFWEEK(booked_date) <> 1 AND DAYOFWEEK(booked_date)<>7