{"action":"created","comment":{"url":"https://api.github.com/repos/tidepool-org/chrome-uploader/pulls/comments/93601648","pull_request_review_id":14132157,"id":93601648,"diff_hunk":"@@ -426,6 +464,84 @@ function buildBGRecords(records) {\n   return postrecords;\n }\n \n+function buildCGMRecords(events) {\n+\n+  var postrecords = [];\n+  var start = null;\n+  var recordsSinceTimestamp = null;\n+\n+  // we have to work through the CGM records in reverse, as sensor timestamps\n+  // affect previous values and are subject to time changes\n+\n+  for( var i = events.length - 1 ; i >= 0; i-- ) {\n+    var event = events[i];\n+\n+    if(event.jsDate != false) {\n+      console.log('CGM event:',sundial.formatDeviceTime(event.jsDate), event.type.name, common.bytes2hex([event.head]),common.bytes2hex(event.date),common.bytes2hex(event.body),common.bytes2hex(event.descriptor) );\n+\n+      if(event.type.value === CBG_RECORD_TYPES.SENSOR_TIMESTAMP.value) {\n+        start = event.jsDate;\n+        recordsSinceTimestamp = 0;\n+      }\n+\n+      if(event.body) {\n+        var offset = event.body.length;\n+        var index = event.index - offset;\n+\n+        while(offset >= 0) {\n+\n+          var isig = struct.extractShort(event.descriptor, offset * 2);\n+\n+          if(isig !== 0x22 &&  isig > 255) {\n+            var cbg = (isig & 0x01) + (event.body[offset] << 1);\n+\n+            var date = sundial.applyOffset(start, -(recordsSinceTimestamp * 5));\n+            recordsSinceTimestamp += 1;\n+\n+            console.log('CBG:', sundial.formatDeviceTime(date), common.bytes2hex(struct.extractBytes(event.descriptor, offset * 2, 2)),',',common.bytes2hex([struct.extractByte(event.body,offset)]),',',(isig & 0x01) + (event.body[offset] << 1),',',(isig  & 0xFFFE) / 100.0);\n+            if(cbg >= 40) { // ignore magic numbers\n+              var record = cfg.builder.makeCBG()\n+                    .with_value(cbg)\n+                    .with_deviceTime(sundial.formatDeviceTime(date))\n+                    .with_units('mg/dL')      // TODO: check if mmol/L cbg is also hard-coded in mg/dL","path":"lib/medtronic/processData.js","position":236,"original_position":230,"commit_id":"21245397db9b00f3afbd487326f1d71f276989e8","original_commit_id":"75a53286d7ad8a605b4499e1da1d0a2f859d19fc","user":{"login":"gniezen","id":418233,"avatar_url":"https://avatars.githubusercontent.com/u/418233?v=3","gravatar_id":"","url":"https://api.github.com/users/gniezen","html_url":"https://github.com/gniezen","followers_url":"https://api.github.com/users/gniezen/followers","following_url":"https://api.github.com/users/gniezen/following{/other_user}","gists_url":"https://api.github.com/users/gniezen/gists{/gist_id}","starred_url":"https://api.github.com/users/gniezen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gniezen/subscriptions","organizations_url":"https://api.github.com/users/gniezen/orgs","repos_url":"https://api.github.com/users/gniezen/repos","events_url":"https://api.github.com/users/gniezen/events{/privacy}","received_events_url":"https://api.github.com/users/gniezen/received_events","type":"User","site_admin":false},"body":"Not a bad idea, but then we'll have to go back and do it for all the other drivers too? ;) I guess in this specific instance I prefer consistency to prevent confusion, and keep in mind that the data services API will validate the units on ingestion.","created_at":"2016-12-22T10:47:13Z","updated_at":"2016-12-22T10:47:13Z","html_url":"https://github.com/tidepool-org/chrome-uploader/pull/354#discussion_r93601648","pull_request_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/pulls/354","_links":{"self":{"href":"https://api.github.com/repos/tidepool-org/chrome-uploader/pulls/comments/93601648"},"html":{"href":"https://github.com/tidepool-org/chrome-uploader/pull/354#discussion_r93601648"},"pull_request":{"href":"https://api.github.com/repos/tidepool-org/chrome-uploader/pulls/354"}}},"pull_request":{"url":"https://api.github.com/repos/tidepool-org/chrome-uploader/pulls/354","id":97958350,"html_url":"https://github.com/tidepool-org/chrome-uploader/pull/354","diff_url":"https://github.com/tidepool-org/chrome-uploader/pull/354.diff","patch_url":"https://github.com/tidepool-org/chrome-uploader/pull/354.patch","issue_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/issues/354","number":354,"state":"open","locked":false,"title":"Medtronic CGM data","user":{"login":"gniezen","id":418233,"avatar_url":"https://avatars.githubusercontent.com/u/418233?v=3","gravatar_id":"","url":"https://api.github.com/users/gniezen","html_url":"https://github.com/gniezen","followers_url":"https://api.github.com/users/gniezen/followers","following_url":"https://api.github.com/users/gniezen/following{/other_user}","gists_url":"https://api.github.com/users/gniezen/gists{/gist_id}","starred_url":"https://api.github.com/users/gniezen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gniezen/subscriptions","organizations_url":"https://api.github.com/users/gniezen/orgs","repos_url":"https://api.github.com/users/gniezen/repos","events_url":"https://api.github.com/users/gniezen/events{/privacy}","received_events_url":"https://api.github.com/users/gniezen/received_events","type":"User","site_admin":false},"body":"See https://trello.com/c/vMtU8xkK for more details","created_at":"2016-12-14T14:07:39Z","updated_at":"2016-12-22T10:47:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ec863e06ef7e2693fc13e29d36d05bc5c9d2eeb4","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/pulls/354/commits","review_comments_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/pulls/354/comments","review_comment_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/pulls/comments{/number}","comments_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/issues/354/comments","statuses_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/statuses/21245397db9b00f3afbd487326f1d71f276989e8","head":{"label":"tidepool-org:gniezen/medtronic-cbg","ref":"gniezen/medtronic-cbg","sha":"21245397db9b00f3afbd487326f1d71f276989e8","user":{"login":"tidepool-org","id":4390820,"avatar_url":"https://avatars.githubusercontent.com/u/4390820?v=3","gravatar_id":"","url":"https://api.github.com/users/tidepool-org","html_url":"https://github.com/tidepool-org","followers_url":"https://api.github.com/users/tidepool-org/followers","following_url":"https://api.github.com/users/tidepool-org/following{/other_user}","gists_url":"https://api.github.com/users/tidepool-org/gists{/gist_id}","starred_url":"https://api.github.com/users/tidepool-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tidepool-org/subscriptions","organizations_url":"https://api.github.com/users/tidepool-org/orgs","repos_url":"https://api.github.com/users/tidepool-org/repos","events_url":"https://api.github.com/users/tidepool-org/events{/privacy}","received_events_url":"https://api.github.com/users/tidepool-org/received_events","type":"Organization","site_admin":false},"repo":{"id":20790599,"name":"chrome-uploader","full_name":"tidepool-org/chrome-uploader","owner":{"login":"tidepool-org","id":4390820,"avatar_url":"https://avatars.githubusercontent.com/u/4390820?v=3","gravatar_id":"","url":"https://api.github.com/users/tidepool-org","html_url":"https://github.com/tidepool-org","followers_url":"https://api.github.com/users/tidepool-org/followers","following_url":"https://api.github.com/users/tidepool-org/following{/other_user}","gists_url":"https://api.github.com/users/tidepool-org/gists{/gist_id}","starred_url":"https://api.github.com/users/tidepool-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tidepool-org/subscriptions","organizations_url":"https://api.github.com/users/tidepool-org/orgs","repos_url":"https://api.github.com/users/tidepool-org/repos","events_url":"https://api.github.com/users/tidepool-org/events{/privacy}","received_events_url":"https://api.github.com/users/tidepool-org/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/tidepool-org/chrome-uploader","description":"A Chrome app for uploading diabetes device data to Tidepool's backend","fork":false,"url":"https://api.github.com/repos/tidepool-org/chrome-uploader","forks_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/forks","keys_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/teams","hooks_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/hooks","issue_events_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/issues/events{/number}","events_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/events","assignees_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/assignees{/user}","branches_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/branches{/branch}","tags_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/tags","blobs_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/git/refs{/sha}","trees_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/statuses/{sha}","languages_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/languages","stargazers_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/stargazers","contributors_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/contributors","subscribers_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/subscribers","subscription_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/subscription","commits_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/commits{/sha}","git_commits_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/git/commits{/sha}","comments_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/comments{/number}","issue_comment_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/issues/comments{/number}","contents_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/contents/{+path}","compare_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/merges","archive_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/downloads","issues_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/issues{/number}","pulls_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/pulls{/number}","milestones_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/milestones{/number}","notifications_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/labels{/name}","releases_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/releases{/id}","deployments_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/deployments","created_at":"2014-06-13T03:12:49Z","updated_at":"2016-11-22T18:25:52Z","pushed_at":"2016-12-22T10:39:38Z","git_url":"git://github.com/tidepool-org/chrome-uploader.git","ssh_url":"git@github.com:tidepool-org/chrome-uploader.git","clone_url":"https://github.com/tidepool-org/chrome-uploader.git","svn_url":"https://github.com/tidepool-org/chrome-uploader","homepage":"","size":7252,"stargazers_count":26,"watchers_count":26,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":25,"mirror_url":null,"open_issues_count":9,"forks":25,"open_issues":9,"watchers":26,"default_branch":"master"}},"base":{"label":"tidepool-org:gniezen/medtronic","ref":"gniezen/medtronic","sha":"39822baf010b4d710e95353fd0929a99d1ab3277","user":{"login":"tidepool-org","id":4390820,"avatar_url":"https://avatars.githubusercontent.com/u/4390820?v=3","gravatar_id":"","url":"https://api.github.com/users/tidepool-org","html_url":"https://github.com/tidepool-org","followers_url":"https://api.github.com/users/tidepool-org/followers","following_url":"https://api.github.com/users/tidepool-org/following{/other_user}","gists_url":"https://api.github.com/users/tidepool-org/gists{/gist_id}","starred_url":"https://api.github.com/users/tidepool-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tidepool-org/subscriptions","organizations_url":"https://api.github.com/users/tidepool-org/orgs","repos_url":"https://api.github.com/users/tidepool-org/repos","events_url":"https://api.github.com/users/tidepool-org/events{/privacy}","received_events_url":"https://api.github.com/users/tidepool-org/received_events","type":"Organization","site_admin":false},"repo":{"id":20790599,"name":"chrome-uploader","full_name":"tidepool-org/chrome-uploader","owner":{"login":"tidepool-org","id":4390820,"avatar_url":"https://avatars.githubusercontent.com/u/4390820?v=3","gravatar_id":"","url":"https://api.github.com/users/tidepool-org","html_url":"https://github.com/tidepool-org","followers_url":"https://api.github.com/users/tidepool-org/followers","following_url":"https://api.github.com/users/tidepool-org/following{/other_user}","gists_url":"https://api.github.com/users/tidepool-org/gists{/gist_id}","starred_url":"https://api.github.com/users/tidepool-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tidepool-org/subscriptions","organizations_url":"https://api.github.com/users/tidepool-org/orgs","repos_url":"https://api.github.com/users/tidepool-org/repos","events_url":"https://api.github.com/users/tidepool-org/events{/privacy}","received_events_url":"https://api.github.com/users/tidepool-org/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/tidepool-org/chrome-uploader","description":"A Chrome app for uploading diabetes device data to Tidepool's backend","fork":false,"url":"https://api.github.com/repos/tidepool-org/chrome-uploader","forks_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/forks","keys_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/teams","hooks_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/hooks","issue_events_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/issues/events{/number}","events_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/events","assignees_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/assignees{/user}","branches_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/branches{/branch}","tags_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/tags","blobs_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/git/refs{/sha}","trees_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/statuses/{sha}","languages_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/languages","stargazers_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/stargazers","contributors_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/contributors","subscribers_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/subscribers","subscription_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/subscription","commits_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/commits{/sha}","git_commits_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/git/commits{/sha}","comments_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/comments{/number}","issue_comment_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/issues/comments{/number}","contents_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/contents/{+path}","compare_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/merges","archive_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/downloads","issues_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/issues{/number}","pulls_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/pulls{/number}","milestones_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/milestones{/number}","notifications_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/labels{/name}","releases_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/releases{/id}","deployments_url":"https://api.github.com/repos/tidepool-org/chrome-uploader/deployments","created_at":"2014-06-13T03:12:49Z","updated_at":"2016-11-22T18:25:52Z","pushed_at":"2016-12-22T10:39:38Z","git_url":"git://github.com/tidepool-org/chrome-uploader.git","ssh_url":"git@github.com:tidepool-org/chrome-uploader.git","clone_url":"https://github.com/tidepool-org/chrome-uploader.git","svn_url":"https://github.com/tidepool-org/chrome-uploader","homepage":"","size":7252,"stargazers_count":26,"watchers_count":26,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":25,"mirror_url":null,"open_issues_count":9,"forks":25,"open_issues":9,"watchers":26,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/tidepool-org/chrome-uploader/pulls/354"},"html":{"href":"https://github.com/tidepool-org/chrome-uploader/pull/354"},"issue":{"href":"https://api.github.com/repos/tidepool-org/chrome-uploader/issues/354"},"comments":{"href":"https://api.github.com/repos/tidepool-org/chrome-uploader/issues/354/comments"},"review_comments":{"href":"https://api.github.com/repos/tidepool-org/chrome-uploader/pulls/354/comments"},"review_comment":{"href":"https://api.github.com/repos/tidepool-org/chrome-uploader/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/tidepool-org/chrome-uploader/pulls/354/commits"},"statuses":{"href":"https://api.github.com/repos/tidepool-org/chrome-uploader/statuses/21245397db9b00f3afbd487326f1d71f276989e8"}}}}
{"actor":{"display_login":"gniezen"}}