{"action":"created","comment":{"url":"https://api.github.com/repos/moneyadviceservice/rad/pulls/comments/39074790","id":39074790,"diff_hunk":"@@ -0,0 +1,94 @@\n+require 'net/http'\n+\n+class ByCountryReport\n+  def initialize\n+    @registered_firms = Firm.registered\n+    @lookup = fetch_countries\n+  end\n+\n+  def firm_report\n+    firms = @registered_firms.where(parent_id: nil) # don't include trading names\n+    grouped_firms = firms.group_by do |firm|\n+      @lookup[postcode_slug_for(firm)]\n+    end\n+    generate_report('Firms', grouped_firms, firms.count)\n+  end\n+\n+  def adviser_report\n+    advisers = @registered_firms.map(&:advisers).flatten # include trading names\n+    grouped_advisers = advisers.group_by do |adviser|\n+      @lookup[postcode_slug_for(adviser.firm)]\n+    end\n+    generate_report('Advisers', grouped_advisers, advisers.count)\n+  end\n+\n+  def error_report\n+    grouped_firms = @registered_firms.group_by do |firm|\n+      @lookup[postcode_slug_for(firm)]\n+    end\n+    firms_with_errors = grouped_firms.select { |k, _| k.blank? }.values.flatten.map(&:id).uniq","path":"lib/reports/by_country_report.rb","position":29,"original_position":29,"commit_id":"e68a58494132e8c5e4fa077f4a417012f7c9deb6","original_commit_id":"e68a58494132e8c5e4fa077f4a417012f7c9deb6","user":{"login":"urfolomeus","id":52965,"avatar_url":"https://avatars.githubusercontent.com/u/52965?v=3","gravatar_id":"","url":"https://api.github.com/users/urfolomeus","html_url":"https://github.com/urfolomeus","followers_url":"https://api.github.com/users/urfolomeus/followers","following_url":"https://api.github.com/users/urfolomeus/following{/other_user}","gists_url":"https://api.github.com/users/urfolomeus/gists{/gist_id}","starred_url":"https://api.github.com/users/urfolomeus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/urfolomeus/subscriptions","organizations_url":"https://api.github.com/users/urfolomeus/orgs","repos_url":"https://api.github.com/users/urfolomeus/repos","events_url":"https://api.github.com/users/urfolomeus/events{/privacy}","received_events_url":"https://api.github.com/users/urfolomeus/received_events","type":"User","site_admin":false},"body":"`k` will be blank for any postcodes which return a blank country (i.e. those that are not found on the postcode lookup).","created_at":"2015-09-09T17:55:23Z","updated_at":"2015-09-09T17:55:23Z","html_url":"https://github.com/moneyadviceservice/rad/pull/312#discussion_r39074790","pull_request_url":"https://api.github.com/repos/moneyadviceservice/rad/pulls/312","_links":{"self":{"href":"https://api.github.com/repos/moneyadviceservice/rad/pulls/comments/39074790"},"html":{"href":"https://github.com/moneyadviceservice/rad/pull/312#discussion_r39074790"},"pull_request":{"href":"https://api.github.com/repos/moneyadviceservice/rad/pulls/312"}}},"pull_request":{"url":"https://api.github.com/repos/moneyadviceservice/rad/pulls/312","id":44553379,"html_url":"https://github.com/moneyadviceservice/rad/pull/312","diff_url":"https://github.com/moneyadviceservice/rad/pull/312.diff","patch_url":"https://github.com/moneyadviceservice/rad/pull/312.patch","issue_url":"https://api.github.com/repos/moneyadviceservice/rad/issues/312","number":312,"state":"open","locked":false,"title":"By country report","user":{"login":"urfolomeus","id":52965,"avatar_url":"https://avatars.githubusercontent.com/u/52965?v=3","gravatar_id":"","url":"https://api.github.com/users/urfolomeus","html_url":"https://github.com/urfolomeus","followers_url":"https://api.github.com/users/urfolomeus/followers","following_url":"https://api.github.com/users/urfolomeus/following{/other_user}","gists_url":"https://api.github.com/users/urfolomeus/gists{/gist_id}","starred_url":"https://api.github.com/users/urfolomeus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/urfolomeus/subscriptions","organizations_url":"https://api.github.com/users/urfolomeus/orgs","repos_url":"https://api.github.com/users/urfolomeus/repos","events_url":"https://api.github.com/users/urfolomeus/events{/privacy}","received_events_url":"https://api.github.com/users/urfolomeus/received_events","type":"User","site_admin":false},"body":"This was a (so far) one-off report to show the uptake of the register by country.\r\nIt's a little rough but has been committed in case we need it again.","created_at":"2015-09-09T14:02:53Z","updated_at":"2015-09-09T17:55:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e75ad820373cf038d631082490320eebcba5d553","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/moneyadviceservice/rad/pulls/312/commits","review_comments_url":"https://api.github.com/repos/moneyadviceservice/rad/pulls/312/comments","review_comment_url":"https://api.github.com/repos/moneyadviceservice/rad/pulls/comments{/number}","comments_url":"https://api.github.com/repos/moneyadviceservice/rad/issues/312/comments","statuses_url":"https://api.github.com/repos/moneyadviceservice/rad/statuses/e68a58494132e8c5e4fa077f4a417012f7c9deb6","head":{"label":"moneyadviceservice:by-country-report","ref":"by-country-report","sha":"e68a58494132e8c5e4fa077f4a417012f7c9deb6","user":{"login":"moneyadviceservice","id":2064781,"avatar_url":"https://avatars.githubusercontent.com/u/2064781?v=3","gravatar_id":"","url":"https://api.github.com/users/moneyadviceservice","html_url":"https://github.com/moneyadviceservice","followers_url":"https://api.github.com/users/moneyadviceservice/followers","following_url":"https://api.github.com/users/moneyadviceservice/following{/other_user}","gists_url":"https://api.github.com/users/moneyadviceservice/gists{/gist_id}","starred_url":"https://api.github.com/users/moneyadviceservice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/moneyadviceservice/subscriptions","organizations_url":"https://api.github.com/users/moneyadviceservice/orgs","repos_url":"https://api.github.com/users/moneyadviceservice/repos","events_url":"https://api.github.com/users/moneyadviceservice/events{/privacy}","received_events_url":"https://api.github.com/users/moneyadviceservice/received_events","type":"Organization","site_admin":false},"repo":{"id":26871523,"name":"rad","full_name":"moneyadviceservice/rad","owner":{"login":"moneyadviceservice","id":2064781,"avatar_url":"https://avatars.githubusercontent.com/u/2064781?v=3","gravatar_id":"","url":"https://api.github.com/users/moneyadviceservice","html_url":"https://github.com/moneyadviceservice","followers_url":"https://api.github.com/users/moneyadviceservice/followers","following_url":"https://api.github.com/users/moneyadviceservice/following{/other_user}","gists_url":"https://api.github.com/users/moneyadviceservice/gists{/gist_id}","starred_url":"https://api.github.com/users/moneyadviceservice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/moneyadviceservice/subscriptions","organizations_url":"https://api.github.com/users/moneyadviceservice/orgs","repos_url":"https://api.github.com/users/moneyadviceservice/repos","events_url":"https://api.github.com/users/moneyadviceservice/events{/privacy}","received_events_url":"https://api.github.com/users/moneyadviceservice/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/moneyadviceservice/rad","description":"Retirement Adviser Directory","fork":false,"url":"https://api.github.com/repos/moneyadviceservice/rad","forks_url":"https://api.github.com/repos/moneyadviceservice/rad/forks","keys_url":"https://api.github.com/repos/moneyadviceservice/rad/keys{/key_id}","collaborators_url":"https://api.github.com/repos/moneyadviceservice/rad/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/moneyadviceservice/rad/teams","hooks_url":"https://api.github.com/repos/moneyadviceservice/rad/hooks","issue_events_url":"https://api.github.com/repos/moneyadviceservice/rad/issues/events{/number}","events_url":"https://api.github.com/repos/moneyadviceservice/rad/events","assignees_url":"https://api.github.com/repos/moneyadviceservice/rad/assignees{/user}","branches_url":"https://api.github.com/repos/moneyadviceservice/rad/branches{/branch}","tags_url":"https://api.github.com/repos/moneyadviceservice/rad/tags","blobs_url":"https://api.github.com/repos/moneyadviceservice/rad/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/moneyadviceservice/rad/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/moneyadviceservice/rad/git/refs{/sha}","trees_url":"https://api.github.com/repos/moneyadviceservice/rad/git/trees{/sha}","statuses_url":"https://api.github.com/repos/moneyadviceservice/rad/statuses/{sha}","languages_url":"https://api.github.com/repos/moneyadviceservice/rad/languages","stargazers_url":"https://api.github.com/repos/moneyadviceservice/rad/stargazers","contributors_url":"https://api.github.com/repos/moneyadviceservice/rad/contributors","subscribers_url":"https://api.github.com/repos/moneyadviceservice/rad/subscribers","subscription_url":"https://api.github.com/repos/moneyadviceservice/rad/subscription","commits_url":"https://api.github.com/repos/moneyadviceservice/rad/commits{/sha}","git_commits_url":"https://api.github.com/repos/moneyadviceservice/rad/git/commits{/sha}","comments_url":"https://api.github.com/repos/moneyadviceservice/rad/comments{/number}","issue_comment_url":"https://api.github.com/repos/moneyadviceservice/rad/issues/comments{/number}","contents_url":"https://api.github.com/repos/moneyadviceservice/rad/contents/{+path}","compare_url":"https://api.github.com/repos/moneyadviceservice/rad/compare/{base}...{head}","merges_url":"https://api.github.com/repos/moneyadviceservice/rad/merges","archive_url":"https://api.github.com/repos/moneyadviceservice/rad/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/moneyadviceservice/rad/downloads","issues_url":"https://api.github.com/repos/moneyadviceservice/rad/issues{/number}","pulls_url":"https://api.github.com/repos/moneyadviceservice/rad/pulls{/number}","milestones_url":"https://api.github.com/repos/moneyadviceservice/rad/milestones{/number}","notifications_url":"https://api.github.com/repos/moneyadviceservice/rad/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/moneyadviceservice/rad/labels{/name}","releases_url":"https://api.github.com/repos/moneyadviceservice/rad/releases{/id}","created_at":"2014-11-19T16:55:48Z","updated_at":"2015-06-15T15:36:58Z","pushed_at":"2015-09-09T14:02:53Z","git_url":"git://github.com/moneyadviceservice/rad.git","ssh_url":"git@github.com:moneyadviceservice/rad.git","clone_url":"https://github.com/moneyadviceservice/rad.git","svn_url":"https://github.com/moneyadviceservice/rad","homepage":"","size":6524,"stargazers_count":1,"watchers_count":1,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":1,"default_branch":"master"}},"base":{"label":"moneyadviceservice:master","ref":"master","sha":"0c55de4445d03d55d86b090910590395c585652f","user":{"login":"moneyadviceservice","id":2064781,"avatar_url":"https://avatars.githubusercontent.com/u/2064781?v=3","gravatar_id":"","url":"https://api.github.com/users/moneyadviceservice","html_url":"https://github.com/moneyadviceservice","followers_url":"https://api.github.com/users/moneyadviceservice/followers","following_url":"https://api.github.com/users/moneyadviceservice/following{/other_user}","gists_url":"https://api.github.com/users/moneyadviceservice/gists{/gist_id}","starred_url":"https://api.github.com/users/moneyadviceservice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/moneyadviceservice/subscriptions","organizations_url":"https://api.github.com/users/moneyadviceservice/orgs","repos_url":"https://api.github.com/users/moneyadviceservice/repos","events_url":"https://api.github.com/users/moneyadviceservice/events{/privacy}","received_events_url":"https://api.github.com/users/moneyadviceservice/received_events","type":"Organization","site_admin":false},"repo":{"id":26871523,"name":"rad","full_name":"moneyadviceservice/rad","owner":{"login":"moneyadviceservice","id":2064781,"avatar_url":"https://avatars.githubusercontent.com/u/2064781?v=3","gravatar_id":"","url":"https://api.github.com/users/moneyadviceservice","html_url":"https://github.com/moneyadviceservice","followers_url":"https://api.github.com/users/moneyadviceservice/followers","following_url":"https://api.github.com/users/moneyadviceservice/following{/other_user}","gists_url":"https://api.github.com/users/moneyadviceservice/gists{/gist_id}","starred_url":"https://api.github.com/users/moneyadviceservice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/moneyadviceservice/subscriptions","organizations_url":"https://api.github.com/users/moneyadviceservice/orgs","repos_url":"https://api.github.com/users/moneyadviceservice/repos","events_url":"https://api.github.com/users/moneyadviceservice/events{/privacy}","received_events_url":"https://api.github.com/users/moneyadviceservice/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/moneyadviceservice/rad","description":"Retirement Adviser Directory","fork":false,"url":"https://api.github.com/repos/moneyadviceservice/rad","forks_url":"https://api.github.com/repos/moneyadviceservice/rad/forks","keys_url":"https://api.github.com/repos/moneyadviceservice/rad/keys{/key_id}","collaborators_url":"https://api.github.com/repos/moneyadviceservice/rad/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/moneyadviceservice/rad/teams","hooks_url":"https://api.github.com/repos/moneyadviceservice/rad/hooks","issue_events_url":"https://api.github.com/repos/moneyadviceservice/rad/issues/events{/number}","events_url":"https://api.github.com/repos/moneyadviceservice/rad/events","assignees_url":"https://api.github.com/repos/moneyadviceservice/rad/assignees{/user}","branches_url":"https://api.github.com/repos/moneyadviceservice/rad/branches{/branch}","tags_url":"https://api.github.com/repos/moneyadviceservice/rad/tags","blobs_url":"https://api.github.com/repos/moneyadviceservice/rad/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/moneyadviceservice/rad/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/moneyadviceservice/rad/git/refs{/sha}","trees_url":"https://api.github.com/repos/moneyadviceservice/rad/git/trees{/sha}","statuses_url":"https://api.github.com/repos/moneyadviceservice/rad/statuses/{sha}","languages_url":"https://api.github.com/repos/moneyadviceservice/rad/languages","stargazers_url":"https://api.github.com/repos/moneyadviceservice/rad/stargazers","contributors_url":"https://api.github.com/repos/moneyadviceservice/rad/contributors","subscribers_url":"https://api.github.com/repos/moneyadviceservice/rad/subscribers","subscription_url":"https://api.github.com/repos/moneyadviceservice/rad/subscription","commits_url":"https://api.github.com/repos/moneyadviceservice/rad/commits{/sha}","git_commits_url":"https://api.github.com/repos/moneyadviceservice/rad/git/commits{/sha}","comments_url":"https://api.github.com/repos/moneyadviceservice/rad/comments{/number}","issue_comment_url":"https://api.github.com/repos/moneyadviceservice/rad/issues/comments{/number}","contents_url":"https://api.github.com/repos/moneyadviceservice/rad/contents/{+path}","compare_url":"https://api.github.com/repos/moneyadviceservice/rad/compare/{base}...{head}","merges_url":"https://api.github.com/repos/moneyadviceservice/rad/merges","archive_url":"https://api.github.com/repos/moneyadviceservice/rad/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/moneyadviceservice/rad/downloads","issues_url":"https://api.github.com/repos/moneyadviceservice/rad/issues{/number}","pulls_url":"https://api.github.com/repos/moneyadviceservice/rad/pulls{/number}","milestones_url":"https://api.github.com/repos/moneyadviceservice/rad/milestones{/number}","notifications_url":"https://api.github.com/repos/moneyadviceservice/rad/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/moneyadviceservice/rad/labels{/name}","releases_url":"https://api.github.com/repos/moneyadviceservice/rad/releases{/id}","created_at":"2014-11-19T16:55:48Z","updated_at":"2015-06-15T15:36:58Z","pushed_at":"2015-09-09T14:02:53Z","git_url":"git://github.com/moneyadviceservice/rad.git","ssh_url":"git@github.com:moneyadviceservice/rad.git","clone_url":"https://github.com/moneyadviceservice/rad.git","svn_url":"https://github.com/moneyadviceservice/rad","homepage":"","size":6524,"stargazers_count":1,"watchers_count":1,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/moneyadviceservice/rad/pulls/312"},"html":{"href":"https://github.com/moneyadviceservice/rad/pull/312"},"issue":{"href":"https://api.github.com/repos/moneyadviceservice/rad/issues/312"},"comments":{"href":"https://api.github.com/repos/moneyadviceservice/rad/issues/312/comments"},"review_comments":{"href":"https://api.github.com/repos/moneyadviceservice/rad/pulls/312/comments"},"review_comment":{"href":"https://api.github.com/repos/moneyadviceservice/rad/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/moneyadviceservice/rad/pulls/312/commits"},"statuses":{"href":"https://api.github.com/repos/moneyadviceservice/rad/statuses/e68a58494132e8c5e4fa077f4a417012f7c9deb6"}}}}