Hi everyone, I have the collection below and I want to compute the average of all uptimes with the type API group by every day, how can I do that? I fetched all data from the table first, and I want to do calculations on it with the help of eloquent, I do not want to get average at first, I mean I want to find every day average uptime of API types. is there a good way to do so? I don't want to use chart data, think that I don't have any access to the model, I just should work with this collection.
thank you all,
To compute the average of all uptimes with the type API group by every day, you can use the groupBy() method to group the collection by date and type, and then use the avg() method to calculate the average uptime for each group. Here's an example:
This will return a new collection where the keys are the date and type of each group, and the values are the average uptimes for each group. You can then further manipulate this collection as needed.
Note that this assumes that the date attribute on your ChartData model is a Carbon instance or can be converted to one. If it's not, you may need to modify the groupBy() callback accordingly.