{"action":"created","comment":{"url":"https://api.github.com/repos/roqua/physiqual/pulls/comments/41699950","id":41699950,"diff_hunk":"@@ -2,25 +2,31 @@ module Physiqual\n   module BucketGenerators\n     class EquidistantBucketGenerator\n       include BucketGenerator\n-      def initialize(measurements_per_day, interval, last_measurement_time)\n+      def initialize(measurements_per_day, interval, hours_before_first_measurement)\n         @measurements_per_day = measurements_per_day\n         @interval = interval\n-        @last_measurement_time = last_measurement_time\n+        @hours_before_first_measurement = hours_before_first_measurement\n       end\n \n       def generate(from, to)\n-        from = from.beginning_of_day.to_datetime\n-        to = to.beginning_of_day.to_datetime\n+        currently = Time.zone.now\n+        first_measurement_of_the_day = from\n+        bucket_start = -1\n+        bucket_end = -1\n         result = []\n-        start = @last_measurement_time.hour - ((@measurements_per_day - 1) * @interval)\n-        from.to_date.upto(to.to_date).map do |date|\n-          (0...@measurements_per_day).map do |measurement|\n-            current = date.to_time.change(hour: start + (measurement * @interval),\n-                                          min: @last_measurement_time.min)\n-\n-            # Only use dates that are in the past\n-            result << output_entry(current.to_time, []) if date < Time.zone.now\n+        loop do\n+          @measurements_per_day.times do |measurement_index|\n+            if measurement_index == 0\n+              bucket_start = first_measurement_of_the_day\n+              bucket_end   = bucket_start + @hours_before_first_measurement.hours","path":"lib/physiqual/bucket_generators/equidistant_bucket_generator.rb","position":32,"original_position":32,"commit_id":"eb72a5506fcc921ffbbba83056983104ea27e977","original_commit_id":"eb72a5506fcc921ffbbba83056983104ea27e977","user":{"login":"frbl","id":617574,"avatar_url":"https://avatars.githubusercontent.com/u/617574?v=3","gravatar_id":"","url":"https://api.github.com/users/frbl","html_url":"https://github.com/frbl","followers_url":"https://api.github.com/users/frbl/followers","following_url":"https://api.github.com/users/frbl/following{/other_user}","gists_url":"https://api.github.com/users/frbl/gists{/gist_id}","starred_url":"https://api.github.com/users/frbl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/frbl/subscriptions","organizations_url":"https://api.github.com/users/frbl/orgs","repos_url":"https://api.github.com/users/frbl/repos","events_url":"https://api.github.com/users/frbl/events{/privacy}","received_events_url":"https://api.github.com/users/frbl/received_events","type":"User","site_admin":false},"body":"moet dit niet - zijn? of begrijp ik hem verkeerd","created_at":"2015-10-10T18:22:16Z","updated_at":"2015-10-10T18:22:16Z","html_url":"https://github.com/roqua/physiqual/pull/43#discussion_r41699950","pull_request_url":"https://api.github.com/repos/roqua/physiqual/pulls/43","_links":{"self":{"href":"https://api.github.com/repos/roqua/physiqual/pulls/comments/41699950"},"html":{"href":"https://github.com/roqua/physiqual/pull/43#discussion_r41699950"},"pull_request":{"href":"https://api.github.com/repos/roqua/physiqual/pulls/43"}}},"pull_request":{"url":"https://api.github.com/repos/roqua/physiqual/pulls/43","id":47348278,"html_url":"https://github.com/roqua/physiqual/pull/43","diff_url":"https://github.com/roqua/physiqual/pull/43.diff","patch_url":"https://github.com/roqua/physiqual/pull/43.patch","issue_url":"https://api.github.com/repos/roqua/physiqual/issues/43","number":43,"state":"open","locked":false,"title":"Reworking timings","user":{"login":"emerencia","id":607965,"avatar_url":"https://avatars.githubusercontent.com/u/607965?v=3","gravatar_id":"","url":"https://api.github.com/users/emerencia","html_url":"https://github.com/emerencia","followers_url":"https://api.github.com/users/emerencia/followers","following_url":"https://api.github.com/users/emerencia/following{/other_user}","gists_url":"https://api.github.com/users/emerencia/gists{/gist_id}","starred_url":"https://api.github.com/users/emerencia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emerencia/subscriptions","organizations_url":"https://api.github.com/users/emerencia/orgs","repos_url":"https://api.github.com/users/emerencia/repos","events_url":"https://api.github.com/users/emerencia/events{/privacy}","received_events_url":"https://api.github.com/users/emerencia/received_events","type":"User","site_admin":false},"body":"The `use_night` setting was replaced with the `hours_before_first_measurement` setting. This works with both the equidistant bucket generator as well as the daily bucket generator.\r\n\r\nAn export data request now only takes two parameters: `first_measurement` and `number_of_days`. The first_measurement is the date and time of the first measurement of the diary study for a user. For equidistant time intervals, the schedule for the measurements is derived by looking at the time of this measurement. The number of days is the number of days the user followed the diary study.\r\n\r\nOnly the exporter knows the start time and number of measurements for a user's diary study. The DataServices and bucket generator objects only know project global measurements_per_day, interval, and hours_before_first_measurement variables. The data ranges are captured using `from` and `to` arguments which are constructed by the exporter.\r\n\r\nThe `from` argument is the first time at which we want to start considering data points for this user. It is defined by the exporter as `first_measurement - hours_before_first_measurement.hours`. Note that this can fall on a previous day, which is fine. The `to` argument is the last time after which we stop considering data points. This is the time of the last measurement on the last day of the diary study of the user.\r\n\r\nThe methods that query the Google and Fitbit services receive the `from` and `to` arguments, and convert those either to dates or to nanosecond time offsets: either way they work to capture at least all and possibly more data than we are interested in. Possible data measurements that we receive from Google or Fitbit that we are not interested in (i.e., that occurred either before the `from`, after the `to` or during the night (which is defined by the engine global variable `Physiqual.hours_before_first_measurement`)) are discarded by the SummarizedDataService.\r\n\r\nThe SummarizedDataServices discards the extra measurements using extra information returned by the bucket generator. In addition to the end datetimestamp of each bucket, the bucket generator now also returns the start time for each bucket. This start time is defined as either the end time - hours_before_first_measurement for the first measurement of the day, or as the end time of the previous measurement on that day. This works with both the Equidistant bucket generator as well as the daily bucket generator. Having both the start and end ranges for each bucket, the SummarizedDataService now knows which data to discard. It also discards the extra bucket start time information so that its output is compatible with those of other data services.\r\n","created_at":"2015-10-10T16:03:28Z","updated_at":"2015-10-10T18:22:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e582953f296e55d67930400a5ba3aa83ea9aa481","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/roqua/physiqual/pulls/43/commits","review_comments_url":"https://api.github.com/repos/roqua/physiqual/pulls/43/comments","review_comment_url":"https://api.github.com/repos/roqua/physiqual/pulls/comments{/number}","comments_url":"https://api.github.com/repos/roqua/physiqual/issues/43/comments","statuses_url":"https://api.github.com/repos/roqua/physiqual/statuses/eb72a5506fcc921ffbbba83056983104ea27e977","head":{"label":"roqua:ae-timings","ref":"ae-timings","sha":"eb72a5506fcc921ffbbba83056983104ea27e977","user":{"login":"roqua","id":598697,"avatar_url":"https://avatars.githubusercontent.com/u/598697?v=3","gravatar_id":"","url":"https://api.github.com/users/roqua","html_url":"https://github.com/roqua","followers_url":"https://api.github.com/users/roqua/followers","following_url":"https://api.github.com/users/roqua/following{/other_user}","gists_url":"https://api.github.com/users/roqua/gists{/gist_id}","starred_url":"https://api.github.com/users/roqua/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roqua/subscriptions","organizations_url":"https://api.github.com/users/roqua/orgs","repos_url":"https://api.github.com/users/roqua/repos","events_url":"https://api.github.com/users/roqua/events{/privacy}","received_events_url":"https://api.github.com/users/roqua/received_events","type":"Organization","site_admin":false},"repo":{"id":40968813,"name":"physiqual","full_name":"roqua/physiqual","owner":{"login":"roqua","id":598697,"avatar_url":"https://avatars.githubusercontent.com/u/598697?v=3","gravatar_id":"","url":"https://api.github.com/users/roqua","html_url":"https://github.com/roqua","followers_url":"https://api.github.com/users/roqua/followers","following_url":"https://api.github.com/users/roqua/following{/other_user}","gists_url":"https://api.github.com/users/roqua/gists{/gist_id}","starred_url":"https://api.github.com/users/roqua/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roqua/subscriptions","organizations_url":"https://api.github.com/users/roqua/orgs","repos_url":"https://api.github.com/users/roqua/repos","events_url":"https://api.github.com/users/roqua/events{/privacy}","received_events_url":"https://api.github.com/users/roqua/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/roqua/physiqual","description":"Ruby Engine for merging various datasources with diary questionnaire data","fork":false,"url":"https://api.github.com/repos/roqua/physiqual","forks_url":"https://api.github.com/repos/roqua/physiqual/forks","keys_url":"https://api.github.com/repos/roqua/physiqual/keys{/key_id}","collaborators_url":"https://api.github.com/repos/roqua/physiqual/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/roqua/physiqual/teams","hooks_url":"https://api.github.com/repos/roqua/physiqual/hooks","issue_events_url":"https://api.github.com/repos/roqua/physiqual/issues/events{/number}","events_url":"https://api.github.com/repos/roqua/physiqual/events","assignees_url":"https://api.github.com/repos/roqua/physiqual/assignees{/user}","branches_url":"https://api.github.com/repos/roqua/physiqual/branches{/branch}","tags_url":"https://api.github.com/repos/roqua/physiqual/tags","blobs_url":"https://api.github.com/repos/roqua/physiqual/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/roqua/physiqual/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/roqua/physiqual/git/refs{/sha}","trees_url":"https://api.github.com/repos/roqua/physiqual/git/trees{/sha}","statuses_url":"https://api.github.com/repos/roqua/physiqual/statuses/{sha}","languages_url":"https://api.github.com/repos/roqua/physiqual/languages","stargazers_url":"https://api.github.com/repos/roqua/physiqual/stargazers","contributors_url":"https://api.github.com/repos/roqua/physiqual/contributors","subscribers_url":"https://api.github.com/repos/roqua/physiqual/subscribers","subscription_url":"https://api.github.com/repos/roqua/physiqual/subscription","commits_url":"https://api.github.com/repos/roqua/physiqual/commits{/sha}","git_commits_url":"https://api.github.com/repos/roqua/physiqual/git/commits{/sha}","comments_url":"https://api.github.com/repos/roqua/physiqual/comments{/number}","issue_comment_url":"https://api.github.com/repos/roqua/physiqual/issues/comments{/number}","contents_url":"https://api.github.com/repos/roqua/physiqual/contents/{+path}","compare_url":"https://api.github.com/repos/roqua/physiqual/compare/{base}...{head}","merges_url":"https://api.github.com/repos/roqua/physiqual/merges","archive_url":"https://api.github.com/repos/roqua/physiqual/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/roqua/physiqual/downloads","issues_url":"https://api.github.com/repos/roqua/physiqual/issues{/number}","pulls_url":"https://api.github.com/repos/roqua/physiqual/pulls{/number}","milestones_url":"https://api.github.com/repos/roqua/physiqual/milestones{/number}","notifications_url":"https://api.github.com/repos/roqua/physiqual/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/roqua/physiqual/labels{/name}","releases_url":"https://api.github.com/repos/roqua/physiqual/releases{/id}","created_at":"2015-08-18T11:44:44Z","updated_at":"2015-09-20T08:07:30Z","pushed_at":"2015-10-10T16:03:28Z","git_url":"git://github.com/roqua/physiqual.git","ssh_url":"git@github.com:roqua/physiqual.git","clone_url":"https://github.com/roqua/physiqual.git","svn_url":"https://github.com/roqua/physiqual","homepage":null,"size":1124,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":14,"forks":0,"open_issues":14,"watchers":1,"default_branch":"master"}},"base":{"label":"roqua:master","ref":"master","sha":"899825bcfaff73b9aa48d563efb12d2401f49509","user":{"login":"roqua","id":598697,"avatar_url":"https://avatars.githubusercontent.com/u/598697?v=3","gravatar_id":"","url":"https://api.github.com/users/roqua","html_url":"https://github.com/roqua","followers_url":"https://api.github.com/users/roqua/followers","following_url":"https://api.github.com/users/roqua/following{/other_user}","gists_url":"https://api.github.com/users/roqua/gists{/gist_id}","starred_url":"https://api.github.com/users/roqua/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roqua/subscriptions","organizations_url":"https://api.github.com/users/roqua/orgs","repos_url":"https://api.github.com/users/roqua/repos","events_url":"https://api.github.com/users/roqua/events{/privacy}","received_events_url":"https://api.github.com/users/roqua/received_events","type":"Organization","site_admin":false},"repo":{"id":40968813,"name":"physiqual","full_name":"roqua/physiqual","owner":{"login":"roqua","id":598697,"avatar_url":"https://avatars.githubusercontent.com/u/598697?v=3","gravatar_id":"","url":"https://api.github.com/users/roqua","html_url":"https://github.com/roqua","followers_url":"https://api.github.com/users/roqua/followers","following_url":"https://api.github.com/users/roqua/following{/other_user}","gists_url":"https://api.github.com/users/roqua/gists{/gist_id}","starred_url":"https://api.github.com/users/roqua/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roqua/subscriptions","organizations_url":"https://api.github.com/users/roqua/orgs","repos_url":"https://api.github.com/users/roqua/repos","events_url":"https://api.github.com/users/roqua/events{/privacy}","received_events_url":"https://api.github.com/users/roqua/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/roqua/physiqual","description":"Ruby Engine for merging various datasources with diary questionnaire data","fork":false,"url":"https://api.github.com/repos/roqua/physiqual","forks_url":"https://api.github.com/repos/roqua/physiqual/forks","keys_url":"https://api.github.com/repos/roqua/physiqual/keys{/key_id}","collaborators_url":"https://api.github.com/repos/roqua/physiqual/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/roqua/physiqual/teams","hooks_url":"https://api.github.com/repos/roqua/physiqual/hooks","issue_events_url":"https://api.github.com/repos/roqua/physiqual/issues/events{/number}","events_url":"https://api.github.com/repos/roqua/physiqual/events","assignees_url":"https://api.github.com/repos/roqua/physiqual/assignees{/user}","branches_url":"https://api.github.com/repos/roqua/physiqual/branches{/branch}","tags_url":"https://api.github.com/repos/roqua/physiqual/tags","blobs_url":"https://api.github.com/repos/roqua/physiqual/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/roqua/physiqual/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/roqua/physiqual/git/refs{/sha}","trees_url":"https://api.github.com/repos/roqua/physiqual/git/trees{/sha}","statuses_url":"https://api.github.com/repos/roqua/physiqual/statuses/{sha}","languages_url":"https://api.github.com/repos/roqua/physiqual/languages","stargazers_url":"https://api.github.com/repos/roqua/physiqual/stargazers","contributors_url":"https://api.github.com/repos/roqua/physiqual/contributors","subscribers_url":"https://api.github.com/repos/roqua/physiqual/subscribers","subscription_url":"https://api.github.com/repos/roqua/physiqual/subscription","commits_url":"https://api.github.com/repos/roqua/physiqual/commits{/sha}","git_commits_url":"https://api.github.com/repos/roqua/physiqual/git/commits{/sha}","comments_url":"https://api.github.com/repos/roqua/physiqual/comments{/number}","issue_comment_url":"https://api.github.com/repos/roqua/physiqual/issues/comments{/number}","contents_url":"https://api.github.com/repos/roqua/physiqual/contents/{+path}","compare_url":"https://api.github.com/repos/roqua/physiqual/compare/{base}...{head}","merges_url":"https://api.github.com/repos/roqua/physiqual/merges","archive_url":"https://api.github.com/repos/roqua/physiqual/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/roqua/physiqual/downloads","issues_url":"https://api.github.com/repos/roqua/physiqual/issues{/number}","pulls_url":"https://api.github.com/repos/roqua/physiqual/pulls{/number}","milestones_url":"https://api.github.com/repos/roqua/physiqual/milestones{/number}","notifications_url":"https://api.github.com/repos/roqua/physiqual/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/roqua/physiqual/labels{/name}","releases_url":"https://api.github.com/repos/roqua/physiqual/releases{/id}","created_at":"2015-08-18T11:44:44Z","updated_at":"2015-09-20T08:07:30Z","pushed_at":"2015-10-10T16:03:28Z","git_url":"git://github.com/roqua/physiqual.git","ssh_url":"git@github.com:roqua/physiqual.git","clone_url":"https://github.com/roqua/physiqual.git","svn_url":"https://github.com/roqua/physiqual","homepage":null,"size":1124,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":14,"forks":0,"open_issues":14,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/roqua/physiqual/pulls/43"},"html":{"href":"https://github.com/roqua/physiqual/pull/43"},"issue":{"href":"https://api.github.com/repos/roqua/physiqual/issues/43"},"comments":{"href":"https://api.github.com/repos/roqua/physiqual/issues/43/comments"},"review_comments":{"href":"https://api.github.com/repos/roqua/physiqual/pulls/43/comments"},"review_comment":{"href":"https://api.github.com/repos/roqua/physiqual/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/roqua/physiqual/pulls/43/commits"},"statuses":{"href":"https://api.github.com/repos/roqua/physiqual/statuses/eb72a5506fcc921ffbbba83056983104ea27e977"}}}}