Plots2: add contributor_count method to Tag model

Created on 14 Nov 2017  Β·  17Comments  Β·  Source: publiclab/plots2

Hi, this is a first-timers-only issue. This means we've worked to make it more legible to folks who either haven't contributed to our codebase before, or even folks who haven't contributed to open source before.

If that's you, we're interested in helping you take the first step and can answer questions and help you out as you do. Note that we're especially interested in contributions from people from groups underrepresented in free and open source software!

If you have contributed before, consider leaving this one for someone new, and looking through our general help wanted issues. Thanks!

The problem

We need a generalized tag-based method, like Tag.contributor_count(tagname) for counting contributors. It'd also be great to count commenters, answerers, etc!

Solution

It could start with this code: https://github.com/publiclab/plots2/blob/master/app/controllers/tag_controller.rb#L216-L219

It could go in the Tag model: https://github.com/publiclab/plots2/blob/master/app/models/tag.rb

Here's some code to start, but we'd want to narrow these to collect only those tagged with tagname -- similar to this code: https://github.com/publiclab/plots2/blob/master/app/controllers/tag_controller.rb#L70-L74

But the general method would look like this:

def contributor_count(tagname)
  uids = Node.where(...).collect(&:uid)
  uids += Comment.where(...).collect(&:uid)
  uids += Answer.where(...).collect(&:uid)
  uids = uids.uniq
  uids.length
end

We'd of course want to unit test it! Unit tests for the Tag model live here: https://github.com/publiclab/plots2/tree/master/test/unit/tag_test.rb

(Follow-up issue: it could then be used to replace parts of #1028 and the code in https://github.com/publiclab/plots2/blob/master/app/controllers/tag_controller.rb#L216-L219)

Steps to Fix

  • [ ] claim this issue with a comment here, below, and ask any clarifying questions you need
  • [ ] set up a repository locally following the README instructions, and make sure that all tests pass
  • [ ] try to fix the issue following the steps above, but even before you're done, you can:
  • [ ] commit your changes and start a pull request (see contributing to Public Lab software) but mark it as "in progress" if you have questions or if you haven't finished
  • [ ] alert someone via the developers list (see below) to have your pull request merged. This may take a few extra steps depending on when you do it, but we'll help you out!

Please email the developers list (see https://publiclab.org/wiki/developers) or go to the chatroom if you have questions, and take a look at our first-timers landing page for more information!

enhancement first-timers-only help wanted

All 17 comments

Can I give it a go?

Yes please! Thank you!

On Nov 14, 2017 10:38 AM, "Vidit" notifications@github.com wrote:

Can I give it a go?

β€”
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/publiclab/plots2/issues/1774#issuecomment-344355423,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AABfJ3U0Lq9HbcPjLamwSvBvftW0zZ_Xks5s2d4qgaJpZM4QdzHL
.

Thanks @ViditChitkara ! Happy to give any support we can, we really appreciate your time thinking about this!

Hi, just checking if you've gotten stuck on this at all, or if I could help in any way? Thanks!

Hi, actually I am a bit busy with my exams. I'll open a PR ASAP. Applologies for the delay!!

no problem and good luck with your exams!

On Wed, Nov 29, 2017 at 2:13 PM, Vidit notifications@github.com wrote:

Hi, actually I am a bit busy with my exams. I'll open a PR ASAP.
Applologies for the delay!!

β€”
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/publiclab/plots2/issues/1774#issuecomment-347965222,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AABfJ6XoyW43ULnzAaQEPbPHZnoHJuMTks5s7azrgaJpZM4QdzHL
.

Thanks jeff, will surely do it ASAP.

Solved by @ViditChitkara !!! Fantastic.

As a follow-up, do you think it's possible to write a Tag.contributors which would collect all the users in an array? If you're interested, we'd LOVE to see this! I think it'd be pretty similar.

If we did a Tag.contributors we could then use it in this controller method, and show a wider range of people on that page:

https://github.com/publiclab/plots2/blob/f6fe2ea6273e30444bb2ccde131c0ae1bf6c8ea6/app/controllers/tag_controller.rb#L262-L272

Thanks @jywarren!! I am happy to do this but could you tell me on what basis should I select the contributors, like there are many possible ways in which a user could contribute. It would be great help if you give a little more details!ThanksπŸ˜„πŸ˜„

Hi, I think the way you implemented the count works well here too - people who've posted nodes, comments or answers on content with the given tag. Does that make sense? πŸ˜πŸ‘

Yes, it makes sense. However, I'll see if there are more ways of getting contributors which are associated with particular tag, else we could use this only!!!!πŸ˜ƒπŸ˜ƒ

Good idea... Maybe wiki page revisions by an author? Under Revision model.

On Dec 10, 2017 10:44 AM, "Vidit" notifications@github.com wrote:

Yes, it makes sense. However, I'll see if there are more ways of getting
contributors which are associated with particular tag, else we could use
this only!!!!πŸ˜ƒπŸ˜ƒ

β€”
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/publiclab/plots2/issues/1774#issuecomment-350557082,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AABfJ9NF6dslTvnTUbZI5hnpPnUFj5Ldks5s-_xKgaJpZM4QdzHL
.

Cool! So I'll make changes in this method only so that wiki page members are also there along with answerers, etc.!!!!πŸ˜‰πŸ˜‰

Super.

On Dec 10, 2017 11:01 AM, "Vidit" notifications@github.com wrote:

Cool! So I'll make changes in this method only so that wiki page members
are also there along with answerers, etc.!!!!πŸ˜‰πŸ˜‰

β€”
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/publiclab/plots2/issues/1774#issuecomment-350558188,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AABfJ76DyuOBSt4ce1ZmwB4JWDkwXVwuks5s_AAygaJpZM4QdzHL
.

this is a really exciting project -- thank you for helping!

--

+1 336-269-1539 / @lizbarry http://twitter.com/lizbarry / lizbarry.net

On Sun, Dec 10, 2017 at 11:14 AM, Jeffrey Warren notifications@github.com
wrote:

Super.

On Dec 10, 2017 11:01 AM, "Vidit" notifications@github.com wrote:

Cool! So I'll make changes in this method only so that wiki page members
are also there along with answerers, etc.!!!!πŸ˜‰πŸ˜‰

β€”
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<https://github.com/publiclab/plots2/issues/1774#issuecomment-350558188
,
or mute the thread
AABfJ76DyuOBSt4ce1ZmwB4JWDkwXVwuks5s_AAygaJpZM4QdzHL>
.

>

β€”
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/publiclab/plots2/issues/1774#issuecomment-350559184,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAJ2nzcdUEMlBsyqeQP7Bv3TRZ3H3DUGks5s_AN0gaJpZM4QdzHL
.

@ebarry surely this is exciting and I'm really happy to contribute to this. I have learnt a lot here and would keep contributing to this. Thank you and @jywarren for helping me out.

Was this page helpful?
0 / 5 - 0 ratings