-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Group results #42
base: main
Are you sure you want to change the base?
Conversation
Add a parameter to return raw SQL results
If requested, group the metric by dimensions
…on` class and use it to build the grouped dimensions.
I'm not against this, but I still have issues with naming... So this would introduce a single bool to deviate from the normal output for one usecase. I feel like if this gem were to provide alternative outputs, this could be generalized a bit. For example, maybe instead of a bool, it would be called something like Something like... ActiveReporting::Report.new(..., format: :values_only) Or... something. 🤷♂️ |
refactor: extract data formatting logic from `build_data` into its own private method
Hi @t27duck, I have refactored the params in line with your suggestions so the report now takes a symbol as a param called
In addition I thought about allowing a block to be passed to the
I am not 100% sure about this, it works okay but I have been calling I implemented a couple of tests to test and show how each of the implementations could be used. |
Passing the block does seem awkward... though I can see some utility in it. My concern is we're passing three things into the block and I can see a "need" in the future to pass in more "stuff"... The metric and raw data is probably the most important things people would need. Maybe we make the argument order in the If you can update the readme explaining these options with maybe an example, that would be great as well. Beyond that, this could be good to go. |
Continuing with Issue #41 I created a PR to demonstrate how we could group
metrics
by thedimensions
to allow for easy charting by some popular gems e.g. chartkick.The report object has a new option called
group_results
which can be passedtrue
orfalse
(default). The default behaviour is unchanged and will return an Array of Hashes with metric name / value and dimension labels / values e.g.Setting
group_results
to true will return a hash with the keys containing the dimensions values and the values containing the metrics values e.g.If no dimensions have been defined in the report, it groups by the metric label e.g.
This could be implemented as application logic in which case I think it would be helpful to expose the dimension names and metric names on the report object. This could help turn this
into this
I have not written any tests yet. I will look into this if the basic direction is okay.