GitHub PullRequestReviewCommentEvent at 2014-10-23 22:09:01
Repository: unshred-tag
Actor: dchaplinsky
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/dchaplinsky/unshred-tag/pulls/comments/19311438","id":19311438,"diff_hunk":"@@ -0,0 +1,83 @@\n+#!env python\n+\n+from __future__ import division\n+\n+from itertools import combinations, islice\n+from fn.iters import grouper\n+\n+from app import db\n+from models import Shreds, ShredsDistances\n+\n+BULK_INSERT_SIZE = 100000\n+SHREDS_CAP = 10000\n+TAGS_REPEATS = 2\n+\n+\n+def jaccard_distance(tags_a, tags_b):\n+    \"\"\"\n+    0 <= J <= 1\n+    0 - tags_a & tags_a sets are equal\n+    1 - tags_a have nothing in common with tags_b\n+\n+    See http://en.wikipedia.org/wiki/Jaccard_index for details\n+    \"\"\"\n+    return 1 - len(tags_a.intersection(tags_b)) / len(tags_a.union(tags_b))\n+\n+\n+def jaccard_distances_iterator(shreds_tags, input_cap=SHREDS_CAP):\n+    \"\"\"\n+    You can take only first `input_cap` items from `shreds_tags` iterable.\n+    Usefull for debugging and test runs.\n+    \"\"\"\n+\n+    for shred_a, shred_b in combinations(islice(shreds_tags.items(), 0, input_cap), 2):\n+        shred_a_id, tags_a = shred_a\n+        shred_b_id, tags_b = shred_b\n+        yield shred_a_id, shred_b_id, jaccard_distance(set(tags_a), set(tags_b))\n+\n+\n+def fetch_normalized_shreds_tags():\n+    \"\"\"\n+    Returns dictionary where keys are shreds ids and values are sets of\n+    filtered(soon) normalized tags.\n+    \"\"\"\n+    shreds = Shreds.objects().only('id', 'tags.tags')\n+    shreds_tags = {}\n+    for s in shreds:\n+        tags = s.get_repeated_tags(TAGS_REPEATS)\n+        if tags:\n+            shreds_tags[s.id] = tags\n+    return shreds_tags\n+\n+\n+def churn_jaccard():\n+    \"\"\"\n+    We'll be working with pre-created list of ShredsDistances documents - s_distances\n+    This way we don't spend CPU cycles & mallocs to create millions of\n+    objects to be thrown away.\n+\n+    It would be even more efficient to not create these documents at all\n+    and insert raw data into mongo, but I haven't dug deep enough.\n+    \"\"\"\n+\n+    shreds_tags = fetch_normalized_shreds_tags()\n+    s_distances = [ShredsDistances() for _ in xrange(BULK_INSERT_SIZE)]\n+\n+    for distances in grouper(BULK_INSERT_SIZE, jaccard_distances_iterator(shreds_tags)):\n+        for i, dist in enumerate(distances):\n+            if dist:\n+                a, b, d = dist","path":"metrics.py","position":69,"original_position":69,"commit_id":"509a0e9f591faaf7f65acc5e27eedab93feda3fa","original_commit_id":"509a0e9f591faaf7f65acc5e27eedab93feda3fa","user":{"login":"dchaplinsky","id":131186,"avatar_url":"https://avatars.githubusercontent.com/u/131186?v=2","gravatar_id":"","url":"https://api.github.com/users/dchaplinsky","html_url":"https://github.com/dchaplinsky","followers_url":"https://api.github.com/users/dchaplinsky/followers","following_url":"https://api.github.com/users/dchaplinsky/following{/other_user}","gists_url":"https://api.github.com/users/dchaplinsky/gists{/gist_id}","starred_url":"https://api.github.com/users/dchaplinsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dchaplinsky/subscriptions","organizations_url":"https://api.github.com/users/dchaplinsky/orgs","repos_url":"https://api.github.com/users/dchaplinsky/repos","events_url":"https://api.github.com/users/dchaplinsky/events{/privacy}","received_events_url":"https://api.github.com/users/dchaplinsky/received_events","type":"User","site_admin":false},"body":"Better variable names","created_at":"2014-10-23T22:09:01Z","updated_at":"2014-10-23T22:09:01Z","html_url":"https://github.com/dchaplinsky/unshred-tag/pull/59#discussion_r19311438","pull_request_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/pulls/59","_links":{"self":{"href":"https://api.github.com/repos/dchaplinsky/unshred-tag/pulls/comments/19311438"},"html":{"href":"https://github.com/dchaplinsky/unshred-tag/pull/59#discussion_r19311438"},"pull_request":{"href":"https://api.github.com/repos/dchaplinsky/unshred-tag/pulls/59"}}},"pull_request":{"url":"https://api.github.com/repos/dchaplinsky/unshred-tag/pulls/59","id":23263324,"html_url":"https://github.com/dchaplinsky/unshred-tag/pull/59","diff_url":"https://github.com/dchaplinsky/unshred-tag/pull/59.diff","patch_url":"https://github.com/dchaplinsky/unshred-tag/pull/59.patch","issue_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/issues/59","number":59,"state":"open","locked":false,"title":"Jaccard distances calculation","user":{"login":"z4y4ts","id":453047,"avatar_url":"https://avatars.githubusercontent.com/u/453047?v=2","gravatar_id":"","url":"https://api.github.com/users/z4y4ts","html_url":"https://github.com/z4y4ts","followers_url":"https://api.github.com/users/z4y4ts/followers","following_url":"https://api.github.com/users/z4y4ts/following{/other_user}","gists_url":"https://api.github.com/users/z4y4ts/gists{/gist_id}","starred_url":"https://api.github.com/users/z4y4ts/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/z4y4ts/subscriptions","organizations_url":"https://api.github.com/users/z4y4ts/orgs","repos_url":"https://api.github.com/users/z4y4ts/repos","events_url":"https://api.github.com/users/z4y4ts/events{/privacy}","received_events_url":"https://api.github.com/users/z4y4ts/received_events","type":"User","site_admin":false},"body":"","created_at":"2014-10-23T22:04:32Z","updated_at":"2014-10-23T22:09:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3104c6677b06ae48b4150c17ba14932673b020e8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/pulls/59/commits","review_comments_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/pulls/59/comments","review_comment_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/pulls/comments/{number}","comments_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/issues/59/comments","statuses_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/statuses/509a0e9f591faaf7f65acc5e27eedab93feda3fa","head":{"label":"z4y4ts:master","ref":"master","sha":"509a0e9f591faaf7f65acc5e27eedab93feda3fa","user":{"login":"z4y4ts","id":453047,"avatar_url":"https://avatars.githubusercontent.com/u/453047?v=2","gravatar_id":"","url":"https://api.github.com/users/z4y4ts","html_url":"https://github.com/z4y4ts","followers_url":"https://api.github.com/users/z4y4ts/followers","following_url":"https://api.github.com/users/z4y4ts/following{/other_user}","gists_url":"https://api.github.com/users/z4y4ts/gists{/gist_id}","starred_url":"https://api.github.com/users/z4y4ts/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/z4y4ts/subscriptions","organizations_url":"https://api.github.com/users/z4y4ts/orgs","repos_url":"https://api.github.com/users/z4y4ts/repos","events_url":"https://api.github.com/users/z4y4ts/events{/privacy}","received_events_url":"https://api.github.com/users/z4y4ts/received_events","type":"User","site_admin":false},"repo":{"id":23115808,"name":"unshred-tag","full_name":"z4y4ts/unshred-tag","owner":{"login":"z4y4ts","id":453047,"avatar_url":"https://avatars.githubusercontent.com/u/453047?v=2","gravatar_id":"","url":"https://api.github.com/users/z4y4ts","html_url":"https://github.com/z4y4ts","followers_url":"https://api.github.com/users/z4y4ts/followers","following_url":"https://api.github.com/users/z4y4ts/following{/other_user}","gists_url":"https://api.github.com/users/z4y4ts/gists{/gist_id}","starred_url":"https://api.github.com/users/z4y4ts/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/z4y4ts/subscriptions","organizations_url":"https://api.github.com/users/z4y4ts/orgs","repos_url":"https://api.github.com/users/z4y4ts/repos","events_url":"https://api.github.com/users/z4y4ts/events{/privacy}","received_events_url":"https://api.github.com/users/z4y4ts/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/z4y4ts/unshred-tag","description":"Flask/Mongo app to manually tag shreds. Experimental, volatile, unstable. No english translation yet, sorry.","fork":true,"url":"https://api.github.com/repos/z4y4ts/unshred-tag","forks_url":"https://api.github.com/repos/z4y4ts/unshred-tag/forks","keys_url":"https://api.github.com/repos/z4y4ts/unshred-tag/keys{/key_id}","collaborators_url":"https://api.github.com/repos/z4y4ts/unshred-tag/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/z4y4ts/unshred-tag/teams","hooks_url":"https://api.github.com/repos/z4y4ts/unshred-tag/hooks","issue_events_url":"https://api.github.com/repos/z4y4ts/unshred-tag/issues/events{/number}","events_url":"https://api.github.com/repos/z4y4ts/unshred-tag/events","assignees_url":"https://api.github.com/repos/z4y4ts/unshred-tag/assignees{/user}","branches_url":"https://api.github.com/repos/z4y4ts/unshred-tag/branches{/branch}","tags_url":"https://api.github.com/repos/z4y4ts/unshred-tag/tags","blobs_url":"https://api.github.com/repos/z4y4ts/unshred-tag/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/z4y4ts/unshred-tag/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/z4y4ts/unshred-tag/git/refs{/sha}","trees_url":"https://api.github.com/repos/z4y4ts/unshred-tag/git/trees{/sha}","statuses_url":"https://api.github.com/repos/z4y4ts/unshred-tag/statuses/{sha}","languages_url":"https://api.github.com/repos/z4y4ts/unshred-tag/languages","stargazers_url":"https://api.github.com/repos/z4y4ts/unshred-tag/stargazers","contributors_url":"https://api.github.com/repos/z4y4ts/unshred-tag/contributors","subscribers_url":"https://api.github.com/repos/z4y4ts/unshred-tag/subscribers","subscription_url":"https://api.github.com/repos/z4y4ts/unshred-tag/subscription","commits_url":"https://api.github.com/repos/z4y4ts/unshred-tag/commits{/sha}","git_commits_url":"https://api.github.com/repos/z4y4ts/unshred-tag/git/commits{/sha}","comments_url":"https://api.github.com/repos/z4y4ts/unshred-tag/comments{/number}","issue_comment_url":"https://api.github.com/repos/z4y4ts/unshred-tag/issues/comments/{number}","contents_url":"https://api.github.com/repos/z4y4ts/unshred-tag/contents/{+path}","compare_url":"https://api.github.com/repos/z4y4ts/unshred-tag/compare/{base}...{head}","merges_url":"https://api.github.com/repos/z4y4ts/unshred-tag/merges","archive_url":"https://api.github.com/repos/z4y4ts/unshred-tag/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/z4y4ts/unshred-tag/downloads","issues_url":"https://api.github.com/repos/z4y4ts/unshred-tag/issues{/number}","pulls_url":"https://api.github.com/repos/z4y4ts/unshred-tag/pulls{/number}","milestones_url":"https://api.github.com/repos/z4y4ts/unshred-tag/milestones{/number}","notifications_url":"https://api.github.com/repos/z4y4ts/unshred-tag/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/z4y4ts/unshred-tag/labels{/name}","releases_url":"https://api.github.com/repos/z4y4ts/unshred-tag/releases{/id}","created_at":"2014-08-19T15:42:15Z","updated_at":"2014-08-20T21:34:32Z","pushed_at":"2014-10-23T22:02:05Z","git_url":"git://github.com/z4y4ts/unshred-tag.git","ssh_url":"git@github.com:z4y4ts/unshred-tag.git","clone_url":"https://github.com/z4y4ts/unshred-tag.git","svn_url":"https://github.com/z4y4ts/unshred-tag","homepage":null,"size":411,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"dchaplinsky:master","ref":"master","sha":"8f013c512b6a5de219227e6ad654d7323d1aa412","user":{"login":"dchaplinsky","id":131186,"avatar_url":"https://avatars.githubusercontent.com/u/131186?v=2","gravatar_id":"","url":"https://api.github.com/users/dchaplinsky","html_url":"https://github.com/dchaplinsky","followers_url":"https://api.github.com/users/dchaplinsky/followers","following_url":"https://api.github.com/users/dchaplinsky/following{/other_user}","gists_url":"https://api.github.com/users/dchaplinsky/gists{/gist_id}","starred_url":"https://api.github.com/users/dchaplinsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dchaplinsky/subscriptions","organizations_url":"https://api.github.com/users/dchaplinsky/orgs","repos_url":"https://api.github.com/users/dchaplinsky/repos","events_url":"https://api.github.com/users/dchaplinsky/events{/privacy}","received_events_url":"https://api.github.com/users/dchaplinsky/received_events","type":"User","site_admin":false},"repo":{"id":21550556,"name":"unshred-tag","full_name":"dchaplinsky/unshred-tag","owner":{"login":"dchaplinsky","id":131186,"avatar_url":"https://avatars.githubusercontent.com/u/131186?v=2","gravatar_id":"","url":"https://api.github.com/users/dchaplinsky","html_url":"https://github.com/dchaplinsky","followers_url":"https://api.github.com/users/dchaplinsky/followers","following_url":"https://api.github.com/users/dchaplinsky/following{/other_user}","gists_url":"https://api.github.com/users/dchaplinsky/gists{/gist_id}","starred_url":"https://api.github.com/users/dchaplinsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dchaplinsky/subscriptions","organizations_url":"https://api.github.com/users/dchaplinsky/orgs","repos_url":"https://api.github.com/users/dchaplinsky/repos","events_url":"https://api.github.com/users/dchaplinsky/events{/privacy}","received_events_url":"https://api.github.com/users/dchaplinsky/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dchaplinsky/unshred-tag","description":"Flask/Mongo app to manually tag shreds. Experimental, volatile, unstable. No english translation yet, sorry.","fork":false,"url":"https://api.github.com/repos/dchaplinsky/unshred-tag","forks_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/forks","keys_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/teams","hooks_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/hooks","issue_events_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/issues/events{/number}","events_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/events","assignees_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/assignees{/user}","branches_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/branches{/branch}","tags_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/tags","blobs_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/git/refs{/sha}","trees_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/statuses/{sha}","languages_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/languages","stargazers_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/stargazers","contributors_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/contributors","subscribers_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/subscribers","subscription_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/subscription","commits_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/commits{/sha}","git_commits_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/git/commits{/sha}","comments_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/comments{/number}","issue_comment_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/issues/comments/{number}","contents_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/contents/{+path}","compare_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/merges","archive_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/downloads","issues_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/issues{/number}","pulls_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/pulls{/number}","milestones_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/milestones{/number}","notifications_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/labels{/name}","releases_url":"https://api.github.com/repos/dchaplinsky/unshred-tag/releases{/id}","created_at":"2014-07-06T23:18:01Z","updated_at":"2014-10-17T11:49:16Z","pushed_at":"2014-10-16T11:36:41Z","git_url":"git://github.com/dchaplinsky/unshred-tag.git","ssh_url":"git@github.com:dchaplinsky/unshred-tag.git","clone_url":"https://github.com/dchaplinsky/unshred-tag.git","svn_url":"https://github.com/dchaplinsky/unshred-tag","homepage":null,"size":3281,"stargazers_count":12,"watchers_count":12,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":4,"forks":9,"open_issues":4,"watchers":12,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dchaplinsky/unshred-tag/pulls/59"},"html":{"href":"https://github.com/dchaplinsky/unshred-tag/pull/59"},"issue":{"href":"https://api.github.com/repos/dchaplinsky/unshred-tag/issues/59"},"comments":{"href":"https://api.github.com/repos/dchaplinsky/unshred-tag/issues/59/comments"},"review_comments":{"href":"https://api.github.com/repos/dchaplinsky/unshred-tag/pulls/59/comments"},"review_comment":{"href":"https://api.github.com/repos/dchaplinsky/unshred-tag/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/dchaplinsky/unshred-tag/pulls/59/commits"},"statuses":{"href":"https://api.github.com/repos/dchaplinsky/unshred-tag/statuses/509a0e9f591faaf7f65acc5e27eedab93feda3fa"}}}}