{"action":"created","comment":{"url":"https://api.github.com/repos/allegro/ralph_pricing/pulls/comments/90431832","pull_request_review_id":10949215,"id":90431832,"diff_hunk":"@@ -339,6 +340,45 @@ def group_missing_values_by_date(usage_type, missing_values):\n     return ret\n \n \n+def _sort_unusual_changes_by_date_and_type(anomalies):\n+    \"\"\"Transform each `unusual_changes` subdict in `anomalies` which has the\n+    following shape:\n+\n+    {\n+        <UsageType>: [\n+            (datetime.date, datetime.date, float, float, float),\n+            ...\n+        ],\n+        ...\n+    }\n+\n+    ...into this structure (a list of tuples):\n+\n+    [\n+        (datetime.date, datetime.date, UsageType, float, float, float),\n+        ...\n+    ]\n+\n+    ...and finally sort this list by it's first three elements, in that\n+    priority (i.e. by 1st date, then by 2nd date and finally by UsageType name.\n+\n+    `missing_values` subdict remains unmodified.\n+    \"\"\"\n+    ret = defaultdict(lambda: {'missing_values': {}, 'unusual_changes': {}})\n+    for owner in anomalies.keys():\n+        ret[owner]['missing_values'] = anomalies[owner]['missing_values']\n+        changes = anomalies[owner]['unusual_changes']\n+        changes_ = []\n+        for ut, ch in changes.items():\n+            for ch_ in ch:\n+                t = (ch_[0], ch_[1], ut, ch_[2], ch_[3], ch_[4])","path":"src/ralph_scrooge/management/commands/detect_usage_anomalies.py","position":63,"original_position":63,"commit_id":"5a9783db5bd593d7ee2336bda81ddb636b52deba","original_commit_id":"5a9783db5bd593d7ee2336bda81ddb636b52deba","user":{"login":"xor-xor","id":2082842,"avatar_url":"https://avatars.githubusercontent.com/u/2082842?v=3","gravatar_id":"","url":"https://api.github.com/users/xor-xor","html_url":"https://github.com/xor-xor","followers_url":"https://api.github.com/users/xor-xor/followers","following_url":"https://api.github.com/users/xor-xor/following{/other_user}","gists_url":"https://api.github.com/users/xor-xor/gists{/gist_id}","starred_url":"https://api.github.com/users/xor-xor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xor-xor/subscriptions","organizations_url":"https://api.github.com/users/xor-xor/orgs","repos_url":"https://api.github.com/users/xor-xor/repos","events_url":"https://api.github.com/users/xor-xor/events{/privacy}","received_events_url":"https://api.github.com/users/xor-xor/received_events","type":"User","site_admin":false},"body":"Well, we iterate here over `changes`, so the meaning of `ch` should be obvious :wink:\r\n\r\nAnd if you'd look into the docstring here, you'd notice that we basically take one such `ch` (which is a tuple of 5 elements), and insert usage type (`ut`) in the middle of them - and since this textual description is just 8 lines apart from all this, I've just assumed that'd suffice.\r\n\r\nI can add some comment above this line saying that we are basically inserting usage type in the middle of `ch` tuple, though - would that be enough for you?","created_at":"2016-12-01T11:51:16Z","updated_at":"2016-12-01T11:51:16Z","html_url":"https://github.com/allegro/ralph_pricing/pull/570#discussion_r90431832","pull_request_url":"https://api.github.com/repos/allegro/ralph_pricing/pulls/570","_links":{"self":{"href":"https://api.github.com/repos/allegro/ralph_pricing/pulls/comments/90431832"},"html":{"href":"https://github.com/allegro/ralph_pricing/pull/570#discussion_r90431832"},"pull_request":{"href":"https://api.github.com/repos/allegro/ralph_pricing/pulls/570"}}},"pull_request":{"url":"https://api.github.com/repos/allegro/ralph_pricing/pulls/570","id":96070674,"html_url":"https://github.com/allegro/ralph_pricing/pull/570","diff_url":"https://github.com/allegro/ralph_pricing/pull/570.diff","patch_url":"https://github.com/allegro/ralph_pricing/pull/570.patch","issue_url":"https://api.github.com/repos/allegro/ralph_pricing/issues/570","number":570,"state":"open","locked":false,"title":"Sort anomalies by date, usage type (+ 2 small bugfixes).","user":{"login":"xor-xor","id":2082842,"avatar_url":"https://avatars.githubusercontent.com/u/2082842?v=3","gravatar_id":"","url":"https://api.github.com/users/xor-xor","html_url":"https://github.com/xor-xor","followers_url":"https://api.github.com/users/xor-xor/followers","following_url":"https://api.github.com/users/xor-xor/following{/other_user}","gists_url":"https://api.github.com/users/xor-xor/gists{/gist_id}","starred_url":"https://api.github.com/users/xor-xor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xor-xor/subscriptions","organizations_url":"https://api.github.com/users/xor-xor/orgs","repos_url":"https://api.github.com/users/xor-xor/repos","events_url":"https://api.github.com/users/xor-xor/events{/privacy}","received_events_url":"https://api.github.com/users/xor-xor/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-12-01T11:24:43Z","updated_at":"2016-12-01T11:51:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8fc29c154a122c668f69d0ca8e56cd8985e6fb49","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/allegro/ralph_pricing/pulls/570/commits","review_comments_url":"https://api.github.com/repos/allegro/ralph_pricing/pulls/570/comments","review_comment_url":"https://api.github.com/repos/allegro/ralph_pricing/pulls/comments{/number}","comments_url":"https://api.github.com/repos/allegro/ralph_pricing/issues/570/comments","statuses_url":"https://api.github.com/repos/allegro/ralph_pricing/statuses/5a9783db5bd593d7ee2336bda81ddb636b52deba","head":{"label":"xor-xor:anomalies-sort","ref":"anomalies-sort","sha":"5a9783db5bd593d7ee2336bda81ddb636b52deba","user":{"login":"xor-xor","id":2082842,"avatar_url":"https://avatars.githubusercontent.com/u/2082842?v=3","gravatar_id":"","url":"https://api.github.com/users/xor-xor","html_url":"https://github.com/xor-xor","followers_url":"https://api.github.com/users/xor-xor/followers","following_url":"https://api.github.com/users/xor-xor/following{/other_user}","gists_url":"https://api.github.com/users/xor-xor/gists{/gist_id}","starred_url":"https://api.github.com/users/xor-xor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xor-xor/subscriptions","organizations_url":"https://api.github.com/users/xor-xor/orgs","repos_url":"https://api.github.com/users/xor-xor/repos","events_url":"https://api.github.com/users/xor-xor/events{/privacy}","received_events_url":"https://api.github.com/users/xor-xor/received_events","type":"User","site_admin":false},"repo":{"id":64742322,"name":"ralph_pricing","full_name":"xor-xor/ralph_pricing","owner":{"login":"xor-xor","id":2082842,"avatar_url":"https://avatars.githubusercontent.com/u/2082842?v=3","gravatar_id":"","url":"https://api.github.com/users/xor-xor","html_url":"https://github.com/xor-xor","followers_url":"https://api.github.com/users/xor-xor/followers","following_url":"https://api.github.com/users/xor-xor/following{/other_user}","gists_url":"https://api.github.com/users/xor-xor/gists{/gist_id}","starred_url":"https://api.github.com/users/xor-xor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xor-xor/subscriptions","organizations_url":"https://api.github.com/users/xor-xor/orgs","repos_url":"https://api.github.com/users/xor-xor/repos","events_url":"https://api.github.com/users/xor-xor/events{/privacy}","received_events_url":"https://api.github.com/users/xor-xor/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/xor-xor/ralph_pricing","description":"A pricing module for Ralph","fork":true,"url":"https://api.github.com/repos/xor-xor/ralph_pricing","forks_url":"https://api.github.com/repos/xor-xor/ralph_pricing/forks","keys_url":"https://api.github.com/repos/xor-xor/ralph_pricing/keys{/key_id}","collaborators_url":"https://api.github.com/repos/xor-xor/ralph_pricing/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/xor-xor/ralph_pricing/teams","hooks_url":"https://api.github.com/repos/xor-xor/ralph_pricing/hooks","issue_events_url":"https://api.github.com/repos/xor-xor/ralph_pricing/issues/events{/number}","events_url":"https://api.github.com/repos/xor-xor/ralph_pricing/events","assignees_url":"https://api.github.com/repos/xor-xor/ralph_pricing/assignees{/user}","branches_url":"https://api.github.com/repos/xor-xor/ralph_pricing/branches{/branch}","tags_url":"https://api.github.com/repos/xor-xor/ralph_pricing/tags","blobs_url":"https://api.github.com/repos/xor-xor/ralph_pricing/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/xor-xor/ralph_pricing/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/xor-xor/ralph_pricing/git/refs{/sha}","trees_url":"https://api.github.com/repos/xor-xor/ralph_pricing/git/trees{/sha}","statuses_url":"https://api.github.com/repos/xor-xor/ralph_pricing/statuses/{sha}","languages_url":"https://api.github.com/repos/xor-xor/ralph_pricing/languages","stargazers_url":"https://api.github.com/repos/xor-xor/ralph_pricing/stargazers","contributors_url":"https://api.github.com/repos/xor-xor/ralph_pricing/contributors","subscribers_url":"https://api.github.com/repos/xor-xor/ralph_pricing/subscribers","subscription_url":"https://api.github.com/repos/xor-xor/ralph_pricing/subscription","commits_url":"https://api.github.com/repos/xor-xor/ralph_pricing/commits{/sha}","git_commits_url":"https://api.github.com/repos/xor-xor/ralph_pricing/git/commits{/sha}","comments_url":"https://api.github.com/repos/xor-xor/ralph_pricing/comments{/number}","issue_comment_url":"https://api.github.com/repos/xor-xor/ralph_pricing/issues/comments{/number}","contents_url":"https://api.github.com/repos/xor-xor/ralph_pricing/contents/{+path}","compare_url":"https://api.github.com/repos/xor-xor/ralph_pricing/compare/{base}...{head}","merges_url":"https://api.github.com/repos/xor-xor/ralph_pricing/merges","archive_url":"https://api.github.com/repos/xor-xor/ralph_pricing/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/xor-xor/ralph_pricing/downloads","issues_url":"https://api.github.com/repos/xor-xor/ralph_pricing/issues{/number}","pulls_url":"https://api.github.com/repos/xor-xor/ralph_pricing/pulls{/number}","milestones_url":"https://api.github.com/repos/xor-xor/ralph_pricing/milestones{/number}","notifications_url":"https://api.github.com/repos/xor-xor/ralph_pricing/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/xor-xor/ralph_pricing/labels{/name}","releases_url":"https://api.github.com/repos/xor-xor/ralph_pricing/releases{/id}","deployments_url":"https://api.github.com/repos/xor-xor/ralph_pricing/deployments","created_at":"2016-08-02T09:12:33Z","updated_at":"2016-08-02T09:12:34Z","pushed_at":"2016-12-01T11:23:51Z","git_url":"git://github.com/xor-xor/ralph_pricing.git","ssh_url":"git@github.com:xor-xor/ralph_pricing.git","clone_url":"https://github.com/xor-xor/ralph_pricing.git","svn_url":"https://github.com/xor-xor/ralph_pricing","homepage":null,"size":5653,"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":"develop"}},"base":{"label":"allegro:develop","ref":"develop","sha":"7cd6ca889d699bc45b27497da9495015ef5d64c9","user":{"login":"allegro","id":562236,"avatar_url":"https://avatars.githubusercontent.com/u/562236?v=3","gravatar_id":"","url":"https://api.github.com/users/allegro","html_url":"https://github.com/allegro","followers_url":"https://api.github.com/users/allegro/followers","following_url":"https://api.github.com/users/allegro/following{/other_user}","gists_url":"https://api.github.com/users/allegro/gists{/gist_id}","starred_url":"https://api.github.com/users/allegro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/allegro/subscriptions","organizations_url":"https://api.github.com/users/allegro/orgs","repos_url":"https://api.github.com/users/allegro/repos","events_url":"https://api.github.com/users/allegro/events{/privacy}","received_events_url":"https://api.github.com/users/allegro/received_events","type":"Organization","site_admin":false},"repo":{"id":9495095,"name":"ralph_pricing","full_name":"allegro/ralph_pricing","owner":{"login":"allegro","id":562236,"avatar_url":"https://avatars.githubusercontent.com/u/562236?v=3","gravatar_id":"","url":"https://api.github.com/users/allegro","html_url":"https://github.com/allegro","followers_url":"https://api.github.com/users/allegro/followers","following_url":"https://api.github.com/users/allegro/following{/other_user}","gists_url":"https://api.github.com/users/allegro/gists{/gist_id}","starred_url":"https://api.github.com/users/allegro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/allegro/subscriptions","organizations_url":"https://api.github.com/users/allegro/orgs","repos_url":"https://api.github.com/users/allegro/repos","events_url":"https://api.github.com/users/allegro/events{/privacy}","received_events_url":"https://api.github.com/users/allegro/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/allegro/ralph_pricing","description":"A pricing module for Ralph","fork":false,"url":"https://api.github.com/repos/allegro/ralph_pricing","forks_url":"https://api.github.com/repos/allegro/ralph_pricing/forks","keys_url":"https://api.github.com/repos/allegro/ralph_pricing/keys{/key_id}","collaborators_url":"https://api.github.com/repos/allegro/ralph_pricing/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/allegro/ralph_pricing/teams","hooks_url":"https://api.github.com/repos/allegro/ralph_pricing/hooks","issue_events_url":"https://api.github.com/repos/allegro/ralph_pricing/issues/events{/number}","events_url":"https://api.github.com/repos/allegro/ralph_pricing/events","assignees_url":"https://api.github.com/repos/allegro/ralph_pricing/assignees{/user}","branches_url":"https://api.github.com/repos/allegro/ralph_pricing/branches{/branch}","tags_url":"https://api.github.com/repos/allegro/ralph_pricing/tags","blobs_url":"https://api.github.com/repos/allegro/ralph_pricing/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/allegro/ralph_pricing/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/allegro/ralph_pricing/git/refs{/sha}","trees_url":"https://api.github.com/repos/allegro/ralph_pricing/git/trees{/sha}","statuses_url":"https://api.github.com/repos/allegro/ralph_pricing/statuses/{sha}","languages_url":"https://api.github.com/repos/allegro/ralph_pricing/languages","stargazers_url":"https://api.github.com/repos/allegro/ralph_pricing/stargazers","contributors_url":"https://api.github.com/repos/allegro/ralph_pricing/contributors","subscribers_url":"https://api.github.com/repos/allegro/ralph_pricing/subscribers","subscription_url":"https://api.github.com/repos/allegro/ralph_pricing/subscription","commits_url":"https://api.github.com/repos/allegro/ralph_pricing/commits{/sha}","git_commits_url":"https://api.github.com/repos/allegro/ralph_pricing/git/commits{/sha}","comments_url":"https://api.github.com/repos/allegro/ralph_pricing/comments{/number}","issue_comment_url":"https://api.github.com/repos/allegro/ralph_pricing/issues/comments{/number}","contents_url":"https://api.github.com/repos/allegro/ralph_pricing/contents/{+path}","compare_url":"https://api.github.com/repos/allegro/ralph_pricing/compare/{base}...{head}","merges_url":"https://api.github.com/repos/allegro/ralph_pricing/merges","archive_url":"https://api.github.com/repos/allegro/ralph_pricing/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/allegro/ralph_pricing/downloads","issues_url":"https://api.github.com/repos/allegro/ralph_pricing/issues{/number}","pulls_url":"https://api.github.com/repos/allegro/ralph_pricing/pulls{/number}","milestones_url":"https://api.github.com/repos/allegro/ralph_pricing/milestones{/number}","notifications_url":"https://api.github.com/repos/allegro/ralph_pricing/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/allegro/ralph_pricing/labels{/name}","releases_url":"https://api.github.com/repos/allegro/ralph_pricing/releases{/id}","deployments_url":"https://api.github.com/repos/allegro/ralph_pricing/deployments","created_at":"2013-04-17T10:30:06Z","updated_at":"2016-10-26T09:31:02Z","pushed_at":"2016-12-01T11:24:43Z","git_url":"git://github.com/allegro/ralph_pricing.git","ssh_url":"git@github.com:allegro/ralph_pricing.git","clone_url":"https://github.com/allegro/ralph_pricing.git","svn_url":"https://github.com/allegro/ralph_pricing","homepage":null,"size":6812,"stargazers_count":7,"watchers_count":7,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":17,"mirror_url":null,"open_issues_count":8,"forks":17,"open_issues":8,"watchers":7,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/allegro/ralph_pricing/pulls/570"},"html":{"href":"https://github.com/allegro/ralph_pricing/pull/570"},"issue":{"href":"https://api.github.com/repos/allegro/ralph_pricing/issues/570"},"comments":{"href":"https://api.github.com/repos/allegro/ralph_pricing/issues/570/comments"},"review_comments":{"href":"https://api.github.com/repos/allegro/ralph_pricing/pulls/570/comments"},"review_comment":{"href":"https://api.github.com/repos/allegro/ralph_pricing/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/allegro/ralph_pricing/pulls/570/commits"},"statuses":{"href":"https://api.github.com/repos/allegro/ralph_pricing/statuses/5a9783db5bd593d7ee2336bda81ddb636b52deba"}}}}
{"actor":{"display_login":"xor-xor"}}