{"action":"created","comment":{"url":"https://api.github.com/repos/coala-analyzer/coala/pulls/comments/47430924","id":47430924,"diff_hunk":"@@ -0,0 +1,220 @@\n+import copy\n+\n+from coalib.results.Diff import Diff, ConflictError\n+\n+\n+def filter_results(original_file_dict,\n+                   modified_file_dict,\n+                   original_results,\n+                   modified_results):\n+    \"\"\"\n+    Filters results for such ones that are unique across file changes\n+\n+    :param original_file_dict: Dict of lists of file contents before  changes\n+    :param modified_file_dict: Dict of lists of file contents after changes\n+    :param original_results:   List of results of the old files\n+    :param modified_results:   List of results of the new files\n+    :return:                   List of results from new files that are unique\n+                               from all those that existed in the old changes\n+    \"\"\"\n+    # diffs_dict[file] is a diff between the original and modified file\n+    diffs_dict = {}\n+    for file in original_file_dict:\n+        diffs_dict[file] = Diff.from_string_arrays(original_file_dict[file],\n+                                                  modified_file_dict[file])\n+\n+    #  orig_result_diff_dict_dict[result][file] is a diff of the changes this\n+    # result would apply to the file\n+\n+    orig_result_diff_dict_dict = {}\n+    for original_result in original_results:\n+        orig_file_dict_copy = copy.deepcopy(original_file_dict)\n+\n+        for source_range in original_result.affected_code:\n+            file_name = source_range.file\n+            new_file = remove_range(orig_file_dict_copy[file_name],\n+                                    source_range)\n+            orig_file_dict_copy[file_name] = new_file\n+\n+        diff_dict = {}\n+        for file_name in original_file_dict:\n+            diff_dict[file_name] = Diff.from_string_arrays(\n+                original_file_dict[file_name],\n+                orig_file_dict_copy[file_name])\n+\n+        orig_result_diff_dict_dict[original_result] = diff_dict\n+\n+    # same thing for modified results. and yes this should really be in a\n+    # function... but as long as both of these are not, code clone detection\n+    # won't find them >:)\n+    # fixme: yeah....\n+\n+    mod_result_diff_dict_dict = {}\n+    for modified_result in modified_results:\n+        mod_file_dict_copy = copy.deepcopy(modified_file_dict)\n+\n+        for source_range in modified_result.affected_code:\n+            file_name = source_range.file\n+            new_file = remove_range(mod_file_dict_copy[file_name],\n+                                    source_range)\n+            mod_file_dict_copy[file_name] = new_file\n+\n+        diff_dict = {}\n+        for file_name in modified_file_dict:\n+            diff_dict[file_name] = Diff.from_string_arrays(\n+                modified_file_dict[file_name],\n+                mod_file_dict_copy[file_name])\n+\n+        mod_result_diff_dict_dict[modified_result] = diff_dict\n+\n+    uniques = []\n+\n+    # THIS IS WHERE THE FUN BEGINS\n+\n+    for m_r in modified_results:\n+        if True not in [basics_match(o_r, m_r) for o_r in original_results]:\n+            uniques.append(m_r)\n+\n+        elif True not in [source_ranges_match(\n+                original_file_dict,\n+                modified_file_dict,\n+                diffs_dict,\n+                o_r,\n+                orig_result_diff_dict_dict[o_r],\n+                m_r,\n+                mod_result_diff_dict_dict[m_r]) for o_r in original_results]:\n+            uniques.append(m_r)\n+\n+    return uniques\n+\n+\n+def basics_match(original_result,\n+                 modified_result):\n+    \"\"\"\n+    Checks whether the following properties of two results match:\n+    * origin\n+    * message\n+    * severity\n+    * debug_msg\n+\n+    :param original_result: A result of the old files\n+    :param modified_result: A result of the new files\n+    :return:                Boolean value whether or not the properties match\n+    \"\"\"\n+    # origin might be a class or class name\n+    original_origin = isinstance(original_result.origin, str) and \\\n+        original_result.origin or original_result.origin.__name__()\n+    modified_origin = isinstance(modified_result.origin, str) and \\\n+        modified_result.origin or modified_result.origin.__name__()\n+\n+    # we cannot tolerate differences!\n+    if original_origin != modified_origin:\n+        return False\n+\n+    elif original_result.message != modified_result.message:\n+        return False\n+\n+    elif original_result.severity != modified_result.severity:\n+        return False\n+\n+    elif original_result.debug_msg != modified_result.debug_msg:\n+        return False\n+\n+    else:\n+        return True\n+\n+\n+def source_ranges_match(original_file_dict,\n+                        modified_file_dict,\n+                        diff_dict,\n+                        original_result,\n+                        original_result_diff_dict,\n+                        modified_result,\n+                        modified_result_diff_dict):\n+    \"\"\"\n+    Checks whether the SourceRanges of two results match\n+\n+    :param original_file_dict: Dict of lists of file contents before changes\n+    :param modified_file_dict: Dict of lists of file contents after changes\n+    :param diff_dict:          Dict of diffs describing the changes per file\n+    :param original_result:    A result of the old files\n+    :param original_result_diff_dict: diff for each file for this result\n+    :param modified_result:    A result of the new files\n+    :param modified_result_diff_dict: guess\n+    :return:                     Boolean value whether the SourceRanges match\n+    \"\"\"\n+    for file_name in original_file_dict:\n+\n+        try:  # fails if the affected range of the result get's modified\n+            original_total_diff = \\\n+                diff_dict[file_name] + original_result_diff_dict[file_name]\n+        except ConflictError:\n+            return False\n+\n+        # original file with file_diff and original_diff applied\n+        original_total_file = original_total_diff.modified\n+        # modified file with modified_diff applied\n+        modified_total_file = modified_result_diff_dict[file_name].modified\n+        if original_total_file != modified_total_file:\n+            return False\n+    return True\n+\n+\n+def diffs_match(original_file_dict,\n+                modified_file_dict,\n+                diff_dict,\n+                original_result,\n+                modified_result):\n+    \"\"\"\n+    Checks whether the Diffs of two results describe the same changes\n+\n+    :param original_file_dict: Dict of lists of file contents before changes\n+    :param modified_file_dict: Dict of lists of file contents after changes\n+    :param diff_dict:          Dict of diffs describing the change in each file\n+    :param original_result:    A result of the old files\n+    :param modified_result:    A result of the new files\n+    :return:                   Boolean value whether the Diffs match\n+    \"\"\"\n+    return False # pragma: no cover","path":"coalib/results/ResultFilter.py","position":178,"original_position":178,"commit_id":"bd9c00b3638560e3299fdcd682ce1150662168f5","original_commit_id":"bd9c00b3638560e3299fdcd682ce1150662168f5","user":{"login":"sils1297","id":5716520,"avatar_url":"https://avatars.githubusercontent.com/u/5716520?v=3","gravatar_id":"","url":"https://api.github.com/users/sils1297","html_url":"https://github.com/sils1297","followers_url":"https://api.github.com/users/sils1297/followers","following_url":"https://api.github.com/users/sils1297/following{/other_user}","gists_url":"https://api.github.com/users/sils1297/gists{/gist_id}","starred_url":"https://api.github.com/users/sils1297/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sils1297/subscriptions","organizations_url":"https://api.github.com/users/sils1297/orgs","repos_url":"https://api.github.com/users/sils1297/repos","events_url":"https://api.github.com/users/sils1297/events{/privacy}","received_events_url":"https://api.github.com/users/sils1297/received_events","type":"User","site_admin":false},"body":"ah interesting, I would have guessed that you need to do the pragma for the whole function... well then take it out until you need it ok?","created_at":"2015-12-12T11:52:41Z","updated_at":"2015-12-12T11:52:41Z","html_url":"https://github.com/coala-analyzer/coala/pull/1086#discussion_r47430924","pull_request_url":"https://api.github.com/repos/coala-analyzer/coala/pulls/1086","_links":{"self":{"href":"https://api.github.com/repos/coala-analyzer/coala/pulls/comments/47430924"},"html":{"href":"https://github.com/coala-analyzer/coala/pull/1086#discussion_r47430924"},"pull_request":{"href":"https://api.github.com/repos/coala-analyzer/coala/pulls/1086"}}},"pull_request":{"url":"https://api.github.com/repos/coala-analyzer/coala/pulls/1086","id":51711332,"html_url":"https://github.com/coala-analyzer/coala/pull/1086","diff_url":"https://github.com/coala-analyzer/coala/pull/1086.diff","patch_url":"https://github.com/coala-analyzer/coala/pull/1086.patch","issue_url":"https://api.github.com/repos/coala-analyzer/coala/issues/1086","number":1086,"state":"open","locked":false,"title":"Result Filtering","user":{"login":"fneu","id":7591685,"avatar_url":"https://avatars.githubusercontent.com/u/7591685?v=3","gravatar_id":"","url":"https://api.github.com/users/fneu","html_url":"https://github.com/fneu","followers_url":"https://api.github.com/users/fneu/followers","following_url":"https://api.github.com/users/fneu/following{/other_user}","gists_url":"https://api.github.com/users/fneu/gists{/gist_id}","starred_url":"https://api.github.com/users/fneu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fneu/subscriptions","organizations_url":"https://api.github.com/users/fneu/orgs","repos_url":"https://api.github.com/users/fneu/repos","events_url":"https://api.github.com/users/fneu/events{/privacy}","received_events_url":"https://api.github.com/users/fneu/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-11-24T20:17:00Z","updated_at":"2015-12-12T11:52:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"22d479dc8b6dde894c048d442de25d5aa082dc1c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/coala-analyzer/coala/pulls/1086/commits","review_comments_url":"https://api.github.com/repos/coala-analyzer/coala/pulls/1086/comments","review_comment_url":"https://api.github.com/repos/coala-analyzer/coala/pulls/comments{/number}","comments_url":"https://api.github.com/repos/coala-analyzer/coala/issues/1086/comments","statuses_url":"https://api.github.com/repos/coala-analyzer/coala/statuses/bd9c00b3638560e3299fdcd682ce1150662168f5","head":{"label":"coala-analyzer:fneu/resfilter2","ref":"fneu/resfilter2","sha":"bd9c00b3638560e3299fdcd682ce1150662168f5","user":{"login":"coala-analyzer","id":10620750,"avatar_url":"https://avatars.githubusercontent.com/u/10620750?v=3","gravatar_id":"","url":"https://api.github.com/users/coala-analyzer","html_url":"https://github.com/coala-analyzer","followers_url":"https://api.github.com/users/coala-analyzer/followers","following_url":"https://api.github.com/users/coala-analyzer/following{/other_user}","gists_url":"https://api.github.com/users/coala-analyzer/gists{/gist_id}","starred_url":"https://api.github.com/users/coala-analyzer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coala-analyzer/subscriptions","organizations_url":"https://api.github.com/users/coala-analyzer/orgs","repos_url":"https://api.github.com/users/coala-analyzer/repos","events_url":"https://api.github.com/users/coala-analyzer/events{/privacy}","received_events_url":"https://api.github.com/users/coala-analyzer/received_events","type":"Organization","site_admin":false},"repo":{"id":19816973,"name":"coala","full_name":"coala-analyzer/coala","owner":{"login":"coala-analyzer","id":10620750,"avatar_url":"https://avatars.githubusercontent.com/u/10620750?v=3","gravatar_id":"","url":"https://api.github.com/users/coala-analyzer","html_url":"https://github.com/coala-analyzer","followers_url":"https://api.github.com/users/coala-analyzer/followers","following_url":"https://api.github.com/users/coala-analyzer/following{/other_user}","gists_url":"https://api.github.com/users/coala-analyzer/gists{/gist_id}","starred_url":"https://api.github.com/users/coala-analyzer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coala-analyzer/subscriptions","organizations_url":"https://api.github.com/users/coala-analyzer/orgs","repos_url":"https://api.github.com/users/coala-analyzer/repos","events_url":"https://api.github.com/users/coala-analyzer/events{/privacy}","received_events_url":"https://api.github.com/users/coala-analyzer/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/coala-analyzer/coala","description":"Easy to use COde AnaLysis Application","fork":false,"url":"https://api.github.com/repos/coala-analyzer/coala","forks_url":"https://api.github.com/repos/coala-analyzer/coala/forks","keys_url":"https://api.github.com/repos/coala-analyzer/coala/keys{/key_id}","collaborators_url":"https://api.github.com/repos/coala-analyzer/coala/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/coala-analyzer/coala/teams","hooks_url":"https://api.github.com/repos/coala-analyzer/coala/hooks","issue_events_url":"https://api.github.com/repos/coala-analyzer/coala/issues/events{/number}","events_url":"https://api.github.com/repos/coala-analyzer/coala/events","assignees_url":"https://api.github.com/repos/coala-analyzer/coala/assignees{/user}","branches_url":"https://api.github.com/repos/coala-analyzer/coala/branches{/branch}","tags_url":"https://api.github.com/repos/coala-analyzer/coala/tags","blobs_url":"https://api.github.com/repos/coala-analyzer/coala/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/coala-analyzer/coala/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/coala-analyzer/coala/git/refs{/sha}","trees_url":"https://api.github.com/repos/coala-analyzer/coala/git/trees{/sha}","statuses_url":"https://api.github.com/repos/coala-analyzer/coala/statuses/{sha}","languages_url":"https://api.github.com/repos/coala-analyzer/coala/languages","stargazers_url":"https://api.github.com/repos/coala-analyzer/coala/stargazers","contributors_url":"https://api.github.com/repos/coala-analyzer/coala/contributors","subscribers_url":"https://api.github.com/repos/coala-analyzer/coala/subscribers","subscription_url":"https://api.github.com/repos/coala-analyzer/coala/subscription","commits_url":"https://api.github.com/repos/coala-analyzer/coala/commits{/sha}","git_commits_url":"https://api.github.com/repos/coala-analyzer/coala/git/commits{/sha}","comments_url":"https://api.github.com/repos/coala-analyzer/coala/comments{/number}","issue_comment_url":"https://api.github.com/repos/coala-analyzer/coala/issues/comments{/number}","contents_url":"https://api.github.com/repos/coala-analyzer/coala/contents/{+path}","compare_url":"https://api.github.com/repos/coala-analyzer/coala/compare/{base}...{head}","merges_url":"https://api.github.com/repos/coala-analyzer/coala/merges","archive_url":"https://api.github.com/repos/coala-analyzer/coala/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/coala-analyzer/coala/downloads","issues_url":"https://api.github.com/repos/coala-analyzer/coala/issues{/number}","pulls_url":"https://api.github.com/repos/coala-analyzer/coala/pulls{/number}","milestones_url":"https://api.github.com/repos/coala-analyzer/coala/milestones{/number}","notifications_url":"https://api.github.com/repos/coala-analyzer/coala/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/coala-analyzer/coala/labels{/name}","releases_url":"https://api.github.com/repos/coala-analyzer/coala/releases{/id}","created_at":"2014-05-15T11:35:34Z","updated_at":"2015-11-23T23:04:39Z","pushed_at":"2015-12-12T11:23:24Z","git_url":"git://github.com/coala-analyzer/coala.git","ssh_url":"git@github.com:coala-analyzer/coala.git","clone_url":"https://github.com/coala-analyzer/coala.git","svn_url":"https://github.com/coala-analyzer/coala","homepage":"http://coala-analyzer.org/","size":5005,"stargazers_count":29,"watchers_count":29,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":21,"mirror_url":null,"open_issues_count":110,"forks":21,"open_issues":110,"watchers":29,"default_branch":"master"}},"base":{"label":"coala-analyzer:master","ref":"master","sha":"74db9ddde0c99b33a09140ac2adc520b5cba5b28","user":{"login":"coala-analyzer","id":10620750,"avatar_url":"https://avatars.githubusercontent.com/u/10620750?v=3","gravatar_id":"","url":"https://api.github.com/users/coala-analyzer","html_url":"https://github.com/coala-analyzer","followers_url":"https://api.github.com/users/coala-analyzer/followers","following_url":"https://api.github.com/users/coala-analyzer/following{/other_user}","gists_url":"https://api.github.com/users/coala-analyzer/gists{/gist_id}","starred_url":"https://api.github.com/users/coala-analyzer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coala-analyzer/subscriptions","organizations_url":"https://api.github.com/users/coala-analyzer/orgs","repos_url":"https://api.github.com/users/coala-analyzer/repos","events_url":"https://api.github.com/users/coala-analyzer/events{/privacy}","received_events_url":"https://api.github.com/users/coala-analyzer/received_events","type":"Organization","site_admin":false},"repo":{"id":19816973,"name":"coala","full_name":"coala-analyzer/coala","owner":{"login":"coala-analyzer","id":10620750,"avatar_url":"https://avatars.githubusercontent.com/u/10620750?v=3","gravatar_id":"","url":"https://api.github.com/users/coala-analyzer","html_url":"https://github.com/coala-analyzer","followers_url":"https://api.github.com/users/coala-analyzer/followers","following_url":"https://api.github.com/users/coala-analyzer/following{/other_user}","gists_url":"https://api.github.com/users/coala-analyzer/gists{/gist_id}","starred_url":"https://api.github.com/users/coala-analyzer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coala-analyzer/subscriptions","organizations_url":"https://api.github.com/users/coala-analyzer/orgs","repos_url":"https://api.github.com/users/coala-analyzer/repos","events_url":"https://api.github.com/users/coala-analyzer/events{/privacy}","received_events_url":"https://api.github.com/users/coala-analyzer/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/coala-analyzer/coala","description":"Easy to use COde AnaLysis Application","fork":false,"url":"https://api.github.com/repos/coala-analyzer/coala","forks_url":"https://api.github.com/repos/coala-analyzer/coala/forks","keys_url":"https://api.github.com/repos/coala-analyzer/coala/keys{/key_id}","collaborators_url":"https://api.github.com/repos/coala-analyzer/coala/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/coala-analyzer/coala/teams","hooks_url":"https://api.github.com/repos/coala-analyzer/coala/hooks","issue_events_url":"https://api.github.com/repos/coala-analyzer/coala/issues/events{/number}","events_url":"https://api.github.com/repos/coala-analyzer/coala/events","assignees_url":"https://api.github.com/repos/coala-analyzer/coala/assignees{/user}","branches_url":"https://api.github.com/repos/coala-analyzer/coala/branches{/branch}","tags_url":"https://api.github.com/repos/coala-analyzer/coala/tags","blobs_url":"https://api.github.com/repos/coala-analyzer/coala/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/coala-analyzer/coala/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/coala-analyzer/coala/git/refs{/sha}","trees_url":"https://api.github.com/repos/coala-analyzer/coala/git/trees{/sha}","statuses_url":"https://api.github.com/repos/coala-analyzer/coala/statuses/{sha}","languages_url":"https://api.github.com/repos/coala-analyzer/coala/languages","stargazers_url":"https://api.github.com/repos/coala-analyzer/coala/stargazers","contributors_url":"https://api.github.com/repos/coala-analyzer/coala/contributors","subscribers_url":"https://api.github.com/repos/coala-analyzer/coala/subscribers","subscription_url":"https://api.github.com/repos/coala-analyzer/coala/subscription","commits_url":"https://api.github.com/repos/coala-analyzer/coala/commits{/sha}","git_commits_url":"https://api.github.com/repos/coala-analyzer/coala/git/commits{/sha}","comments_url":"https://api.github.com/repos/coala-analyzer/coala/comments{/number}","issue_comment_url":"https://api.github.com/repos/coala-analyzer/coala/issues/comments{/number}","contents_url":"https://api.github.com/repos/coala-analyzer/coala/contents/{+path}","compare_url":"https://api.github.com/repos/coala-analyzer/coala/compare/{base}...{head}","merges_url":"https://api.github.com/repos/coala-analyzer/coala/merges","archive_url":"https://api.github.com/repos/coala-analyzer/coala/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/coala-analyzer/coala/downloads","issues_url":"https://api.github.com/repos/coala-analyzer/coala/issues{/number}","pulls_url":"https://api.github.com/repos/coala-analyzer/coala/pulls{/number}","milestones_url":"https://api.github.com/repos/coala-analyzer/coala/milestones{/number}","notifications_url":"https://api.github.com/repos/coala-analyzer/coala/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/coala-analyzer/coala/labels{/name}","releases_url":"https://api.github.com/repos/coala-analyzer/coala/releases{/id}","created_at":"2014-05-15T11:35:34Z","updated_at":"2015-11-23T23:04:39Z","pushed_at":"2015-12-12T11:23:24Z","git_url":"git://github.com/coala-analyzer/coala.git","ssh_url":"git@github.com:coala-analyzer/coala.git","clone_url":"https://github.com/coala-analyzer/coala.git","svn_url":"https://github.com/coala-analyzer/coala","homepage":"http://coala-analyzer.org/","size":5005,"stargazers_count":29,"watchers_count":29,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":21,"mirror_url":null,"open_issues_count":110,"forks":21,"open_issues":110,"watchers":29,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/coala-analyzer/coala/pulls/1086"},"html":{"href":"https://github.com/coala-analyzer/coala/pull/1086"},"issue":{"href":"https://api.github.com/repos/coala-analyzer/coala/issues/1086"},"comments":{"href":"https://api.github.com/repos/coala-analyzer/coala/issues/1086/comments"},"review_comments":{"href":"https://api.github.com/repos/coala-analyzer/coala/pulls/1086/comments"},"review_comment":{"href":"https://api.github.com/repos/coala-analyzer/coala/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/coala-analyzer/coala/pulls/1086/commits"},"statuses":{"href":"https://api.github.com/repos/coala-analyzer/coala/statuses/bd9c00b3638560e3299fdcd682ce1150662168f5"}}}}