{"action":"created","comment":{"url":"https://api.github.com/repos/ushahidi/platform/pulls/comments/180181385","pull_request_review_id":110558325,"id":180181385,"diff_hunk":"@@ -87,6 +88,80 @@ public function getResponses($form_id)\n \t\t\t->execute($this->db)\n \t\t\t->get('total');\n \t}\n+\n+\tpublic function countTotalPending($form_id, $total_sent) {\n+\t\t$form_id = intval($form_id);\n+\t\t//total_contacts = select count(contact_id) from targeted_survey_state where form_id=8 and survey_status IN ('RECEIVED RESPONSE','PENDING RESPONSE')\n+\t\t//total_attributes = select count(form_attributes.id) from form_attributes INNER JOIN form_stages ON form_attributes.form_stage_id = form_stages.id WHERE form_stages.form_id=8\n+\t\t$total_contacts = DB::query(Database::SELECT,\n+\t\t\t\"select count(contact_id) as total from targeted_survey_state where form_id=$form_id\n+\t\t\t and survey_status NOT IN ('SURVEY FINISHED')\")\n+\t\t->execute($this->db)->get('total');\n+\t\t$total_attributes = DB::query(Database::SELECT,\n+\t\t\t\"select count(form_attributes.id) as total from form_attributes \n+\t\t\tINNER JOIN form_stages ON form_attributes.form_stage_id = form_stages.id WHERE form_stages.form_id=$form_id\")","path":"application/classes/Ushahidi/Repository/Form/Stats.php","position":25,"original_position":25,"commit_id":"48b5515a2bf54890327b744ffd66f27267475c7e","original_commit_id":"48b5515a2bf54890327b744ffd66f27267475c7e","user":{"login":"rowasc","id":2434401,"avatar_url":"https://avatars0.githubusercontent.com/u/2434401?v=4","gravatar_id":"","url":"https://api.github.com/users/rowasc","html_url":"https://github.com/rowasc","followers_url":"https://api.github.com/users/rowasc/followers","following_url":"https://api.github.com/users/rowasc/following{/other_user}","gists_url":"https://api.github.com/users/rowasc/gists{/gist_id}","starred_url":"https://api.github.com/users/rowasc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rowasc/subscriptions","organizations_url":"https://api.github.com/users/rowasc/orgs","repos_url":"https://api.github.com/users/rowasc/repos","events_url":"https://api.github.com/users/rowasc/events{/privacy}","received_events_url":"https://api.github.com/users/rowasc/received_events","type":"User","site_admin":false},"body":"just in case:the rough query (replacing the form id obviously)  is this\r\n```SELECT SUM(results.counted) as total FROM (SELECT count(form_attributes.form_stage_id) as counted from targeted_survey_state INNER JOIN form_stages ON targeted_survey_state.form_id=form_stages.form_id INNER JOIN form_attributes ON form_stages.id = form_attributes.form_stage_id INNER JOIN (SELECT form_attributes.priority, targeted_survey_state.form_attribute_id, targeted_survey_state.contact_id FROM form_attributes INNER JOIN targeted_survey_state ON form_attributes.id =targeted_survey_state.form_attribute_id WHERE targeted_survey_state.form_id=8 and targeted_survey_state.survey_status='INACTIVE') as internal_query ON internal_query.contact_id = targeted_survey_state.contact_id WHERE form_attributes.priority > internal_query.priority AND survey_status = 'INACTIVE' AND form_stages.form_id=8 group by targeted_survey_state.contact_id, form_attributes.form_stage_id) as results; ```\r\n\r\n","created_at":"2018-04-09T18:06:17Z","updated_at":"2018-04-09T18:06:17Z","html_url":"https://github.com/ushahidi/platform/pull/2712#discussion_r180181385","pull_request_url":"https://api.github.com/repos/ushahidi/platform/pulls/2712","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/ushahidi/platform/pulls/comments/180181385"},"html":{"href":"https://github.com/ushahidi/platform/pull/2712#discussion_r180181385"},"pull_request":{"href":"https://api.github.com/repos/ushahidi/platform/pulls/2712"}},"in_reply_to_id":180178387},"pull_request":{"url":"https://api.github.com/repos/ushahidi/platform/pulls/2712","id":180373119,"html_url":"https://github.com/ushahidi/platform/pull/2712","diff_url":"https://github.com/ushahidi/platform/pull/2712.diff","patch_url":"https://github.com/ushahidi/platform/pull/2712.patch","issue_url":"https://api.github.com/repos/ushahidi/platform/issues/2712","number":2712,"state":"open","locked":false,"title":"wip - 2683 - stats endpoint with total pending and total sent added","user":{"login":"rowasc","id":2434401,"avatar_url":"https://avatars0.githubusercontent.com/u/2434401?v=4","gravatar_id":"","url":"https://api.github.com/users/rowasc","html_url":"https://github.com/rowasc","followers_url":"https://api.github.com/users/rowasc/followers","following_url":"https://api.github.com/users/rowasc/following{/other_user}","gists_url":"https://api.github.com/users/rowasc/gists{/gist_id}","starred_url":"https://api.github.com/users/rowasc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rowasc/subscriptions","organizations_url":"https://api.github.com/users/rowasc/orgs","repos_url":"https://api.github.com/users/rowasc/repos","events_url":"https://api.github.com/users/rowasc/events{/privacy}","received_events_url":"https://api.github.com/users/rowasc/received_events","type":"User","site_admin":false},"body":"This pull request makes the following changes:\r\n- Adds total pending messages (accounts for INACTIVE contacts)\r\n- Adds total sent messagges (based on message count joined with survey state table contacts)\r\n\r\nTODO: \r\n- Add +fix tests!\r\n- Convert queries to use query builder\r\n- Clean up countTotalPending\r\n- If possible make the main query in countTotalPending more concise. Right now this is where I'm at: \r\n```SELECT SUM(results.counted) as total FROM (SELECT count(form_attributes.form_stage_id) as counted from targeted_survey_state INNER JOIN form_stages ON targeted_survey_state.form_id=form_stages.form_id INNER JOIN form_attributes ON form_stages.id = form_attributes.form_stage_id INNER JOIN (SELECT form_attributes.priority, targeted_survey_state.form_attribute_id, targeted_survey_state.contact_id FROM form_attributes INNER JOIN targeted_survey_state ON form_attributes.id =targeted_survey_state.form_attribute_id WHERE targeted_survey_state.form_id=8 and targeted_survey_state.survey_status='INACTIVE') as internal_query ON internal_query.contact_id = targeted_survey_state.contact_id WHERE form_attributes.priority > internal_query.priority AND survey_status = 'INACTIVE' AND form_stages.form_id=8 group by targeted_survey_state.contact_id, form_attributes.form_stage_id) as results;``` => this gets the total pending messages for contacts marked as inactive ($total_pending_for_inactive)\r\n- change INACTIVE exact to a CONTAINS that works with our \"CONTACT MOVED\" survey status format\r\nTest checklist:\r\n- [ ]\r\n\r\n- [ ] I certify that I ran my checklist\r\n\r\nFixes ushahidi/platform# .\r\n\r\nPing @ushahidi/platform\r\n","created_at":"2018-04-09T17:16:52Z","updated_at":"2018-04-09T18:06:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"82ea440e1db73245fde64f0f164d72471d820e03","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/ushahidi/platform/pulls/2712/commits","review_comments_url":"https://api.github.com/repos/ushahidi/platform/pulls/2712/comments","review_comment_url":"https://api.github.com/repos/ushahidi/platform/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ushahidi/platform/issues/2712/comments","statuses_url":"https://api.github.com/repos/ushahidi/platform/statuses/48b5515a2bf54890327b744ffd66f27267475c7e","head":{"label":"ushahidi:2683","ref":"2683","sha":"48b5515a2bf54890327b744ffd66f27267475c7e","user":{"login":"ushahidi","id":16959,"avatar_url":"https://avatars3.githubusercontent.com/u/16959?v=4","gravatar_id":"","url":"https://api.github.com/users/ushahidi","html_url":"https://github.com/ushahidi","followers_url":"https://api.github.com/users/ushahidi/followers","following_url":"https://api.github.com/users/ushahidi/following{/other_user}","gists_url":"https://api.github.com/users/ushahidi/gists{/gist_id}","starred_url":"https://api.github.com/users/ushahidi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ushahidi/subscriptions","organizations_url":"https://api.github.com/users/ushahidi/orgs","repos_url":"https://api.github.com/users/ushahidi/repos","events_url":"https://api.github.com/users/ushahidi/events{/privacy}","received_events_url":"https://api.github.com/users/ushahidi/received_events","type":"Organization","site_admin":false},"repo":{"id":6126775,"name":"platform","full_name":"ushahidi/platform","owner":{"login":"ushahidi","id":16959,"avatar_url":"https://avatars3.githubusercontent.com/u/16959?v=4","gravatar_id":"","url":"https://api.github.com/users/ushahidi","html_url":"https://github.com/ushahidi","followers_url":"https://api.github.com/users/ushahidi/followers","following_url":"https://api.github.com/users/ushahidi/following{/other_user}","gists_url":"https://api.github.com/users/ushahidi/gists{/gist_id}","starred_url":"https://api.github.com/users/ushahidi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ushahidi/subscriptions","organizations_url":"https://api.github.com/users/ushahidi/orgs","repos_url":"https://api.github.com/users/ushahidi/repos","events_url":"https://api.github.com/users/ushahidi/events{/privacy}","received_events_url":"https://api.github.com/users/ushahidi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ushahidi/platform","description":"Ushahidi Platform v3 API","fork":false,"url":"https://api.github.com/repos/ushahidi/platform","forks_url":"https://api.github.com/repos/ushahidi/platform/forks","keys_url":"https://api.github.com/repos/ushahidi/platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ushahidi/platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ushahidi/platform/teams","hooks_url":"https://api.github.com/repos/ushahidi/platform/hooks","issue_events_url":"https://api.github.com/repos/ushahidi/platform/issues/events{/number}","events_url":"https://api.github.com/repos/ushahidi/platform/events","assignees_url":"https://api.github.com/repos/ushahidi/platform/assignees{/user}","branches_url":"https://api.github.com/repos/ushahidi/platform/branches{/branch}","tags_url":"https://api.github.com/repos/ushahidi/platform/tags","blobs_url":"https://api.github.com/repos/ushahidi/platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ushahidi/platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ushahidi/platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/ushahidi/platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ushahidi/platform/statuses/{sha}","languages_url":"https://api.github.com/repos/ushahidi/platform/languages","stargazers_url":"https://api.github.com/repos/ushahidi/platform/stargazers","contributors_url":"https://api.github.com/repos/ushahidi/platform/contributors","subscribers_url":"https://api.github.com/repos/ushahidi/platform/subscribers","subscription_url":"https://api.github.com/repos/ushahidi/platform/subscription","commits_url":"https://api.github.com/repos/ushahidi/platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/ushahidi/platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/ushahidi/platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/ushahidi/platform/issues/comments{/number}","contents_url":"https://api.github.com/repos/ushahidi/platform/contents/{+path}","compare_url":"https://api.github.com/repos/ushahidi/platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ushahidi/platform/merges","archive_url":"https://api.github.com/repos/ushahidi/platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ushahidi/platform/downloads","issues_url":"https://api.github.com/repos/ushahidi/platform/issues{/number}","pulls_url":"https://api.github.com/repos/ushahidi/platform/pulls{/number}","milestones_url":"https://api.github.com/repos/ushahidi/platform/milestones{/number}","notifications_url":"https://api.github.com/repos/ushahidi/platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ushahidi/platform/labels{/name}","releases_url":"https://api.github.com/repos/ushahidi/platform/releases{/id}","deployments_url":"https://api.github.com/repos/ushahidi/platform/deployments","created_at":"2012-10-08T15:40:14Z","updated_at":"2018-04-09T16:54:03Z","pushed_at":"2018-04-09T18:03:52Z","git_url":"git://github.com/ushahidi/platform.git","ssh_url":"git@github.com:ushahidi/platform.git","clone_url":"https://github.com/ushahidi/platform.git","svn_url":"https://github.com/ushahidi/platform","homepage":"http://ushahidi.com","size":30091,"stargazers_count":455,"watchers_count":455,"language":"PHP","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":255,"mirror_url":null,"archived":false,"open_issues_count":621,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":255,"open_issues":621,"watchers":455,"default_branch":"develop"}},"base":{"label":"ushahidi:cycle-2-sms-api","ref":"cycle-2-sms-api","sha":"30da4320f4284ca9636fac6ea623724d2742ed4c","user":{"login":"ushahidi","id":16959,"avatar_url":"https://avatars3.githubusercontent.com/u/16959?v=4","gravatar_id":"","url":"https://api.github.com/users/ushahidi","html_url":"https://github.com/ushahidi","followers_url":"https://api.github.com/users/ushahidi/followers","following_url":"https://api.github.com/users/ushahidi/following{/other_user}","gists_url":"https://api.github.com/users/ushahidi/gists{/gist_id}","starred_url":"https://api.github.com/users/ushahidi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ushahidi/subscriptions","organizations_url":"https://api.github.com/users/ushahidi/orgs","repos_url":"https://api.github.com/users/ushahidi/repos","events_url":"https://api.github.com/users/ushahidi/events{/privacy}","received_events_url":"https://api.github.com/users/ushahidi/received_events","type":"Organization","site_admin":false},"repo":{"id":6126775,"name":"platform","full_name":"ushahidi/platform","owner":{"login":"ushahidi","id":16959,"avatar_url":"https://avatars3.githubusercontent.com/u/16959?v=4","gravatar_id":"","url":"https://api.github.com/users/ushahidi","html_url":"https://github.com/ushahidi","followers_url":"https://api.github.com/users/ushahidi/followers","following_url":"https://api.github.com/users/ushahidi/following{/other_user}","gists_url":"https://api.github.com/users/ushahidi/gists{/gist_id}","starred_url":"https://api.github.com/users/ushahidi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ushahidi/subscriptions","organizations_url":"https://api.github.com/users/ushahidi/orgs","repos_url":"https://api.github.com/users/ushahidi/repos","events_url":"https://api.github.com/users/ushahidi/events{/privacy}","received_events_url":"https://api.github.com/users/ushahidi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ushahidi/platform","description":"Ushahidi Platform v3 API","fork":false,"url":"https://api.github.com/repos/ushahidi/platform","forks_url":"https://api.github.com/repos/ushahidi/platform/forks","keys_url":"https://api.github.com/repos/ushahidi/platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ushahidi/platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ushahidi/platform/teams","hooks_url":"https://api.github.com/repos/ushahidi/platform/hooks","issue_events_url":"https://api.github.com/repos/ushahidi/platform/issues/events{/number}","events_url":"https://api.github.com/repos/ushahidi/platform/events","assignees_url":"https://api.github.com/repos/ushahidi/platform/assignees{/user}","branches_url":"https://api.github.com/repos/ushahidi/platform/branches{/branch}","tags_url":"https://api.github.com/repos/ushahidi/platform/tags","blobs_url":"https://api.github.com/repos/ushahidi/platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ushahidi/platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ushahidi/platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/ushahidi/platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ushahidi/platform/statuses/{sha}","languages_url":"https://api.github.com/repos/ushahidi/platform/languages","stargazers_url":"https://api.github.com/repos/ushahidi/platform/stargazers","contributors_url":"https://api.github.com/repos/ushahidi/platform/contributors","subscribers_url":"https://api.github.com/repos/ushahidi/platform/subscribers","subscription_url":"https://api.github.com/repos/ushahidi/platform/subscription","commits_url":"https://api.github.com/repos/ushahidi/platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/ushahidi/platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/ushahidi/platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/ushahidi/platform/issues/comments{/number}","contents_url":"https://api.github.com/repos/ushahidi/platform/contents/{+path}","compare_url":"https://api.github.com/repos/ushahidi/platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ushahidi/platform/merges","archive_url":"https://api.github.com/repos/ushahidi/platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ushahidi/platform/downloads","issues_url":"https://api.github.com/repos/ushahidi/platform/issues{/number}","pulls_url":"https://api.github.com/repos/ushahidi/platform/pulls{/number}","milestones_url":"https://api.github.com/repos/ushahidi/platform/milestones{/number}","notifications_url":"https://api.github.com/repos/ushahidi/platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ushahidi/platform/labels{/name}","releases_url":"https://api.github.com/repos/ushahidi/platform/releases{/id}","deployments_url":"https://api.github.com/repos/ushahidi/platform/deployments","created_at":"2012-10-08T15:40:14Z","updated_at":"2018-04-09T16:54:03Z","pushed_at":"2018-04-09T18:03:52Z","git_url":"git://github.com/ushahidi/platform.git","ssh_url":"git@github.com:ushahidi/platform.git","clone_url":"https://github.com/ushahidi/platform.git","svn_url":"https://github.com/ushahidi/platform","homepage":"http://ushahidi.com","size":30091,"stargazers_count":455,"watchers_count":455,"language":"PHP","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":255,"mirror_url":null,"archived":false,"open_issues_count":621,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":255,"open_issues":621,"watchers":455,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/ushahidi/platform/pulls/2712"},"html":{"href":"https://github.com/ushahidi/platform/pull/2712"},"issue":{"href":"https://api.github.com/repos/ushahidi/platform/issues/2712"},"comments":{"href":"https://api.github.com/repos/ushahidi/platform/issues/2712/comments"},"review_comments":{"href":"https://api.github.com/repos/ushahidi/platform/pulls/2712/comments"},"review_comment":{"href":"https://api.github.com/repos/ushahidi/platform/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ushahidi/platform/pulls/2712/commits"},"statuses":{"href":"https://api.github.com/repos/ushahidi/platform/statuses/48b5515a2bf54890327b744ffd66f27267475c7e"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"rowasc"}}