Merge lp:~intellectronica/launchpad/tags-cloud-improvement into lp:launchpad

Proposed by Eleanor Berger
Status: Merged
Approved by: Brad Crittenden
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~intellectronica/launchpad/tags-cloud-improvement
Merge into: lp:launchpad
Diff against target: None lines
To merge this branch: bzr merge lp:~intellectronica/launchpad/tags-cloud-improvement
Reviewer Review Type Date Requested Status
Brad Crittenden (community) release-critical Approve
Gavin Panella (community) code Approve
Review via email: mp+12220@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Eleanor Berger (intellectronica) wrote :

In the tags cloud portlet, only display official tags and the ten most popular unofficial ones.

Revision history for this message
Gavin Panella (allenap) wrote :

Hi Tom,

This is fine, but it's a bit ugly. It's difficult to understand, yet
it's a short view method. I have some suggestions, but I think it will
always be a slightly ugly method because of the mix of data that is
has to deal with. Oh well.

Approved, but consider my suggestions :)

Thanks, Gavin.

> === modified file 'lib/lp/bugs/browser/bugtarget.py'
> --- lib/lp/bugs/browser/bugtarget.py 2009-09-20 16:05:43 +0000
> +++ lib/lp/bugs/browser/bugtarget.py 2009-09-22 12:49:43 +0000
> @@ -1293,9 +1293,21 @@
> @property
> def tags_cloud_data(self):
> """The data for rendering a tags cloud"""
> - official_tags = set(self.context.official_bug_tags)
> + official_tags = self.context.official_bug_tags
> tags = self.getUsedBugTagsWithURLs()

Okay, this is a bit confusing because tags contains dicts. This could
perhaps be tags_with_urls?

> - tags.sort(key=itemgetter('tag'))
> + popular_tags = [tag['tag'] for tag in sorted(
> + [tag for tag in tags
> + if tag['tag'] not in official_tags],

This could be a generator expression instead of a list
comprehension. Either that, or do a list.sort() as a second step.

> + key=itemgetter('count'))[:10]]
> + tags = [
> + tag for tag in tags
> + if tag['tag'] in official_tags + popular_tags]

Gah, creating temporary lists every time around a loop. I guess there
aren't many items here, but this smells nevertheless.

> + for official_tag in official_tags:
> + if official_tag not in [tag['tag'] for tag in tags]:

This smells again. It's a little bit bad for performance, and a bit
worse for understanding.

> + tags.append({
> + 'tag': official_tag,
> + 'count': 0,
> + 'url': "+bugs?field.tag=%s" % urllib.quote(official_tag)})
> max_count = float(max([1] + [tag['count'] for tag in tags]))
> for tag in tags:
> if tag['tag'] in official_tags:
> @@ -1305,7 +1317,7 @@
> tag['factor'] = 1.5 + (tag['count'] / max_count)
> else:
> tag['factor'] = 1 + (tag['count'] / max_count)
> - return tags
> + return sorted(tags, key=itemgetter('tag'))
>
> @property
> def show_manage_tags_link(self):
>

review: Approve (code)
Revision history for this message
Eleanor Berger (intellectronica) wrote :

Thanks for the review. I have now renamed tags to tag_dicts and tag to tag_dict.

Revision history for this message
Brad Crittenden (bac) wrote :

Hi Tom,

I agree with Gavin that lines 12-15 should be broken into multiple statements. I read it a few times and before fully understanding the intent.

And at line 20 of your diff you are recalculating the list of tag['tag'] for each official tag. Move that list creation above the for loop.

With those changes you're ok to land on devel.

review: Approve (release-critical)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/bugs/browser/bugtarget.py'
2--- lib/lp/bugs/browser/bugtarget.py 2009-09-20 16:05:43 +0000
3+++ lib/lp/bugs/browser/bugtarget.py 2009-09-22 12:42:16 +0000
4@@ -1293,9 +1293,21 @@
5 @property
6 def tags_cloud_data(self):
7 """The data for rendering a tags cloud"""
8- official_tags = set(self.context.official_bug_tags)
9+ official_tags = self.context.official_bug_tags
10 tags = self.getUsedBugTagsWithURLs()
11- tags.sort(key=itemgetter('tag'))
12+ popular_tags = [tag['tag'] for tag in sorted(
13+ [tag for tag in tags
14+ if tag['tag'] not in official_tags],
15+ key=itemgetter('count'))[:10]]
16+ tags = [
17+ tag for tag in tags
18+ if tag['tag'] in official_tags + popular_tags]
19+ for official_tag in official_tags:
20+ if official_tag not in [tag['tag'] for tag in tags]:
21+ tags.append({
22+ 'tag': official_tag,
23+ 'count': 0,
24+ 'url': "+bugs?field.tag=%s" % urllib.quote(official_tag)})
25 max_count = float(max([1] + [tag['count'] for tag in tags]))
26 for tag in tags:
27 if tag['tag'] in official_tags:
28@@ -1305,7 +1317,7 @@
29 tag['factor'] = 1.5 + (tag['count'] / max_count)
30 else:
31 tag['factor'] = 1 + (tag['count'] / max_count)
32- return tags
33+ return sorted(tags, key=itemgetter('tag'))
34
35 @property
36 def show_manage_tags_link(self):