{"action":"created","comment":{"url":"https://api.github.com/repos/puppetlabs/vmpooler/pulls/comments/25802933","id":25802933,"diff_hunk":"@@ -5,48 +5,59 @@ class V1 < Sinatra::Base\n     api_prefix  = \"/api/v#{api_version}\"\n \n     helpers do\n-      def hostname_shorten(hostname)\n-        if $config[:config]['domain'] && hostname =~ /^\\w+\\.#{$config[:config]['domain']}$/\n-          hostname = hostname[/[^\\.]+/]\n-        end\n+      def get_capacity_metrics()\n+        capacity = {\n+          current: 0,\n+          total: 0,\n+          percent: 0\n+        }\n \n-        hostname\n-      end\n+        $config[:pools].each do |pool|\n+          pool['capacity'] = $redis.scard('vmpooler__ready__' + pool['name']).to_i\n \n-      def validate_date_str(date_str)\n-        /^\\d{4}-\\d{2}-\\d{2}$/ === date_str\n-      end\n+          capacity[:current] += pool['capacity']\n+          capacity[:total] += pool['size'].to_i\n+        end\n \n-      def mean(list)\n-        s = list.map(&:to_f).reduce(:+).to_f\n-        (s > 0 && list.length > 0) ? s / list.length.to_f : 0\n-      end\n-    end\n+        if capacity[:total] > 0\n+          capacity[:percent] = ((capacity[:current].to_f / capacity[:total].to_f) * 100.0).round(1)\n+        end\n \n-    get \"#{api_prefix}/status/?\" do\n-      content_type :json\n+        capacity\n+      end\n \n-      result = {\n-        status: {\n-          ok: true,\n-          message: 'Battle station fully armed and operational.'\n-        },\n-        capacity: {\n-          current: 0,\n-          total: 0,\n-          percent: 0\n-        },\n-        clone: {\n+      def get_clone_metrics(date)\n+        clone = {\n           duration: {\n             average: 0,\n             min: 0,\n-            max: 0\n+            max: 0,\n+            total: 0\n           },\n           count: {\n             total: 0\n           }\n-        },\n-        queue: {\n+        }\n+\n+        clone[:count][:total] = $redis.hlen('vmpooler__clone__' + date).to_i","path":"lib/vmpooler/api/v1.rb","position":68,"original_position":68,"commit_id":"5453ec6206fcc910f2d40bc93d845009589ed37f","original_commit_id":"5453ec6206fcc910f2d40bc93d845009589ed37f","user":{"login":"colinPL","id":6528153,"avatar_url":"https://avatars.githubusercontent.com/u/6528153?v=3","gravatar_id":"","url":"https://api.github.com/users/colinPL","html_url":"https://github.com/colinPL","followers_url":"https://api.github.com/users/colinPL/followers","following_url":"https://api.github.com/users/colinPL/following{/other_user}","gists_url":"https://api.github.com/users/colinPL/gists{/gist_id}","starred_url":"https://api.github.com/users/colinPL/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/colinPL/subscriptions","organizations_url":"https://api.github.com/users/colinPL/orgs","repos_url":"https://api.github.com/users/colinPL/repos","events_url":"https://api.github.com/users/colinPL/events{/privacy}","received_events_url":"https://api.github.com/users/colinPL/received_events","type":"User","site_admin":false},"body":"Is `date` a date string or an actual date? If the latter, this needs `.to_s`. If the former, then I suggest renaming the variable to `date_str`. (methods below use \"date\" and treat it as a date object)","created_at":"2015-03-04T19:07:09Z","updated_at":"2015-03-04T19:07:09Z","html_url":"https://github.com/puppetlabs/vmpooler/pull/62#discussion_r25802933","pull_request_url":"https://api.github.com/repos/puppetlabs/vmpooler/pulls/62","_links":{"self":{"href":"https://api.github.com/repos/puppetlabs/vmpooler/pulls/comments/25802933"},"html":{"href":"https://github.com/puppetlabs/vmpooler/pull/62#discussion_r25802933"},"pull_request":{"href":"https://api.github.com/repos/puppetlabs/vmpooler/pulls/62"}}},"pull_request":{"url":"https://api.github.com/repos/puppetlabs/vmpooler/pulls/62","id":30491104,"html_url":"https://github.com/puppetlabs/vmpooler/pull/62","diff_url":"https://github.com/puppetlabs/vmpooler/pull/62.diff","patch_url":"https://github.com/puppetlabs/vmpooler/pull/62.patch","issue_url":"https://api.github.com/repos/puppetlabs/vmpooler/issues/62","number":62,"state":"open","locked":false,"title":"Metric calc via helpers","user":{"login":"sschneid","id":20033,"avatar_url":"https://avatars.githubusercontent.com/u/20033?v=3","gravatar_id":"","url":"https://api.github.com/users/sschneid","html_url":"https://github.com/sschneid","followers_url":"https://api.github.com/users/sschneid/followers","following_url":"https://api.github.com/users/sschneid/following{/other_user}","gists_url":"https://api.github.com/users/sschneid/gists{/gist_id}","starred_url":"https://api.github.com/users/sschneid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sschneid/subscriptions","organizations_url":"https://api.github.com/users/sschneid/orgs","repos_url":"https://api.github.com/users/sschneid/repos","events_url":"https://api.github.com/users/sschneid/events{/privacy}","received_events_url":"https://api.github.com/users/sschneid/received_events","type":"User","site_admin":false},"body":"This PR moves common metrics calculations to helpers.","created_at":"2015-03-04T18:30:11Z","updated_at":"2015-03-04T19:07:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"198b555169107217296c2ac0e55505b16780ca71","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/puppetlabs/vmpooler/pulls/62/commits","review_comments_url":"https://api.github.com/repos/puppetlabs/vmpooler/pulls/62/comments","review_comment_url":"https://api.github.com/repos/puppetlabs/vmpooler/pulls/comments{/number}","comments_url":"https://api.github.com/repos/puppetlabs/vmpooler/issues/62/comments","statuses_url":"https://api.github.com/repos/puppetlabs/vmpooler/statuses/5453ec6206fcc910f2d40bc93d845009589ed37f","head":{"label":"sschneid:metric_calc_via_helper","ref":"metric_calc_via_helper","sha":"5453ec6206fcc910f2d40bc93d845009589ed37f","user":{"login":"sschneid","id":20033,"avatar_url":"https://avatars.githubusercontent.com/u/20033?v=3","gravatar_id":"","url":"https://api.github.com/users/sschneid","html_url":"https://github.com/sschneid","followers_url":"https://api.github.com/users/sschneid/followers","following_url":"https://api.github.com/users/sschneid/following{/other_user}","gists_url":"https://api.github.com/users/sschneid/gists{/gist_id}","starred_url":"https://api.github.com/users/sschneid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sschneid/subscriptions","organizations_url":"https://api.github.com/users/sschneid/orgs","repos_url":"https://api.github.com/users/sschneid/repos","events_url":"https://api.github.com/users/sschneid/events{/privacy}","received_events_url":"https://api.github.com/users/sschneid/received_events","type":"User","site_admin":false},"repo":{"id":21907793,"name":"vmpooler","full_name":"sschneid/vmpooler","owner":{"login":"sschneid","id":20033,"avatar_url":"https://avatars.githubusercontent.com/u/20033?v=3","gravatar_id":"","url":"https://api.github.com/users/sschneid","html_url":"https://github.com/sschneid","followers_url":"https://api.github.com/users/sschneid/followers","following_url":"https://api.github.com/users/sschneid/following{/other_user}","gists_url":"https://api.github.com/users/sschneid/gists{/gist_id}","starred_url":"https://api.github.com/users/sschneid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sschneid/subscriptions","organizations_url":"https://api.github.com/users/sschneid/orgs","repos_url":"https://api.github.com/users/sschneid/repos","events_url":"https://api.github.com/users/sschneid/events{/privacy}","received_events_url":"https://api.github.com/users/sschneid/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sschneid/vmpooler","description":"Provide configurable 'pools' of available (running) virtual machines","fork":true,"url":"https://api.github.com/repos/sschneid/vmpooler","forks_url":"https://api.github.com/repos/sschneid/vmpooler/forks","keys_url":"https://api.github.com/repos/sschneid/vmpooler/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sschneid/vmpooler/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sschneid/vmpooler/teams","hooks_url":"https://api.github.com/repos/sschneid/vmpooler/hooks","issue_events_url":"https://api.github.com/repos/sschneid/vmpooler/issues/events{/number}","events_url":"https://api.github.com/repos/sschneid/vmpooler/events","assignees_url":"https://api.github.com/repos/sschneid/vmpooler/assignees{/user}","branches_url":"https://api.github.com/repos/sschneid/vmpooler/branches{/branch}","tags_url":"https://api.github.com/repos/sschneid/vmpooler/tags","blobs_url":"https://api.github.com/repos/sschneid/vmpooler/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sschneid/vmpooler/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sschneid/vmpooler/git/refs{/sha}","trees_url":"https://api.github.com/repos/sschneid/vmpooler/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sschneid/vmpooler/statuses/{sha}","languages_url":"https://api.github.com/repos/sschneid/vmpooler/languages","stargazers_url":"https://api.github.com/repos/sschneid/vmpooler/stargazers","contributors_url":"https://api.github.com/repos/sschneid/vmpooler/contributors","subscribers_url":"https://api.github.com/repos/sschneid/vmpooler/subscribers","subscription_url":"https://api.github.com/repos/sschneid/vmpooler/subscription","commits_url":"https://api.github.com/repos/sschneid/vmpooler/commits{/sha}","git_commits_url":"https://api.github.com/repos/sschneid/vmpooler/git/commits{/sha}","comments_url":"https://api.github.com/repos/sschneid/vmpooler/comments{/number}","issue_comment_url":"https://api.github.com/repos/sschneid/vmpooler/issues/comments{/number}","contents_url":"https://api.github.com/repos/sschneid/vmpooler/contents/{+path}","compare_url":"https://api.github.com/repos/sschneid/vmpooler/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sschneid/vmpooler/merges","archive_url":"https://api.github.com/repos/sschneid/vmpooler/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sschneid/vmpooler/downloads","issues_url":"https://api.github.com/repos/sschneid/vmpooler/issues{/number}","pulls_url":"https://api.github.com/repos/sschneid/vmpooler/pulls{/number}","milestones_url":"https://api.github.com/repos/sschneid/vmpooler/milestones{/number}","notifications_url":"https://api.github.com/repos/sschneid/vmpooler/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sschneid/vmpooler/labels{/name}","releases_url":"https://api.github.com/repos/sschneid/vmpooler/releases{/id}","created_at":"2014-07-16T16:07:36Z","updated_at":"2015-03-02T17:17:44Z","pushed_at":"2015-03-04T18:29:16Z","git_url":"git://github.com/sschneid/vmpooler.git","ssh_url":"git@github.com:sschneid/vmpooler.git","clone_url":"https://github.com/sschneid/vmpooler.git","svn_url":"https://github.com/sschneid/vmpooler","homepage":"","size":1922,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"puppetlabs:master","ref":"master","sha":"a50b9bae10e460acb6cba7e143646fba683a75d4","user":{"login":"puppetlabs","id":234268,"avatar_url":"https://avatars.githubusercontent.com/u/234268?v=3","gravatar_id":"","url":"https://api.github.com/users/puppetlabs","html_url":"https://github.com/puppetlabs","followers_url":"https://api.github.com/users/puppetlabs/followers","following_url":"https://api.github.com/users/puppetlabs/following{/other_user}","gists_url":"https://api.github.com/users/puppetlabs/gists{/gist_id}","starred_url":"https://api.github.com/users/puppetlabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/puppetlabs/subscriptions","organizations_url":"https://api.github.com/users/puppetlabs/orgs","repos_url":"https://api.github.com/users/puppetlabs/repos","events_url":"https://api.github.com/users/puppetlabs/events{/privacy}","received_events_url":"https://api.github.com/users/puppetlabs/received_events","type":"Organization","site_admin":false},"repo":{"id":13072980,"name":"vmpooler","full_name":"puppetlabs/vmpooler","owner":{"login":"puppetlabs","id":234268,"avatar_url":"https://avatars.githubusercontent.com/u/234268?v=3","gravatar_id":"","url":"https://api.github.com/users/puppetlabs","html_url":"https://github.com/puppetlabs","followers_url":"https://api.github.com/users/puppetlabs/followers","following_url":"https://api.github.com/users/puppetlabs/following{/other_user}","gists_url":"https://api.github.com/users/puppetlabs/gists{/gist_id}","starred_url":"https://api.github.com/users/puppetlabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/puppetlabs/subscriptions","organizations_url":"https://api.github.com/users/puppetlabs/orgs","repos_url":"https://api.github.com/users/puppetlabs/repos","events_url":"https://api.github.com/users/puppetlabs/events{/privacy}","received_events_url":"https://api.github.com/users/puppetlabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/puppetlabs/vmpooler","description":"Provide configurable 'pools' of available (running) virtual machines","fork":false,"url":"https://api.github.com/repos/puppetlabs/vmpooler","forks_url":"https://api.github.com/repos/puppetlabs/vmpooler/forks","keys_url":"https://api.github.com/repos/puppetlabs/vmpooler/keys{/key_id}","collaborators_url":"https://api.github.com/repos/puppetlabs/vmpooler/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/puppetlabs/vmpooler/teams","hooks_url":"https://api.github.com/repos/puppetlabs/vmpooler/hooks","issue_events_url":"https://api.github.com/repos/puppetlabs/vmpooler/issues/events{/number}","events_url":"https://api.github.com/repos/puppetlabs/vmpooler/events","assignees_url":"https://api.github.com/repos/puppetlabs/vmpooler/assignees{/user}","branches_url":"https://api.github.com/repos/puppetlabs/vmpooler/branches{/branch}","tags_url":"https://api.github.com/repos/puppetlabs/vmpooler/tags","blobs_url":"https://api.github.com/repos/puppetlabs/vmpooler/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/puppetlabs/vmpooler/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/puppetlabs/vmpooler/git/refs{/sha}","trees_url":"https://api.github.com/repos/puppetlabs/vmpooler/git/trees{/sha}","statuses_url":"https://api.github.com/repos/puppetlabs/vmpooler/statuses/{sha}","languages_url":"https://api.github.com/repos/puppetlabs/vmpooler/languages","stargazers_url":"https://api.github.com/repos/puppetlabs/vmpooler/stargazers","contributors_url":"https://api.github.com/repos/puppetlabs/vmpooler/contributors","subscribers_url":"https://api.github.com/repos/puppetlabs/vmpooler/subscribers","subscription_url":"https://api.github.com/repos/puppetlabs/vmpooler/subscription","commits_url":"https://api.github.com/repos/puppetlabs/vmpooler/commits{/sha}","git_commits_url":"https://api.github.com/repos/puppetlabs/vmpooler/git/commits{/sha}","comments_url":"https://api.github.com/repos/puppetlabs/vmpooler/comments{/number}","issue_comment_url":"https://api.github.com/repos/puppetlabs/vmpooler/issues/comments{/number}","contents_url":"https://api.github.com/repos/puppetlabs/vmpooler/contents/{+path}","compare_url":"https://api.github.com/repos/puppetlabs/vmpooler/compare/{base}...{head}","merges_url":"https://api.github.com/repos/puppetlabs/vmpooler/merges","archive_url":"https://api.github.com/repos/puppetlabs/vmpooler/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/puppetlabs/vmpooler/downloads","issues_url":"https://api.github.com/repos/puppetlabs/vmpooler/issues{/number}","pulls_url":"https://api.github.com/repos/puppetlabs/vmpooler/pulls{/number}","milestones_url":"https://api.github.com/repos/puppetlabs/vmpooler/milestones{/number}","notifications_url":"https://api.github.com/repos/puppetlabs/vmpooler/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/puppetlabs/vmpooler/labels{/name}","releases_url":"https://api.github.com/repos/puppetlabs/vmpooler/releases{/id}","created_at":"2013-09-24T18:27:35Z","updated_at":"2015-03-02T17:17:49Z","pushed_at":"2015-03-02T17:18:20Z","git_url":"git://github.com/puppetlabs/vmpooler.git","ssh_url":"git@github.com:puppetlabs/vmpooler.git","clone_url":"https://github.com/puppetlabs/vmpooler.git","svn_url":"https://github.com/puppetlabs/vmpooler","homepage":"","size":1965,"stargazers_count":26,"watchers_count":26,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":9,"mirror_url":null,"open_issues_count":2,"forks":9,"open_issues":2,"watchers":26,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/puppetlabs/vmpooler/pulls/62"},"html":{"href":"https://github.com/puppetlabs/vmpooler/pull/62"},"issue":{"href":"https://api.github.com/repos/puppetlabs/vmpooler/issues/62"},"comments":{"href":"https://api.github.com/repos/puppetlabs/vmpooler/issues/62/comments"},"review_comments":{"href":"https://api.github.com/repos/puppetlabs/vmpooler/pulls/62/comments"},"review_comment":{"href":"https://api.github.com/repos/puppetlabs/vmpooler/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/puppetlabs/vmpooler/pulls/62/commits"},"statuses":{"href":"https://api.github.com/repos/puppetlabs/vmpooler/statuses/5453ec6206fcc910f2d40bc93d845009589ed37f"}}}}