{"action":"created","comment":{"url":"https://api.github.com/repos/CrisisTextLine/Elmer/pulls/comments/68618507","id":68618507,"diff_hunk":"@@ -0,0 +1,225 @@\n+var CronJob = require('cron').CronJob;\n+var canvas = require('../../canvas.js');\n+var bignumJSON = require('json-bignum');\n+var Request = require('request');\n+var mandrill = require('mandrill-api/mandrill');\n+var mandrill_client = new mandrill.Mandrill(KEYS.mandrill.api_key);\n+var fs = require('fs');\n+\n+//runs crone job every day at 5am\n+new CronJob(CONFIG.time_interval.gtw_attendance_sync_with_canvas, function () {\n+   scrapeGTWSessions();\n+}, null, true);\n+\n+//gets all webinar sessions in a specified time period\n+function scrapeGTWSessions(){\n+  var keysArr = [];\n+  var time = urlTime();\n+  var endTime = time.endDate;\n+  var startTime = time.startDate;\n+\n+\tvar url = 'https://api.citrixonline.com/G2W/rest/organizers/'+KEYS.GTW.org_id+'/sessions?fromTime='+startTime+'&toTime='+endTime;\n+\tvar options = {\n+  \t\turl: url,\n+  \t\theaders: {\n+  \t\tAccept: 'application/json',\n+    \tAuthorization: KEYS.GTW.api_key\n+      }\n+\t};\n+\n+\tfunction callback(e, r, b) {\n+  \t\tif (!e && r.statusCode == 200) {\n+        //we need bignumJSON because JS rounds GTW session ids otherwise\n+\t   \t\tvar info = bignumJSON.parse(b);\n+        if(info.length===0){\n+          CONSOLE_WITH_TIME('NO SESSIONS DURING', startTime, 'and', endTime, '!');\n+          return;\n+        }\n+\t   \t\tinfo.forEach(function(webinar){\n+\t   \t\t\tkeysArr.push({webinarKey: webinar.webinarKey.toString(), sessionKey: webinar.sessionKey.toString()});\n+\t   \t\t});\n+\t   \t\tscrapeGTWAttendees(keysArr);\n+  \t\t} else {\n+  \t\t\tCONSOLE_WITH_TIME(\"GTW get all webinars error message: \", b);\n+  \t\t}\n+\t}\n+\n+\tRequest.get(options, callback);\n+}\n+\n+//gets all webinar attendees for each session\n+function scrapeGTWAttendees(keysArr){\n+\n+\tfunction callback(e, r, b) {\n+  \t\tif (!e && r.statusCode == 200) {\n+\t   \t\tvar info = bignumJSON.parse(b);\n+\t   \t\tcheckForDupUsersInGTWFilterForThoseWhoAttendedLessThan90Mins(info);\n+  \t\t} else {\n+  \t\t\tCONSOLE_WITH_TIME(\"GTW get all webinar attendees error message: \", b);\n+  \t\t}\n+\t}\n+\n+\tkeysArr.forEach(function(id){\n+\t\tvar url = 'https://api.citrixonline.com/G2W/rest/organizers/'+KEYS.GTW.org_id+'/webinars/'+id.webinarKey+'/sessions/'+id.sessionKey+'/attendees';\n+\t\tvar options = {\n+  \t\turl: url,\n+  \t\theaders: {\n+    \tAuthorization: KEYS.GTW.api_key\n+  \t\t\t}\n+\t\t};\n+\t\tRequest.get(options, callback);\n+\t});\n+}\n+\n+//removes duplicate emails, calculates attended time and filters out users who attended for less than 90 minutes.\n+function checkForDupUsersInGTWFilterForThoseWhoAttendedLessThan90Mins(arr){\n+\tvar last;\n+  var GTWusers = [];\n+\n+\tarr.forEach(function(user, index){\n+\t\tif(!last){\n+\t\tlast = {firstName: user.firstName, lastName: user.lastName, email: user.email, attendance: user.attendanceTimeInSeconds};\n+\t\t} else {\n+\t\t\tif(last.email == user.email){\n+\t\t\t\tlast.attendance+=user.attendanceTimeInSeconds;\n+\t\t\t} else {\n+\t\t\t\tif(last.attendance>=CONFIG.GTW_attendance_minimum) {GTWusers.push(last);}\n+\t\t\t\tlast = {firstName: user.firstName, lastName: user.lastName, email: user.email, attendance: user.attendanceTimeInSeconds};\n+\t\t\t}\n+\t\t\tif(arr.length-1==index){\n+\t\t\t GTWusers.push(last);\n+\n+\t\t\t}\n+\t\t}\n+\t});\n+  //stops the script if GTWusers array is empty\n+  if(!GTWusers) { \n+    CONSOLE_WITH_TIME('None of the scrapped GTW users attended a webinar for 90 minutes or more.');\n+     return;\n+   } else {\n+    findCanvasUsersEmail(GTWusers);\n+  }\n+}\n+\n+//scrapes canvas for user by email, course and assignment id's\n+function findCanvasUsersEmail(GTWusers){\n+  var Uurl = 'https://crisistextline.instructure.com/api/v1/accounts/1/users';\n+  \n+  GTWusers.forEach(function(guser){","path":"jobs/scheduling/AttendanceSync.js","position":108,"original_position":108,"commit_id":"400b35ccd612c48749945e24b96f66f1d43ac1b2","original_commit_id":"400b35ccd612c48749945e24b96f66f1d43ac1b2","user":{"login":"tongxiang","id":5678066,"avatar_url":"https://avatars.githubusercontent.com/u/5678066?v=3","gravatar_id":"","url":"https://api.github.com/users/tongxiang","html_url":"https://github.com/tongxiang","followers_url":"https://api.github.com/users/tongxiang/followers","following_url":"https://api.github.com/users/tongxiang/following{/other_user}","gists_url":"https://api.github.com/users/tongxiang/gists{/gist_id}","starred_url":"https://api.github.com/users/tongxiang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tongxiang/subscriptions","organizations_url":"https://api.github.com/users/tongxiang/orgs","repos_url":"https://api.github.com/users/tongxiang/repos","events_url":"https://api.github.com/users/tongxiang/events{/privacy}","received_events_url":"https://api.github.com/users/tongxiang/received_events","type":"User","site_admin":false},"body":"`guser` vs. `user` variable declarations are unclear here. ","created_at":"2016-06-27T17:24:04Z","updated_at":"2016-06-27T17:24:04Z","html_url":"https://github.com/CrisisTextLine/Elmer/pull/126#discussion_r68618507","pull_request_url":"https://api.github.com/repos/CrisisTextLine/Elmer/pulls/126","_links":{"self":{"href":"https://api.github.com/repos/CrisisTextLine/Elmer/pulls/comments/68618507"},"html":{"href":"https://github.com/CrisisTextLine/Elmer/pull/126#discussion_r68618507"},"pull_request":{"href":"https://api.github.com/repos/CrisisTextLine/Elmer/pulls/126"}}},"pull_request":{"url":"https://api.github.com/repos/CrisisTextLine/Elmer/pulls/126","id":74686754,"html_url":"https://github.com/CrisisTextLine/Elmer/pull/126","diff_url":"https://github.com/CrisisTextLine/Elmer/pull/126.diff","patch_url":"https://github.com/CrisisTextLine/Elmer/pull/126.patch","issue_url":"https://api.github.com/repos/CrisisTextLine/Elmer/issues/126","number":126,"state":"closed","locked":false,"title":"Gtw integration","user":{"login":"mbogor","id":16216164,"avatar_url":"https://avatars.githubusercontent.com/u/16216164?v=3","gravatar_id":"","url":"https://api.github.com/users/mbogor","html_url":"https://github.com/mbogor","followers_url":"https://api.github.com/users/mbogor/followers","following_url":"https://api.github.com/users/mbogor/following{/other_user}","gists_url":"https://api.github.com/users/mbogor/gists{/gist_id}","starred_url":"https://api.github.com/users/mbogor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbogor/subscriptions","organizations_url":"https://api.github.com/users/mbogor/orgs","repos_url":"https://api.github.com/users/mbogor/repos","events_url":"https://api.github.com/users/mbogor/events{/privacy}","received_events_url":"https://api.github.com/users/mbogor/received_events","type":"User","site_admin":false},"body":"#### What's this PR do?\r\nautomates canvas grading for attending GTW observation\r\n#### Where should the reviewer start?\r\n#### How should this be manually tested?\r\n#### Any background context you want to provide?\r\n#### What are the relevant tickets?\r\n#### Questions:\r\n","created_at":"2016-06-21T21:14:53Z","updated_at":"2016-06-27T17:24:04Z","closed_at":"2016-06-27T14:21:57Z","merged_at":"2016-06-27T14:21:57Z","merge_commit_sha":"8b332a2e41ed6aff1953d5ec2d4efd60f9284530","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/CrisisTextLine/Elmer/pulls/126/commits","review_comments_url":"https://api.github.com/repos/CrisisTextLine/Elmer/pulls/126/comments","review_comment_url":"https://api.github.com/repos/CrisisTextLine/Elmer/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CrisisTextLine/Elmer/issues/126/comments","statuses_url":"https://api.github.com/repos/CrisisTextLine/Elmer/statuses/400b35ccd612c48749945e24b96f66f1d43ac1b2","head":{"label":"CrisisTextLine:GTWintegration","ref":"GTWintegration","sha":"400b35ccd612c48749945e24b96f66f1d43ac1b2","user":{"login":"CrisisTextLine","id":3536558,"avatar_url":"https://avatars.githubusercontent.com/u/3536558?v=3","gravatar_id":"","url":"https://api.github.com/users/CrisisTextLine","html_url":"https://github.com/CrisisTextLine","followers_url":"https://api.github.com/users/CrisisTextLine/followers","following_url":"https://api.github.com/users/CrisisTextLine/following{/other_user}","gists_url":"https://api.github.com/users/CrisisTextLine/gists{/gist_id}","starred_url":"https://api.github.com/users/CrisisTextLine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CrisisTextLine/subscriptions","organizations_url":"https://api.github.com/users/CrisisTextLine/orgs","repos_url":"https://api.github.com/users/CrisisTextLine/repos","events_url":"https://api.github.com/users/CrisisTextLine/events{/privacy}","received_events_url":"https://api.github.com/users/CrisisTextLine/received_events","type":"Organization","site_admin":false},"repo":{"id":47287892,"name":"Elmer","full_name":"CrisisTextLine/Elmer","owner":{"login":"CrisisTextLine","id":3536558,"avatar_url":"https://avatars.githubusercontent.com/u/3536558?v=3","gravatar_id":"","url":"https://api.github.com/users/CrisisTextLine","html_url":"https://github.com/CrisisTextLine","followers_url":"https://api.github.com/users/CrisisTextLine/followers","following_url":"https://api.github.com/users/CrisisTextLine/following{/other_user}","gists_url":"https://api.github.com/users/CrisisTextLine/gists{/gist_id}","starred_url":"https://api.github.com/users/CrisisTextLine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CrisisTextLine/subscriptions","organizations_url":"https://api.github.com/users/CrisisTextLine/orgs","repos_url":"https://api.github.com/users/CrisisTextLine/repos","events_url":"https://api.github.com/users/CrisisTextLine/events{/privacy}","received_events_url":"https://api.github.com/users/CrisisTextLine/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CrisisTextLine/Elmer","description":"","fork":false,"url":"https://api.github.com/repos/CrisisTextLine/Elmer","forks_url":"https://api.github.com/repos/CrisisTextLine/Elmer/forks","keys_url":"https://api.github.com/repos/CrisisTextLine/Elmer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CrisisTextLine/Elmer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CrisisTextLine/Elmer/teams","hooks_url":"https://api.github.com/repos/CrisisTextLine/Elmer/hooks","issue_events_url":"https://api.github.com/repos/CrisisTextLine/Elmer/issues/events{/number}","events_url":"https://api.github.com/repos/CrisisTextLine/Elmer/events","assignees_url":"https://api.github.com/repos/CrisisTextLine/Elmer/assignees{/user}","branches_url":"https://api.github.com/repos/CrisisTextLine/Elmer/branches{/branch}","tags_url":"https://api.github.com/repos/CrisisTextLine/Elmer/tags","blobs_url":"https://api.github.com/repos/CrisisTextLine/Elmer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CrisisTextLine/Elmer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CrisisTextLine/Elmer/git/refs{/sha}","trees_url":"https://api.github.com/repos/CrisisTextLine/Elmer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CrisisTextLine/Elmer/statuses/{sha}","languages_url":"https://api.github.com/repos/CrisisTextLine/Elmer/languages","stargazers_url":"https://api.github.com/repos/CrisisTextLine/Elmer/stargazers","contributors_url":"https://api.github.com/repos/CrisisTextLine/Elmer/contributors","subscribers_url":"https://api.github.com/repos/CrisisTextLine/Elmer/subscribers","subscription_url":"https://api.github.com/repos/CrisisTextLine/Elmer/subscription","commits_url":"https://api.github.com/repos/CrisisTextLine/Elmer/commits{/sha}","git_commits_url":"https://api.github.com/repos/CrisisTextLine/Elmer/git/commits{/sha}","comments_url":"https://api.github.com/repos/CrisisTextLine/Elmer/comments{/number}","issue_comment_url":"https://api.github.com/repos/CrisisTextLine/Elmer/issues/comments{/number}","contents_url":"https://api.github.com/repos/CrisisTextLine/Elmer/contents/{+path}","compare_url":"https://api.github.com/repos/CrisisTextLine/Elmer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CrisisTextLine/Elmer/merges","archive_url":"https://api.github.com/repos/CrisisTextLine/Elmer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CrisisTextLine/Elmer/downloads","issues_url":"https://api.github.com/repos/CrisisTextLine/Elmer/issues{/number}","pulls_url":"https://api.github.com/repos/CrisisTextLine/Elmer/pulls{/number}","milestones_url":"https://api.github.com/repos/CrisisTextLine/Elmer/milestones{/number}","notifications_url":"https://api.github.com/repos/CrisisTextLine/Elmer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CrisisTextLine/Elmer/labels{/name}","releases_url":"https://api.github.com/repos/CrisisTextLine/Elmer/releases{/id}","deployments_url":"https://api.github.com/repos/CrisisTextLine/Elmer/deployments","created_at":"2015-12-02T20:51:51Z","updated_at":"2016-05-30T18:08:39Z","pushed_at":"2016-06-27T15:31:07Z","git_url":"git://github.com/CrisisTextLine/Elmer.git","ssh_url":"git@github.com:CrisisTextLine/Elmer.git","clone_url":"https://github.com/CrisisTextLine/Elmer.git","svn_url":"https://github.com/CrisisTextLine/Elmer","homepage":null,"size":422,"stargazers_count":2,"watchers_count":2,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":7,"forks":0,"open_issues":7,"watchers":2,"default_branch":"master"}},"base":{"label":"CrisisTextLine:master","ref":"master","sha":"5511b5ea0211b91beecc9e37ac9041e9fea03139","user":{"login":"CrisisTextLine","id":3536558,"avatar_url":"https://avatars.githubusercontent.com/u/3536558?v=3","gravatar_id":"","url":"https://api.github.com/users/CrisisTextLine","html_url":"https://github.com/CrisisTextLine","followers_url":"https://api.github.com/users/CrisisTextLine/followers","following_url":"https://api.github.com/users/CrisisTextLine/following{/other_user}","gists_url":"https://api.github.com/users/CrisisTextLine/gists{/gist_id}","starred_url":"https://api.github.com/users/CrisisTextLine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CrisisTextLine/subscriptions","organizations_url":"https://api.github.com/users/CrisisTextLine/orgs","repos_url":"https://api.github.com/users/CrisisTextLine/repos","events_url":"https://api.github.com/users/CrisisTextLine/events{/privacy}","received_events_url":"https://api.github.com/users/CrisisTextLine/received_events","type":"Organization","site_admin":false},"repo":{"id":47287892,"name":"Elmer","full_name":"CrisisTextLine/Elmer","owner":{"login":"CrisisTextLine","id":3536558,"avatar_url":"https://avatars.githubusercontent.com/u/3536558?v=3","gravatar_id":"","url":"https://api.github.com/users/CrisisTextLine","html_url":"https://github.com/CrisisTextLine","followers_url":"https://api.github.com/users/CrisisTextLine/followers","following_url":"https://api.github.com/users/CrisisTextLine/following{/other_user}","gists_url":"https://api.github.com/users/CrisisTextLine/gists{/gist_id}","starred_url":"https://api.github.com/users/CrisisTextLine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CrisisTextLine/subscriptions","organizations_url":"https://api.github.com/users/CrisisTextLine/orgs","repos_url":"https://api.github.com/users/CrisisTextLine/repos","events_url":"https://api.github.com/users/CrisisTextLine/events{/privacy}","received_events_url":"https://api.github.com/users/CrisisTextLine/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CrisisTextLine/Elmer","description":"","fork":false,"url":"https://api.github.com/repos/CrisisTextLine/Elmer","forks_url":"https://api.github.com/repos/CrisisTextLine/Elmer/forks","keys_url":"https://api.github.com/repos/CrisisTextLine/Elmer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CrisisTextLine/Elmer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CrisisTextLine/Elmer/teams","hooks_url":"https://api.github.com/repos/CrisisTextLine/Elmer/hooks","issue_events_url":"https://api.github.com/repos/CrisisTextLine/Elmer/issues/events{/number}","events_url":"https://api.github.com/repos/CrisisTextLine/Elmer/events","assignees_url":"https://api.github.com/repos/CrisisTextLine/Elmer/assignees{/user}","branches_url":"https://api.github.com/repos/CrisisTextLine/Elmer/branches{/branch}","tags_url":"https://api.github.com/repos/CrisisTextLine/Elmer/tags","blobs_url":"https://api.github.com/repos/CrisisTextLine/Elmer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CrisisTextLine/Elmer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CrisisTextLine/Elmer/git/refs{/sha}","trees_url":"https://api.github.com/repos/CrisisTextLine/Elmer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CrisisTextLine/Elmer/statuses/{sha}","languages_url":"https://api.github.com/repos/CrisisTextLine/Elmer/languages","stargazers_url":"https://api.github.com/repos/CrisisTextLine/Elmer/stargazers","contributors_url":"https://api.github.com/repos/CrisisTextLine/Elmer/contributors","subscribers_url":"https://api.github.com/repos/CrisisTextLine/Elmer/subscribers","subscription_url":"https://api.github.com/repos/CrisisTextLine/Elmer/subscription","commits_url":"https://api.github.com/repos/CrisisTextLine/Elmer/commits{/sha}","git_commits_url":"https://api.github.com/repos/CrisisTextLine/Elmer/git/commits{/sha}","comments_url":"https://api.github.com/repos/CrisisTextLine/Elmer/comments{/number}","issue_comment_url":"https://api.github.com/repos/CrisisTextLine/Elmer/issues/comments{/number}","contents_url":"https://api.github.com/repos/CrisisTextLine/Elmer/contents/{+path}","compare_url":"https://api.github.com/repos/CrisisTextLine/Elmer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CrisisTextLine/Elmer/merges","archive_url":"https://api.github.com/repos/CrisisTextLine/Elmer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CrisisTextLine/Elmer/downloads","issues_url":"https://api.github.com/repos/CrisisTextLine/Elmer/issues{/number}","pulls_url":"https://api.github.com/repos/CrisisTextLine/Elmer/pulls{/number}","milestones_url":"https://api.github.com/repos/CrisisTextLine/Elmer/milestones{/number}","notifications_url":"https://api.github.com/repos/CrisisTextLine/Elmer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CrisisTextLine/Elmer/labels{/name}","releases_url":"https://api.github.com/repos/CrisisTextLine/Elmer/releases{/id}","deployments_url":"https://api.github.com/repos/CrisisTextLine/Elmer/deployments","created_at":"2015-12-02T20:51:51Z","updated_at":"2016-05-30T18:08:39Z","pushed_at":"2016-06-27T15:31:07Z","git_url":"git://github.com/CrisisTextLine/Elmer.git","ssh_url":"git@github.com:CrisisTextLine/Elmer.git","clone_url":"https://github.com/CrisisTextLine/Elmer.git","svn_url":"https://github.com/CrisisTextLine/Elmer","homepage":null,"size":422,"stargazers_count":2,"watchers_count":2,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":7,"forks":0,"open_issues":7,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/CrisisTextLine/Elmer/pulls/126"},"html":{"href":"https://github.com/CrisisTextLine/Elmer/pull/126"},"issue":{"href":"https://api.github.com/repos/CrisisTextLine/Elmer/issues/126"},"comments":{"href":"https://api.github.com/repos/CrisisTextLine/Elmer/issues/126/comments"},"review_comments":{"href":"https://api.github.com/repos/CrisisTextLine/Elmer/pulls/126/comments"},"review_comment":{"href":"https://api.github.com/repos/CrisisTextLine/Elmer/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CrisisTextLine/Elmer/pulls/126/commits"},"statuses":{"href":"https://api.github.com/repos/CrisisTextLine/Elmer/statuses/400b35ccd612c48749945e24b96f66f1d43ac1b2"}}}}
{"actor":{"display_login":"tongxiang"}}