-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
group subscription tags with number of subscribers #5224
group subscription tags with number of subscribers #5224
Conversation
@publiclab/reviewers I need a review on this one please |
Generated by 🚫 Danger |
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.
This is fantastic!! 🎉 🎉
Thanks so much for working on this 🎈
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.
This was really nicely set up, easy to review, and you're almost there. I made a couple suggestions to simplify it even a little bit more, so that we just get a table of plain text, for now sorted by ranges of 10. This'll set us up really nicely for future refinements, too!
Thanks for writing a really clear PR and submitting a great screenshot of the feature working. And thanks for your help!
app/controllers/stats_controller.rb
Outdated
@@ -5,7 +5,7 @@ def subscriptions | |||
@tags[tag.tagname] = @tags[tag.tagname] || 0 | |||
@tags[tag.tagname] += 1 | |||
end | |||
render plain: @tags.inspect, status: 200 | |||
@tags = @tags.group_by { |_k, v| v }.map { |k, v| { k => v.map { |x| x.join("-") } } } |
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.
So let's take this for example:
> tags
=> {"boagd"=>3, "boa"=>34, "boag"=>39, "b"=>66}
see how if group by v/10 then 34 becomes 3, 66 becomes 6, so ones within 10 of each other get added to the same group?
> tags.group_by { |k, v| v/10 }
=> {0=>[["boagd", 3]], 3=>[["boa", 34], ["boag", 39]], 6=>[["b", 66]]}
I think the second map
is something we can do in the template though, since it relates to how we want to display the data. So i'll suggest:
@tags = @tags.group_by { |_k, v| v }.map { |k, v| { k => v.map { |x| x.join("-") } } } | |
@tags = @tags.group_by { |k, v| v/10 } | |
@tags = @tags.reverse # because it's naturally sorted "ascending", so let's flip it! |
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.
nice that the group is automatically sorted, too!
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.
Yes actually this works better and is way cleaner. The ruby hash doesn't have the reverse method though I think it's safe to use sort
?
<th>Tags</th> | ||
</thead> | ||
</tr> | ||
<% @tags.each do |map| %> |
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.
Here we could rename map
to group
, since each item in @tags
represents a group of tags.
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.
<% @tags.each do |map| %> | |
<% @tags.each do |range, tags| %> |
We could do this because the key will represent the range of numbers, and the value will contain the tags themselves, for example ['tagname', 46]
.
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.
oh alright. so I'll do away with joining tags to the count with hyphens (-)
</thead> | ||
</tr> | ||
<% @tags.each do |map| %> | ||
<% map.each do |subscriptions,tags| %> |
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.
Here we wouldn't have to unpack things, we could skip this line!
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.
Okay I'll just use the tags map as it is.
<% map.each do |subscriptions,tags| %> | ||
<tr> | ||
<tbody> | ||
<td><%=subscriptions%></td> |
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.
Here we could put this, because we'd want to expand back out to the full ranges (since we divided by 10 earlier) -- try this out:
<td><%=subscriptions%></td> | |
<td><% (range - 1) * 10 - <%= range*10 %></td> |
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.
<td> | ||
<select style="width: 50%; height: 50px;"> | ||
<%tags.each do |tag| %> | ||
<option><%=tag%></option> |
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.
Then here, I actually think we could just display a list of tags, one per line in plain text, not in a select, so just the tag's name, a colon, and the true count next to it -- remember each of these is in the format ['tagname', 888]
:
<p><%= tag[0] %>: <%= tag[1] %></p>
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.
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.
Huh, that is so weird. Let me look at the code, but I'm not sure why the <p>
tags aren't making newlines. We could try <br />
instead, between each line?
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.
No no. I hadn't used <p>
tags here.
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.
Just two more small changes and this is ready to merge! Great work!
<div class="col-md-8 col-md-offset-1"> | ||
<h2>Subscriptions</h2> | ||
</div> | ||
<table class="table inline-grid"> | ||
<tr> |
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.
Not a huge deal, but would you mind using just 2 spaces for indents? We've tried to standardize a bit on this to help keep our code tidier. Thanks, and sorry for the minute details! 😄
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.
yes of course. sorry I switched to a new editor that I'm still finding my way around. I'll fix that.
<tbody> | ||
<td><%= range * 10 %> - <%= range * 10 + 9 %></td> | ||
<% tags.each do |tag| %> | ||
<td><%= tag[0]%>:<%=tag[1] %></td> |
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.
Oh, aha - yes, so instead of the <td>
we need to also use <p>
tags - and the <td>
tags should go outside the each
loop. That way the whole collection will be in a single table cell, but each tag will be in its own paragraph (on its own line). Make sense?
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.
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.
Great! Actually let's tackle a few more things in a follow-up PR:
- let's sort this DESCENDING or
desc
so we start with the most-used tags - let's hide anything more than 25 results and show a "View all" link to show them?
- let's make the tag names into links that go to
/tag/TAGNAME
and we can do more! This is a great start!
…b.com/GettyOrawo/plots2 into classify-tags-with-subscriber-numbers
Hey @jywarren I cleared the suggested reviews. Any more fixes I need to do on this one? |
Congrats on merging your first pull request! 🙌🎉⚡️ Help others take their first stepNow that you've merged your first pull request, you're the perfect person to help someone else out with this challenging first step. 🙌 Try looking at this list of `first-timers-only` issues, and see if someone else is waiting for feedback, or even stuck! 😕 People often get stuck at the same steps, so you might be able to help someone get unstuck, or help lead them to some documentation that'd help. Reach out and be encouraging and friendly! 😄 🎉 Read about how to help support another newcomer here, or find other ways to offer mutual support here. |
Fantastic work!!! I'll open a new issue with the follow-ups. #5260 Thanks so much!!!! |
* group tags with number of subscribers * cleanup * fix codeclimate errors * refactoring the subscriber count range and stats display * fix codeclimate failing lint test * fix indent on stats view
* group tags with number of subscribers * cleanup * fix codeclimate errors * refactoring the subscriber count range and stats display * fix codeclimate failing lint test * fix indent on stats view
Fixes #4603
Display After Refactors
rake test
@publiclab/reviewers
for help, in a comment below