@code-penguin wrote:
Hi,
Does anyone here have experience with reporting nested data?
I have a working solution for this, but it isn't all that great, so I am looking for a different approach.As an example, let's consider the following use case:
- I log events with a category, action and name.
- I would like to have an API function that returns a JSON object with the number of events per category/action/name combinationIf I use the Piwik events API, I can only ever get data for two dimensions, not all three. For example, Events.getNameFromActionId will return the action and name, but category is missing. So what I currently do is call processRequest('Events.getCategory'), then for each category call processRequest('Events.getAction') with the category as segment, and for each action call processRequest('Events.getName') with the category and action as segment. However, this is obviously far from ideal, because there is a lot of (unnecessary) querying going on. In MySQL I can get the same dataset directly from the log data with a single query!
So I have been looking at generating a custom archive. The concept being that I can move most of the logic to the archiver, making sure that the nesting is preserved in the archive, and my custom API functions will only have to do minor processing. Unfortunately I haven't been able to get this to work correctly. The interesting thing is that the result of the query in Events/Archiver::aggregateDayEvents is exactly what I need, but when it is stored in the archive only one subDimension is preserved..
Any ideas on a better solution are welcome!
P.S. the return object could be something like this:
{
myCategory1:
{
myAction1:
{
myName1:
{
nb_events: 2
}
}
}
}
Or this:
{
{
category: myCategory1,
action: myAction1,
name: myName1,
nb_events: 2
}
}
Or even this:
{
myCategory1|myAction1|myName1:
{
nb_events: 2
}
}
As long as the full nesting is preserved!Cheers,
Posts: 1
Participants: 1