{"action":"created","comment":{"url":"https://api.github.com/repos/jgheerardyn/yields/pulls/comments/22437638","id":22437638,"diff_hunk":"@@ -0,0 +1,231 @@\n+/*\n+ * Copyright 2014 by Yields.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *        http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package io.yields.plugins.kpi;\n+\n+import org.apache.commons.lang.StringUtils;\n+import org.jfree.chart.ChartFactory;\n+import org.jfree.chart.JFreeChart;\n+import org.jfree.chart.axis.NumberAxis;\n+import org.jfree.chart.plot.CategoryPlot;\n+import org.jfree.chart.plot.PlotOrientation;\n+import org.jfree.data.category.CategoryDataset;\n+import org.jfree.ui.RectangleEdge;\n+import org.jfree.ui.RectangleInsets;\n+import org.kohsuke.stapler.StaplerRequest;\n+import org.kohsuke.stapler.StaplerResponse;\n+\n+import java.awt.*;\n+import java.io.IOException;\n+import java.util.Map;\n+import java.util.SortedSet;\n+import java.util.TreeMap;\n+import java.util.TreeSet;\n+\n+import hudson.model.AbstractBuild;\n+import hudson.model.ModelObject;\n+import hudson.model.TaskListener;\n+import hudson.util.DataSetBuilder;\n+import hudson.util.Graph;\n+import io.yields.math.framework.kpi.ScoreResult;\n+\n+import static io.yields.plugins.kpi.LocalMessages.REPORT_DISPLAY_NAME;\n+\n+/**\n+ * Report displaying Yields KPI results.\n+ */\n+public class BuildActionResultsDisplay implements ModelObject {\n+\n+    /**\n+     * The {@link io.yields.plugins.kpi.KPIReportBuildAction} this report belongs to\n+     */\n+    private transient KPIReportBuildAction buildAction;\n+\n+    /**\n+     * The {@link io.yields.plugins.kpi.KPIReport} for this build\n+     */\n+    private KPIReport currentReport;\n+\n+    /**\n+     * Parses the reports and build a {@link io.yields.plugins.kpi.BuildActionResultsDisplay}.\n+     *\n+     * @throws java.io.IOException if a report fails to parse\n+     */\n+    BuildActionResultsDisplay(final KPIReportBuildAction buildAction, TaskListener listener) throws IOException {\n+        this.buildAction = buildAction;\n+\n+        currentReport = this.buildAction.getKPIReport();\n+        currentReport.setBuildAction(buildAction);\n+    }\n+\n+    public String getDisplayName() {\n+        return REPORT_DISPLAY_NAME.toString();\n+    }\n+\n+    public AbstractBuild<?, ?> getBuild() {\n+        return buildAction.getBuild();\n+    }\n+\n+    public KPIReport getKPIReport() {\n+        return currentReport;\n+    }\n+\n+\n+    public void doBuildGraph(final StaplerRequest request, final StaplerResponse response) throws IOException {\n+\n+        final String testName = request.getParameter(\"test\");\n+        final int buildsInTrend = buildAction.getBuildsInTrend();\n+\n+        final int width = getOrElse(request, \"width\", 400);\n+        final int height = getOrElse(request, \"height\", 300);\n+\n+        final Graph graph = new BuildKPIGraph(\"Trend of \" + testName, width, height) {\n+\n+            protected DataSetBuilder<String, Integer> createDataSet() {\n+                DataSetBuilder<String, Integer> dataSetBuilder = new DataSetBuilder<String, Integer>();\n+\n+                KPIReport kpiReport = getKPIReport();\n+                if (kpiReport != null) {\n+\n+                    Map<Integer, ScoreResult> testResults = new TreeMap<Integer, ScoreResult>();\n+                    testResults.put(0, kpiReport.getKpiScore(testName));\n+\n+                    int total = 1;\n+\n+                    while (total < buildsInTrend) {\n+\n+                        if (kpiReport != null) {\n+                            kpiReport = kpiReport.getPrevious();\n+                        } else {\n+                            kpiReport = null;\n+                        }\n+\n+                        if (kpiReport != null) {\n+                            testResults.put(total, kpiReport.getKpiScore(testName));\n+                        }\n+\n+                        total++;\n+                    }\n+\n+                    total = 0;\n+\n+                    SortedSet<String> kpiNames = getKPINames(buildsInTrend, testName);","path":"plugins/kpis/src/main/java/io/yields/plugins/kpi/BuildActionResultsDisplay.java","position":125,"original_position":125,"commit_id":"e9d1b723ed4df50a02268710e54dd693e39de74f","original_commit_id":"5afc4e5391deb505573f3b6bf2393e6e28baf9c0","user":{"login":"rombautt","id":462553,"avatar_url":"https://avatars.githubusercontent.com/u/462553?v=3","gravatar_id":"","url":"https://api.github.com/users/rombautt","html_url":"https://github.com/rombautt","followers_url":"https://api.github.com/users/rombautt/followers","following_url":"https://api.github.com/users/rombautt/following{/other_user}","gists_url":"https://api.github.com/users/rombautt/gists{/gist_id}","starred_url":"https://api.github.com/users/rombautt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rombautt/subscriptions","organizations_url":"https://api.github.com/users/rombautt/orgs","repos_url":"https://api.github.com/users/rombautt/repos","events_url":"https://api.github.com/users/rombautt/events{/privacy}","received_events_url":"https://api.github.com/users/rombautt/received_events","type":"User","site_admin":false},"body":"Possible.\r\nHowever, I was thinking we'd introduce a kind of grouping of KPIs later on (if there are too many to fit in 1 graph), so maybe this ordering would fit in there (eg. alphabetically per group).","created_at":"2015-01-04T08:44:18Z","updated_at":"2015-01-04T08:44:18Z","html_url":"https://github.com/jgheerardyn/yields/pull/39#discussion_r22437638","pull_request_url":"https://api.github.com/repos/jgheerardyn/yields/pulls/39","_links":{"self":{"href":"https://api.github.com/repos/jgheerardyn/yields/pulls/comments/22437638"},"html":{"href":"https://github.com/jgheerardyn/yields/pull/39#discussion_r22437638"},"pull_request":{"href":"https://api.github.com/repos/jgheerardyn/yields/pulls/39"}}},"pull_request":{"url":"https://api.github.com/repos/jgheerardyn/yields/pulls/39","id":26783783,"html_url":"https://github.com/jgheerardyn/yields/pull/39","diff_url":"https://github.com/jgheerardyn/yields/pull/39.diff","patch_url":"https://github.com/jgheerardyn/yields/pull/39.patch","issue_url":"https://api.github.com/repos/jgheerardyn/yields/issues/39","number":39,"state":"open","locked":false,"title":"Kpi","user":{"login":"jgheerardyn","id":6535557,"avatar_url":"https://avatars.githubusercontent.com/u/6535557?v=3","gravatar_id":"","url":"https://api.github.com/users/jgheerardyn","html_url":"https://github.com/jgheerardyn","followers_url":"https://api.github.com/users/jgheerardyn/followers","following_url":"https://api.github.com/users/jgheerardyn/following{/other_user}","gists_url":"https://api.github.com/users/jgheerardyn/gists{/gist_id}","starred_url":"https://api.github.com/users/jgheerardyn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jgheerardyn/subscriptions","organizations_url":"https://api.github.com/users/jgheerardyn/orgs","repos_url":"https://api.github.com/users/jgheerardyn/repos","events_url":"https://api.github.com/users/jgheerardyn/events{/privacy}","received_events_url":"https://api.github.com/users/jgheerardyn/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-01-03T15:26:17Z","updated_at":"2015-01-04T08:44:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ac55ecb125ed94937cbc0981520ac0a28c443c7f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/jgheerardyn/yields/pulls/39/commits","review_comments_url":"https://api.github.com/repos/jgheerardyn/yields/pulls/39/comments","review_comment_url":"https://api.github.com/repos/jgheerardyn/yields/pulls/comments/{number}","comments_url":"https://api.github.com/repos/jgheerardyn/yields/issues/39/comments","statuses_url":"https://api.github.com/repos/jgheerardyn/yields/statuses/e9d1b723ed4df50a02268710e54dd693e39de74f","head":{"label":"jgheerardyn:KPI","ref":"KPI","sha":"e9d1b723ed4df50a02268710e54dd693e39de74f","user":{"login":"jgheerardyn","id":6535557,"avatar_url":"https://avatars.githubusercontent.com/u/6535557?v=3","gravatar_id":"","url":"https://api.github.com/users/jgheerardyn","html_url":"https://github.com/jgheerardyn","followers_url":"https://api.github.com/users/jgheerardyn/followers","following_url":"https://api.github.com/users/jgheerardyn/following{/other_user}","gists_url":"https://api.github.com/users/jgheerardyn/gists{/gist_id}","starred_url":"https://api.github.com/users/jgheerardyn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jgheerardyn/subscriptions","organizations_url":"https://api.github.com/users/jgheerardyn/orgs","repos_url":"https://api.github.com/users/jgheerardyn/repos","events_url":"https://api.github.com/users/jgheerardyn/events{/privacy}","received_events_url":"https://api.github.com/users/jgheerardyn/received_events","type":"User","site_admin":false},"repo":{"id":24840606,"name":"yields","full_name":"jgheerardyn/yields","owner":{"login":"jgheerardyn","id":6535557,"avatar_url":"https://avatars.githubusercontent.com/u/6535557?v=3","gravatar_id":"","url":"https://api.github.com/users/jgheerardyn","html_url":"https://github.com/jgheerardyn","followers_url":"https://api.github.com/users/jgheerardyn/followers","following_url":"https://api.github.com/users/jgheerardyn/following{/other_user}","gists_url":"https://api.github.com/users/jgheerardyn/gists{/gist_id}","starred_url":"https://api.github.com/users/jgheerardyn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jgheerardyn/subscriptions","organizations_url":"https://api.github.com/users/jgheerardyn/orgs","repos_url":"https://api.github.com/users/jgheerardyn/repos","events_url":"https://api.github.com/users/jgheerardyn/events{/privacy}","received_events_url":"https://api.github.com/users/jgheerardyn/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jgheerardyn/yields","description":"Mathematic software testing framework","fork":false,"url":"https://api.github.com/repos/jgheerardyn/yields","forks_url":"https://api.github.com/repos/jgheerardyn/yields/forks","keys_url":"https://api.github.com/repos/jgheerardyn/yields/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jgheerardyn/yields/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jgheerardyn/yields/teams","hooks_url":"https://api.github.com/repos/jgheerardyn/yields/hooks","issue_events_url":"https://api.github.com/repos/jgheerardyn/yields/issues/events{/number}","events_url":"https://api.github.com/repos/jgheerardyn/yields/events","assignees_url":"https://api.github.com/repos/jgheerardyn/yields/assignees{/user}","branches_url":"https://api.github.com/repos/jgheerardyn/yields/branches{/branch}","tags_url":"https://api.github.com/repos/jgheerardyn/yields/tags","blobs_url":"https://api.github.com/repos/jgheerardyn/yields/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jgheerardyn/yields/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jgheerardyn/yields/git/refs{/sha}","trees_url":"https://api.github.com/repos/jgheerardyn/yields/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jgheerardyn/yields/statuses/{sha}","languages_url":"https://api.github.com/repos/jgheerardyn/yields/languages","stargazers_url":"https://api.github.com/repos/jgheerardyn/yields/stargazers","contributors_url":"https://api.github.com/repos/jgheerardyn/yields/contributors","subscribers_url":"https://api.github.com/repos/jgheerardyn/yields/subscribers","subscription_url":"https://api.github.com/repos/jgheerardyn/yields/subscription","commits_url":"https://api.github.com/repos/jgheerardyn/yields/commits{/sha}","git_commits_url":"https://api.github.com/repos/jgheerardyn/yields/git/commits{/sha}","comments_url":"https://api.github.com/repos/jgheerardyn/yields/comments{/number}","issue_comment_url":"https://api.github.com/repos/jgheerardyn/yields/issues/comments/{number}","contents_url":"https://api.github.com/repos/jgheerardyn/yields/contents/{+path}","compare_url":"https://api.github.com/repos/jgheerardyn/yields/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jgheerardyn/yields/merges","archive_url":"https://api.github.com/repos/jgheerardyn/yields/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jgheerardyn/yields/downloads","issues_url":"https://api.github.com/repos/jgheerardyn/yields/issues{/number}","pulls_url":"https://api.github.com/repos/jgheerardyn/yields/pulls{/number}","milestones_url":"https://api.github.com/repos/jgheerardyn/yields/milestones{/number}","notifications_url":"https://api.github.com/repos/jgheerardyn/yields/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jgheerardyn/yields/labels{/name}","releases_url":"https://api.github.com/repos/jgheerardyn/yields/releases{/id}","created_at":"2014-10-06T09:45:19Z","updated_at":"2014-12-24T13:36:30Z","pushed_at":"2015-01-03T19:40:22Z","git_url":"git://github.com/jgheerardyn/yields.git","ssh_url":"git@github.com:jgheerardyn/yields.git","clone_url":"https://github.com/jgheerardyn/yields.git","svn_url":"https://github.com/jgheerardyn/yields","homepage":null,"size":1057,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":0,"default_branch":"master"}},"base":{"label":"jgheerardyn:master","ref":"master","sha":"dc06021c0feab91e02286360521fabde7e6f924f","user":{"login":"jgheerardyn","id":6535557,"avatar_url":"https://avatars.githubusercontent.com/u/6535557?v=3","gravatar_id":"","url":"https://api.github.com/users/jgheerardyn","html_url":"https://github.com/jgheerardyn","followers_url":"https://api.github.com/users/jgheerardyn/followers","following_url":"https://api.github.com/users/jgheerardyn/following{/other_user}","gists_url":"https://api.github.com/users/jgheerardyn/gists{/gist_id}","starred_url":"https://api.github.com/users/jgheerardyn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jgheerardyn/subscriptions","organizations_url":"https://api.github.com/users/jgheerardyn/orgs","repos_url":"https://api.github.com/users/jgheerardyn/repos","events_url":"https://api.github.com/users/jgheerardyn/events{/privacy}","received_events_url":"https://api.github.com/users/jgheerardyn/received_events","type":"User","site_admin":false},"repo":{"id":24840606,"name":"yields","full_name":"jgheerardyn/yields","owner":{"login":"jgheerardyn","id":6535557,"avatar_url":"https://avatars.githubusercontent.com/u/6535557?v=3","gravatar_id":"","url":"https://api.github.com/users/jgheerardyn","html_url":"https://github.com/jgheerardyn","followers_url":"https://api.github.com/users/jgheerardyn/followers","following_url":"https://api.github.com/users/jgheerardyn/following{/other_user}","gists_url":"https://api.github.com/users/jgheerardyn/gists{/gist_id}","starred_url":"https://api.github.com/users/jgheerardyn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jgheerardyn/subscriptions","organizations_url":"https://api.github.com/users/jgheerardyn/orgs","repos_url":"https://api.github.com/users/jgheerardyn/repos","events_url":"https://api.github.com/users/jgheerardyn/events{/privacy}","received_events_url":"https://api.github.com/users/jgheerardyn/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jgheerardyn/yields","description":"Mathematic software testing framework","fork":false,"url":"https://api.github.com/repos/jgheerardyn/yields","forks_url":"https://api.github.com/repos/jgheerardyn/yields/forks","keys_url":"https://api.github.com/repos/jgheerardyn/yields/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jgheerardyn/yields/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jgheerardyn/yields/teams","hooks_url":"https://api.github.com/repos/jgheerardyn/yields/hooks","issue_events_url":"https://api.github.com/repos/jgheerardyn/yields/issues/events{/number}","events_url":"https://api.github.com/repos/jgheerardyn/yields/events","assignees_url":"https://api.github.com/repos/jgheerardyn/yields/assignees{/user}","branches_url":"https://api.github.com/repos/jgheerardyn/yields/branches{/branch}","tags_url":"https://api.github.com/repos/jgheerardyn/yields/tags","blobs_url":"https://api.github.com/repos/jgheerardyn/yields/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jgheerardyn/yields/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jgheerardyn/yields/git/refs{/sha}","trees_url":"https://api.github.com/repos/jgheerardyn/yields/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jgheerardyn/yields/statuses/{sha}","languages_url":"https://api.github.com/repos/jgheerardyn/yields/languages","stargazers_url":"https://api.github.com/repos/jgheerardyn/yields/stargazers","contributors_url":"https://api.github.com/repos/jgheerardyn/yields/contributors","subscribers_url":"https://api.github.com/repos/jgheerardyn/yields/subscribers","subscription_url":"https://api.github.com/repos/jgheerardyn/yields/subscription","commits_url":"https://api.github.com/repos/jgheerardyn/yields/commits{/sha}","git_commits_url":"https://api.github.com/repos/jgheerardyn/yields/git/commits{/sha}","comments_url":"https://api.github.com/repos/jgheerardyn/yields/comments{/number}","issue_comment_url":"https://api.github.com/repos/jgheerardyn/yields/issues/comments/{number}","contents_url":"https://api.github.com/repos/jgheerardyn/yields/contents/{+path}","compare_url":"https://api.github.com/repos/jgheerardyn/yields/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jgheerardyn/yields/merges","archive_url":"https://api.github.com/repos/jgheerardyn/yields/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jgheerardyn/yields/downloads","issues_url":"https://api.github.com/repos/jgheerardyn/yields/issues{/number}","pulls_url":"https://api.github.com/repos/jgheerardyn/yields/pulls{/number}","milestones_url":"https://api.github.com/repos/jgheerardyn/yields/milestones{/number}","notifications_url":"https://api.github.com/repos/jgheerardyn/yields/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jgheerardyn/yields/labels{/name}","releases_url":"https://api.github.com/repos/jgheerardyn/yields/releases{/id}","created_at":"2014-10-06T09:45:19Z","updated_at":"2014-12-24T13:36:30Z","pushed_at":"2015-01-03T19:40:22Z","git_url":"git://github.com/jgheerardyn/yields.git","ssh_url":"git@github.com:jgheerardyn/yields.git","clone_url":"https://github.com/jgheerardyn/yields.git","svn_url":"https://github.com/jgheerardyn/yields","homepage":null,"size":1057,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/jgheerardyn/yields/pulls/39"},"html":{"href":"https://github.com/jgheerardyn/yields/pull/39"},"issue":{"href":"https://api.github.com/repos/jgheerardyn/yields/issues/39"},"comments":{"href":"https://api.github.com/repos/jgheerardyn/yields/issues/39/comments"},"review_comments":{"href":"https://api.github.com/repos/jgheerardyn/yields/pulls/39/comments"},"review_comment":{"href":"https://api.github.com/repos/jgheerardyn/yields/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/jgheerardyn/yields/pulls/39/commits"},"statuses":{"href":"https://api.github.com/repos/jgheerardyn/yields/statuses/e9d1b723ed4df50a02268710e54dd693e39de74f"}}}}