-
Notifications
You must be signed in to change notification settings - Fork 139
[WIP] (#63) Add a /stats sub-endpoint #181
Conversation
* Syntax is WIP; needs to be reviewed * We should have an API spec test - tbd.
|
@siruguri this is pretty sweet. Since the metrics are delivered with the results anyhow, I don't think need the /stats endpoint, especially since @yozlet added the _ prefix to all of the option params. I think it would be nice to have consistent naming -- I like the option _metrics and would use that same name for DataMagic.search option instead of add_aggregations. let's get feedback from @shawnbot and/or @yozlet before finalizing the naming Thank you so much! |
|
All sounds good ... will wait for more fdbk. Will rebase to @yozley's On Sun, Sep 13, 2015 at 11:44 PM, Sarah Allen [email protected]
|
|
@ultrasaurus I still think that it'd be better to have a separate endpoint for stats. In our case, we need to display stats for a larger subset of the data than we're fetching to display. For instance, we need the median value of three fields for a large subset of schools (common to all searches), but then we need to query the API for a specific subset determined by the search parameters. Having these separated into two different requests should actually improve performance because the stats queries can be cached separately. |
|
For reference this is the current output of the API: |
|
I think @ultrasaurus is implying that without the _metrics option, metrics are NOT calculated. So the use case @shawnbot describes would be something like:
Does that describe what both of you are looking to do? |
|
@siruguri I think it does, but in that case I don't care about the results in the first request, and in the case of College Scorecard they could increase the payload size significantly. I guess that limiting the fields would help, but you'd still end up with 20 objects * 3 properties in the Also with College Scorecard (and, I imagine, in most apps), there are lots of fields that we need to display that we don't necessarily want stats for. In fact, I'm having a hard time imagining a scenario in which you would only want to get the fields that you've summarized. What happens, for instance, when you want the I guess what I'm suggesting is that there aren't many use cases for getting results and stats in the same request, and that overloading the results endpoint with stats capabilities might lead to confusion, both in the code and among API users. |
|
I could implement it so that _metrics takes one of two values - included Tbc, I don't really care - if you give me the final word, I'll go that way On Tue, Sep 15, 2015 at 11:08 AM, Shawn Allen [email protected]
|
lib/data_magic/document_builder.rb
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this addition about? Looks like it's related to the test you added to api_spec.rb - is that right?
|
I'm inclined towards @shawnbot's take on the API design, specifically that
|
|
I like this direction! I think we're talking about an API that looks like this: that would generate results that look like this: |
|
What branch shd I rebase to before continuing to work on this? dev? |
|
Yep. |
|
BTW, I recommend breaking the |
|
@yozlet - For re-factoring, maybe pull the params management out into a module in I am not sure if the routing/controller code's ready for re-factoring already ... maybe a third endpoint will inform it a bit better? I can see cleaning up |
|
Oh, sorry, I didn't mean to go as far as breaking everything out into separate files (though if that's where refactoring takes us, then sure). More just adding an additional |
|
Ah, ok. Got it, yes, that makes sense. On Thu, Sep 24, 2015 at 10:56 AM, Yoz Grahame [email protected]
|
|
Hey @siruguri, many apologies for the slowness around this PR. We're about to get funding to continue work on Open Data Maker so hopefully things should move faster soon. Many thanks for sticking with us! |
app/controllers.rb
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the if clause returns a boolean anyway, you can just have it be the body of the method without the if/else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, idk why my brain doesn't notice these redundant blocks.
* Allow /stats to not be given _metrics option * Re-factor code in controllers to separate /stats from main endpoint * Remove result hits from aggregation payload in /stats * Remove stray debugging cruft * Refactor error checking * Fix comments position
ed5922b to
f93aece
Compare
|
FYI, I pushed an amended commit with the edits from today's discussion, but without rebasing to dev. |
|
@siruguri Thanks for the update! However, it looks like you have a failing test - see the Travis CI failure. |
|
Sorry, I didn't realize that the test would fail on Travis - it's because On Mon, Nov 9, 2015 at 3:21 PM, Yoz Grahame [email protected]
|
|
@siruguri that is likely fine -- plenty of other things we need to do on this project, though I feel bad that you keep having to rebase! Let us know if you prefer we pick it up and integrate it. Otherwise we'll only do that if it (unexpectedly) becomes a critical feature in the interim. |
5d0adcc to
b662c95
Compare
|
Ok, I'm back from vacation! :) I merged in |
|
YAY! Almost there, just one last question: What's that |
|
Thank you so much for sticking with us! |
|
Oh, duh, sorry, I see what happened - the |
|
They were generated by On Tue, Dec 8, 2015 at 3:32 PM, Yoz Grahame [email protected]
|
|
No, because you'll delete the |
|
@siruguri WOOHOO! Thank you so much for this fantastic contribution! |
[WIP] (#63) Add a /stats sub-endpoint
|
:) Love the meme. On Tue, Dec 8, 2015 at 6:04 PM, Yoz Grahame [email protected]
|
|
👍 🎉 🎈 |

localhost:3000/v1/cities/stats?state=TX&fields=population,land_area&_metrics=avg,max,sum_of_squaresworksspec/features/api_spec.rb