{"action":"created","comment":{"url":"https://api.github.com/repos/praekelt/familyconnect-registration/pulls/comments/90619686","pull_request_review_id":11138055,"id":90619686,"diff_hunk":"@@ -0,0 +1,79 @@\n+import re\n+\n+from datetime import datetime, timedelta\n+\n+\n+class GraphiteRetention(object):\n+    \"\"\"\n+    Represents one graphite retention. Provides utilities to get time buckets.\n+    \"\"\"\n+    RETENTION_RE = re.compile(r'^(\\d+)([a-z]+)$')\n+    MULTIPLIERS = {\n+        's': 1,\n+        'm': 60,\n+        'h': 60 * 60,\n+        'd': 60 * 60 * 24,\n+        'w': 60 * 60 * 24 * 7,\n+        'y': 60 * 60 * 24 * 365,\n+    }\n+\n+    def __init__(self, retention):\n+        precision, duration = retention.split(':')\n+        self.precision = self._str_to_timedelta(precision)\n+        self.duration = self._str_to_timedelta(duration)\n+\n+    def _str_to_timedelta(self, retention):\n+        match = self.RETENTION_RE.match(retention)\n+        seconds = int(match.group(1)) * self.MULTIPLIERS[match.group(2)]\n+        return timedelta(seconds=seconds)\n+\n+    def get_buckets(self, now=None, finish=None):\n+        \"\"\"\n+        Returns an iterator of tuples (start, end) that define the time\n+        buckets that this retention scheme covers.\n+        kwargs:\n+            now: timestamp of current time. Defaults to current time.\n+            finish: timestamp of when to stop buckets. Defaults to now.\n+        \"\"\"\n+        if now is None:\n+            now = datetime.utcnow()\n+        if finish is None:\n+            finish = now\n+        start = now - self.duration\n+\n+        while start < finish:\n+            end = start + self.precision\n+            if end > finish:\n+                end = finish\n+            yield (start, end)\n+            start = end\n+\n+\n+class RetentionScheme(object):\n+    \"\"\"\n+    Represents multiple graphite retentions. Provides utilities to get time\n+    buckets across all retentions.\n+    \"\"\"\n+    def __init__(self, retentions):\n+        self.retentions = [GraphiteRetention(r) for r in retentions.split(',')]\n+\n+    def get_buckets(self, now=None):\n+        \"\"\"\n+        Returns an iterator of tuples (start, end) that define the time\n+        buckets that all the retention schemes cover.\n+        kwargs:\n+            now: timestamp of current time. Defaults to current time.\n+        \"\"\"\n+        if now is None:\n+            now = datetime.utcnow()\n+        finish = now\n+\n+        for r in self.retentions:\n+            beginning = now\n+            for start, end in r.get_buckets(now=now, finish=finish):\n+                # We always want to end the next retention at the earliest\n+                # point that this retention covers, to avoid overlaps\n+                beginning = min(beginning, start)\n+                yield (start, end)\n+            # The next retention should end where this one started\n+            finish = beginning","path":"registrations/graphite.py","position":79,"original_position":79,"commit_id":"8028d9b99b2d86a4e186ababbc9a3cf1dc08db77","original_commit_id":"8028d9b99b2d86a4e186ababbc9a3cf1dc08db77","user":{"login":"erikh360","id":21120463,"avatar_url":"https://avatars.githubusercontent.com/u/21120463?v=3","gravatar_id":"","url":"https://api.github.com/users/erikh360","html_url":"https://github.com/erikh360","followers_url":"https://api.github.com/users/erikh360/followers","following_url":"https://api.github.com/users/erikh360/following{/other_user}","gists_url":"https://api.github.com/users/erikh360/gists{/gist_id}","starred_url":"https://api.github.com/users/erikh360/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erikh360/subscriptions","organizations_url":"https://api.github.com/users/erikh360/orgs","repos_url":"https://api.github.com/users/erikh360/repos","events_url":"https://api.github.com/users/erikh360/events{/privacy}","received_events_url":"https://api.github.com/users/erikh360/received_events","type":"User","site_admin":false},"body":"I was thinking the same while doing this, where do I make a note of this? ","created_at":"2016-12-02T10:33:25Z","updated_at":"2016-12-02T10:33:25Z","html_url":"https://github.com/praekelt/familyconnect-registration/pull/27#discussion_r90619686","pull_request_url":"https://api.github.com/repos/praekelt/familyconnect-registration/pulls/27","_links":{"self":{"href":"https://api.github.com/repos/praekelt/familyconnect-registration/pulls/comments/90619686"},"html":{"href":"https://github.com/praekelt/familyconnect-registration/pull/27#discussion_r90619686"},"pull_request":{"href":"https://api.github.com/repos/praekelt/familyconnect-registration/pulls/27"}}},"pull_request":{"url":"https://api.github.com/repos/praekelt/familyconnect-registration/pulls/27","id":96237425,"html_url":"https://github.com/praekelt/familyconnect-registration/pull/27","diff_url":"https://github.com/praekelt/familyconnect-registration/pull/27.diff","patch_url":"https://github.com/praekelt/familyconnect-registration/pull/27.patch","issue_url":"https://api.github.com/repos/praekelt/familyconnect-registration/issues/27","number":27,"state":"open","locked":false,"title":"Metrics setup and total registrations over time metrics","user":{"login":"erikh360","id":21120463,"avatar_url":"https://avatars.githubusercontent.com/u/21120463?v=3","gravatar_id":"","url":"https://api.github.com/users/erikh360","html_url":"https://github.com/erikh360","followers_url":"https://api.github.com/users/erikh360/followers","following_url":"https://api.github.com/users/erikh360/following{/other_user}","gists_url":"https://api.github.com/users/erikh360/gists{/gist_id}","starred_url":"https://api.github.com/users/erikh360/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erikh360/subscriptions","organizations_url":"https://api.github.com/users/erikh360/orgs","repos_url":"https://api.github.com/users/erikh360/repos","events_url":"https://api.github.com/users/erikh360/events{/privacy}","received_events_url":"https://api.github.com/users/erikh360/received_events","type":"User","site_admin":false},"body":"This PR adds support for metrics and the \"registrations.created.sum\" and \"registrations.created.total.last\" metrics.\r\n\r\nMostly just copied from hellomama, I also included the repopulate metrics functionality","created_at":"2016-12-02T08:09:19Z","updated_at":"2016-12-02T10:33:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e0743353c1918299beacacf9dff6a35ef41efc34","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/praekelt/familyconnect-registration/pulls/27/commits","review_comments_url":"https://api.github.com/repos/praekelt/familyconnect-registration/pulls/27/comments","review_comment_url":"https://api.github.com/repos/praekelt/familyconnect-registration/pulls/comments{/number}","comments_url":"https://api.github.com/repos/praekelt/familyconnect-registration/issues/27/comments","statuses_url":"https://api.github.com/repos/praekelt/familyconnect-registration/statuses/8028d9b99b2d86a4e186ababbc9a3cf1dc08db77","head":{"label":"praekelt:feature/MOMUG-182-metrics-total-registrations-over-time","ref":"feature/MOMUG-182-metrics-total-registrations-over-time","sha":"8028d9b99b2d86a4e186ababbc9a3cf1dc08db77","user":{"login":"praekelt","id":81810,"avatar_url":"https://avatars.githubusercontent.com/u/81810?v=3","gravatar_id":"","url":"https://api.github.com/users/praekelt","html_url":"https://github.com/praekelt","followers_url":"https://api.github.com/users/praekelt/followers","following_url":"https://api.github.com/users/praekelt/following{/other_user}","gists_url":"https://api.github.com/users/praekelt/gists{/gist_id}","starred_url":"https://api.github.com/users/praekelt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/praekelt/subscriptions","organizations_url":"https://api.github.com/users/praekelt/orgs","repos_url":"https://api.github.com/users/praekelt/repos","events_url":"https://api.github.com/users/praekelt/events{/privacy}","received_events_url":"https://api.github.com/users/praekelt/received_events","type":"Organization","site_admin":false},"repo":{"id":49591179,"name":"familyconnect-registration","full_name":"praekelt/familyconnect-registration","owner":{"login":"praekelt","id":81810,"avatar_url":"https://avatars.githubusercontent.com/u/81810?v=3","gravatar_id":"","url":"https://api.github.com/users/praekelt","html_url":"https://github.com/praekelt","followers_url":"https://api.github.com/users/praekelt/followers","following_url":"https://api.github.com/users/praekelt/following{/other_user}","gists_url":"https://api.github.com/users/praekelt/gists{/gist_id}","starred_url":"https://api.github.com/users/praekelt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/praekelt/subscriptions","organizations_url":"https://api.github.com/users/praekelt/orgs","repos_url":"https://api.github.com/users/praekelt/repos","events_url":"https://api.github.com/users/praekelt/events{/privacy}","received_events_url":"https://api.github.com/users/praekelt/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/praekelt/familyconnect-registration","description":"FamilyConnect Registration","fork":false,"url":"https://api.github.com/repos/praekelt/familyconnect-registration","forks_url":"https://api.github.com/repos/praekelt/familyconnect-registration/forks","keys_url":"https://api.github.com/repos/praekelt/familyconnect-registration/keys{/key_id}","collaborators_url":"https://api.github.com/repos/praekelt/familyconnect-registration/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/praekelt/familyconnect-registration/teams","hooks_url":"https://api.github.com/repos/praekelt/familyconnect-registration/hooks","issue_events_url":"https://api.github.com/repos/praekelt/familyconnect-registration/issues/events{/number}","events_url":"https://api.github.com/repos/praekelt/familyconnect-registration/events","assignees_url":"https://api.github.com/repos/praekelt/familyconnect-registration/assignees{/user}","branches_url":"https://api.github.com/repos/praekelt/familyconnect-registration/branches{/branch}","tags_url":"https://api.github.com/repos/praekelt/familyconnect-registration/tags","blobs_url":"https://api.github.com/repos/praekelt/familyconnect-registration/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/praekelt/familyconnect-registration/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/praekelt/familyconnect-registration/git/refs{/sha}","trees_url":"https://api.github.com/repos/praekelt/familyconnect-registration/git/trees{/sha}","statuses_url":"https://api.github.com/repos/praekelt/familyconnect-registration/statuses/{sha}","languages_url":"https://api.github.com/repos/praekelt/familyconnect-registration/languages","stargazers_url":"https://api.github.com/repos/praekelt/familyconnect-registration/stargazers","contributors_url":"https://api.github.com/repos/praekelt/familyconnect-registration/contributors","subscribers_url":"https://api.github.com/repos/praekelt/familyconnect-registration/subscribers","subscription_url":"https://api.github.com/repos/praekelt/familyconnect-registration/subscription","commits_url":"https://api.github.com/repos/praekelt/familyconnect-registration/commits{/sha}","git_commits_url":"https://api.github.com/repos/praekelt/familyconnect-registration/git/commits{/sha}","comments_url":"https://api.github.com/repos/praekelt/familyconnect-registration/comments{/number}","issue_comment_url":"https://api.github.com/repos/praekelt/familyconnect-registration/issues/comments{/number}","contents_url":"https://api.github.com/repos/praekelt/familyconnect-registration/contents/{+path}","compare_url":"https://api.github.com/repos/praekelt/familyconnect-registration/compare/{base}...{head}","merges_url":"https://api.github.com/repos/praekelt/familyconnect-registration/merges","archive_url":"https://api.github.com/repos/praekelt/familyconnect-registration/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/praekelt/familyconnect-registration/downloads","issues_url":"https://api.github.com/repos/praekelt/familyconnect-registration/issues{/number}","pulls_url":"https://api.github.com/repos/praekelt/familyconnect-registration/pulls{/number}","milestones_url":"https://api.github.com/repos/praekelt/familyconnect-registration/milestones{/number}","notifications_url":"https://api.github.com/repos/praekelt/familyconnect-registration/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/praekelt/familyconnect-registration/labels{/name}","releases_url":"https://api.github.com/repos/praekelt/familyconnect-registration/releases{/id}","deployments_url":"https://api.github.com/repos/praekelt/familyconnect-registration/deployments","created_at":"2016-01-13T17:51:12Z","updated_at":"2016-01-25T09:18:11Z","pushed_at":"2016-12-02T08:09:20Z","git_url":"git://github.com/praekelt/familyconnect-registration.git","ssh_url":"git@github.com:praekelt/familyconnect-registration.git","clone_url":"https://github.com/praekelt/familyconnect-registration.git","svn_url":"https://github.com/praekelt/familyconnect-registration","homepage":null,"size":114,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":5,"forks":0,"open_issues":5,"watchers":0,"default_branch":"develop"}},"base":{"label":"praekelt:develop","ref":"develop","sha":"d3612a87ab0bd55fc762994015e18751083c8b5e","user":{"login":"praekelt","id":81810,"avatar_url":"https://avatars.githubusercontent.com/u/81810?v=3","gravatar_id":"","url":"https://api.github.com/users/praekelt","html_url":"https://github.com/praekelt","followers_url":"https://api.github.com/users/praekelt/followers","following_url":"https://api.github.com/users/praekelt/following{/other_user}","gists_url":"https://api.github.com/users/praekelt/gists{/gist_id}","starred_url":"https://api.github.com/users/praekelt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/praekelt/subscriptions","organizations_url":"https://api.github.com/users/praekelt/orgs","repos_url":"https://api.github.com/users/praekelt/repos","events_url":"https://api.github.com/users/praekelt/events{/privacy}","received_events_url":"https://api.github.com/users/praekelt/received_events","type":"Organization","site_admin":false},"repo":{"id":49591179,"name":"familyconnect-registration","full_name":"praekelt/familyconnect-registration","owner":{"login":"praekelt","id":81810,"avatar_url":"https://avatars.githubusercontent.com/u/81810?v=3","gravatar_id":"","url":"https://api.github.com/users/praekelt","html_url":"https://github.com/praekelt","followers_url":"https://api.github.com/users/praekelt/followers","following_url":"https://api.github.com/users/praekelt/following{/other_user}","gists_url":"https://api.github.com/users/praekelt/gists{/gist_id}","starred_url":"https://api.github.com/users/praekelt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/praekelt/subscriptions","organizations_url":"https://api.github.com/users/praekelt/orgs","repos_url":"https://api.github.com/users/praekelt/repos","events_url":"https://api.github.com/users/praekelt/events{/privacy}","received_events_url":"https://api.github.com/users/praekelt/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/praekelt/familyconnect-registration","description":"FamilyConnect Registration","fork":false,"url":"https://api.github.com/repos/praekelt/familyconnect-registration","forks_url":"https://api.github.com/repos/praekelt/familyconnect-registration/forks","keys_url":"https://api.github.com/repos/praekelt/familyconnect-registration/keys{/key_id}","collaborators_url":"https://api.github.com/repos/praekelt/familyconnect-registration/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/praekelt/familyconnect-registration/teams","hooks_url":"https://api.github.com/repos/praekelt/familyconnect-registration/hooks","issue_events_url":"https://api.github.com/repos/praekelt/familyconnect-registration/issues/events{/number}","events_url":"https://api.github.com/repos/praekelt/familyconnect-registration/events","assignees_url":"https://api.github.com/repos/praekelt/familyconnect-registration/assignees{/user}","branches_url":"https://api.github.com/repos/praekelt/familyconnect-registration/branches{/branch}","tags_url":"https://api.github.com/repos/praekelt/familyconnect-registration/tags","blobs_url":"https://api.github.com/repos/praekelt/familyconnect-registration/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/praekelt/familyconnect-registration/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/praekelt/familyconnect-registration/git/refs{/sha}","trees_url":"https://api.github.com/repos/praekelt/familyconnect-registration/git/trees{/sha}","statuses_url":"https://api.github.com/repos/praekelt/familyconnect-registration/statuses/{sha}","languages_url":"https://api.github.com/repos/praekelt/familyconnect-registration/languages","stargazers_url":"https://api.github.com/repos/praekelt/familyconnect-registration/stargazers","contributors_url":"https://api.github.com/repos/praekelt/familyconnect-registration/contributors","subscribers_url":"https://api.github.com/repos/praekelt/familyconnect-registration/subscribers","subscription_url":"https://api.github.com/repos/praekelt/familyconnect-registration/subscription","commits_url":"https://api.github.com/repos/praekelt/familyconnect-registration/commits{/sha}","git_commits_url":"https://api.github.com/repos/praekelt/familyconnect-registration/git/commits{/sha}","comments_url":"https://api.github.com/repos/praekelt/familyconnect-registration/comments{/number}","issue_comment_url":"https://api.github.com/repos/praekelt/familyconnect-registration/issues/comments{/number}","contents_url":"https://api.github.com/repos/praekelt/familyconnect-registration/contents/{+path}","compare_url":"https://api.github.com/repos/praekelt/familyconnect-registration/compare/{base}...{head}","merges_url":"https://api.github.com/repos/praekelt/familyconnect-registration/merges","archive_url":"https://api.github.com/repos/praekelt/familyconnect-registration/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/praekelt/familyconnect-registration/downloads","issues_url":"https://api.github.com/repos/praekelt/familyconnect-registration/issues{/number}","pulls_url":"https://api.github.com/repos/praekelt/familyconnect-registration/pulls{/number}","milestones_url":"https://api.github.com/repos/praekelt/familyconnect-registration/milestones{/number}","notifications_url":"https://api.github.com/repos/praekelt/familyconnect-registration/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/praekelt/familyconnect-registration/labels{/name}","releases_url":"https://api.github.com/repos/praekelt/familyconnect-registration/releases{/id}","deployments_url":"https://api.github.com/repos/praekelt/familyconnect-registration/deployments","created_at":"2016-01-13T17:51:12Z","updated_at":"2016-01-25T09:18:11Z","pushed_at":"2016-12-02T08:09:20Z","git_url":"git://github.com/praekelt/familyconnect-registration.git","ssh_url":"git@github.com:praekelt/familyconnect-registration.git","clone_url":"https://github.com/praekelt/familyconnect-registration.git","svn_url":"https://github.com/praekelt/familyconnect-registration","homepage":null,"size":114,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":5,"forks":0,"open_issues":5,"watchers":0,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/praekelt/familyconnect-registration/pulls/27"},"html":{"href":"https://github.com/praekelt/familyconnect-registration/pull/27"},"issue":{"href":"https://api.github.com/repos/praekelt/familyconnect-registration/issues/27"},"comments":{"href":"https://api.github.com/repos/praekelt/familyconnect-registration/issues/27/comments"},"review_comments":{"href":"https://api.github.com/repos/praekelt/familyconnect-registration/pulls/27/comments"},"review_comment":{"href":"https://api.github.com/repos/praekelt/familyconnect-registration/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/praekelt/familyconnect-registration/pulls/27/commits"},"statuses":{"href":"https://api.github.com/repos/praekelt/familyconnect-registration/statuses/8028d9b99b2d86a4e186ababbc9a3cf1dc08db77"}}}}
{"actor":{"display_login":"erikh360"}}