Skip to content
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

Implement questions answered vs questions asked #4256

Merged
merged 4 commits into from
Dec 22, 2018

Conversation

cesswairimu
Copy link
Collaborator

@cesswairimu cesswairimu commented Dec 10, 2018

Fixes #4137

  • tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR -- or run tests locally with rake test
  • code is in uniquely-named feature branch and has no merge conflicts
  • PR is descriptively titled
  • ask @publiclab/reviewers for help, in a comment below

We're happy to help you get this ready -- don't be afraid to ask for help, and don't be discouraged if your tests fail at first!

If tests do fail, click on the red X to learn why by reading the logs.

Please be sure you've reviewed our contribution guidelines at https://publiclab.org/contributing-to-public-lab-software

Thanks!

@ghost ghost assigned cesswairimu Dec 10, 2018
@ghost ghost added the in progress label Dec 10, 2018
@plotsbot
Copy link
Collaborator

plotsbot commented Dec 10, 2018

1 Message
📖 @cesswairimu Thank you for your pull request! I’m here to help with some tips and recommendations. Please take a look at the list provided and help us review and accept your contribution! And don’t be discouraged if you see errors – we’re here to help.

Generated by 🚫 Danger

@jywarren
Copy link
Member

Hi! Just a hint - we can ignore the CodeClimate things, but sometimes they're really helpful suggestions. You can read them in detail and how to resolve them here: https://codeclimate.com/github/publiclab/plots2/pull/4256

public

def index
if params[:period]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a good one to cache daily! I think esp. with collecting a year's worth of content each page load.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great! thanks

@cesswairimu cesswairimu force-pushed the stats-on-questions branch 7 times, most recently from 946d3f0 to 0bdc26a Compare December 12, 2018 19:38
@cesswairimu
Copy link
Collaborator Author

past_year

@cesswairimu cesswairimu force-pushed the stats-on-questions branch 3 times, most recently from dc417cf to 2d477d9 Compare December 13, 2018 07:33
@cesswairimu
Copy link
Collaborator Author

cesswairimu commented Dec 13, 2018

Hey @gauravano @SidharthBansal @jywarren Kindly take a look and any suggestions on how I can best cache the stats here would be great. Thanks.

@grvsachdeva
Copy link
Member

As @jywarren mentioned we could cache for a day #4256 (comment)

we also cache home page data so you can see home_controller for reference. Let me know if you need help. Thanks!

@cesswairimu
Copy link
Collaborator Author

cesswairimu commented Dec 14, 2018

Hey @jywarren I did some refactoring and removed the whole bunch of instance variables. Does the caching I did on the questions helper method make sense? Thanks

SORTING_OPTIONS
end

def cache_quiz_stats
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works, but then people coding do have to remember to use the "cached version". Another way would be to build this inside the filtering() method itself, so all calls to that are filtered. If people really want the non-filtered version, they can manually flush it with... i forget but something like Rails.cache.flush(...). Make sense? This is exciting!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it does thanks, on it

@cesswairimu cesswairimu changed the title (WIP) Implement questions answered vs questions asked Implement questions answered vs questions asked Dec 16, 2018
@cesswairimu
Copy link
Collaborator Author

cesswairimu commented Dec 16, 2018

@jywarren this is ready @publiclab/reviewers this is ready kindly review

Copy link
Member

@jywarren jywarren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Cess, great work! I don't think we've as extensively used helpers before but I don't see a reason not to. Where do you think the bulk of statistics code would eventually live?

module QuestionsHelper
SORTING_OPTIONS = %w(All Week Month Year).freeze

def filtering(period)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good but perhaps it could have a more descriptive name -- something describing how it's related to stats, or Q&A? Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I'd love to see a simple test for these methods. Where would that live?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me try and figure out where the tests will go. Thanks


if period == 'All'
Rails.cache.fetch("all_stats", expires_in: 1.days) do
@asked = Node.questions.to_a.size
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if you use Node.questions.count it should do a more efficient query, just a SQL SIZE query instead of fetching all the full records and counting them. Maybe same on line below! 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jywarren tried .count was not working fine because its a hash returning results like so {82=>1, 85=>2, 86=>2, 87=>1}. Using .length instead. hope that's a better query?

</div>
<div class="col-md-4">
<%= form_tag request.url, :method => 'get' do %>
<%= select_tag :period, options_for_select(options),onchange: "this.form.submit();", include_blank: "Filter stats", class: "form-control"%>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh this is cool, could you share a screenshot? Thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jywarren a screenshot is ☝️ above. Thanks for the feedback.

@jywarren
Copy link
Member

Regarding the question of where statistics code "home base" is - would it fit in a model, so it's testable via unit tests? But open to ideas and brainstorming. Maybe ask @gauravano or @SidharthBansal for input on this as well!

@cesswairimu cesswairimu force-pushed the stats-on-questions branch 2 times, most recently from a8234a2 to cbf49d1 Compare December 20, 2018 16:52
@cesswairimu
Copy link
Collaborator Author

during
month

@jywarren I implemented the tests and changed the method name to a better name and improved the queries. Please take a look.

@cesswairimu
Copy link
Collaborator Author

Regarding the question of where statistics code "home base" is - would it fit in a model, so it's testable via unit tests? But open to ideas and brainstorming. Maybe ask @gauravano or @SidharthBansal for input on this as well!

@jywarren is this for this ticket #4317?

@jywarren
Copy link
Member

Actually it's more broad - that is, should we have a central location where we keep much of the statistics code, as if in a model, or should we be OK with some appearing in controllers, some in helpers... i'm just trying to think critically about how we're doing overall code organization. We don't have to come up with a final solution right now! Thanks!

@jywarren
Copy link
Member

This is great. Merging!!!

@jywarren jywarren merged commit 1802e62 into publiclab:master Dec 22, 2018
@ghost ghost removed the in progress label Dec 22, 2018
SrinandanPai pushed a commit to SrinandanPai/plots2 that referenced this pull request May 5, 2019
* implement questions answered vs questions asked

* Refactoring the questions stats

* caching questions stats

* test question helper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants