{"action":"created","comment":{"url":"https://api.github.com/repos/SciTools/tehuti/pulls/comments/34662976","id":34662976,"diff_hunk":"@@ -17,78 +17,95 @@\n # along with Tehuti.  If not, see <http://www.gnu.org/licenses/>.\n import argparse\n \n-import matplotlib.pyplot as plt\n+from tehuti import Results\n+from vis_methods import VaryRepoCommit, Violin\n \n-from tehuti import Results, sha, shorten_sha\n \n+class Vis(object):\n+    \"\"\"Provides functionality to visualise tehuti metrics results.\"\"\"\n \n-# Based on (minor label tweaks and line plotting on single value input):\n-# http://pyinsci.blogspot.co.uk/2009/09/violin-plot-with-matplotlib.html\n-def violin_plot(ax,data,bp=False):\n-    '''\n-    create violin plots on an axis\n-    '''\n-    from scipy.stats import gaussian_kde\n-    from numpy import arange\n-    pos = range(len(data))\n-    dist = max(pos)-min(pos)\n-    w = min(0.15*max(dist,1.0),0.5)\n-    for d,p in zip(data,pos):\n-        # If we only have a single value, plot a line instead\n+    def __init__(self, results, method):\n+        \"\"\"\n+        Construct a tehuti metrics visualiser.\n+\n+        The data selected and plots produced are determined by the\n+        visualisation method (or state) that the visualiser is constructed\n+        with.\n+\n+        Args:\n+\n+        * results:\n+            The benchmarking results to visualise.\n+        * method:\n+            The visualisation method (state) to use. Available states are:\n+                * 'basic': plot benchmark results against repository commits\n+                           for all supplied metrics.\n+                * 'violin': plot benchmark results as a violin plot.\n+        \"\"\"\n+        self.results = results\n+        self._method = method\n+        self.plot_data = None\n+\n+        self.methods = {'basic': VaryRepoCommit(self),\n+                        'violin': Violin(self)}\n+\n+    @property\n+    def method(self):\n+        if self._method is None:\n+            self._method = 'basic'\n+        return self.methods[self._method]\n+\n+    @method.setter\n+    def method(self, value):\n         try:\n-            k = gaussian_kde(d) #calculates the kernel density\n-        except ValueError:\n-            ax.hlines(d, p-w, p+w)\n-        else:\n-            line = False\n-            m = k.dataset.min() #lower bound of violin\n-            M = k.dataset.max() #upper bound of violin\n-            x = arange(m,M,(M-m)/100.) # support for violin\n-            v = k.evaluate(x) #violin profile (density curve)\n-            v = v/v.max()*w #scaling the violin to the available space\n-            ax.fill_betweenx(x,p,v+p,facecolor='y',alpha=0.3)\n-            ax.fill_betweenx(x,p,-v+p,facecolor='y',alpha=0.3)\n-    if bp:\n-        ax.boxplot(data,notch=1,positions=pos,vert=1)\n-\n-\n-def plot(picked, single_id):\n-    keys = None\n-    for commit, results in picked:\n-        if keys is None:\n-            keys = results.viewkeys()\n-        else:\n-            keys = keys & results.viewkeys()\n-    for key in keys:\n-        if key == 'name' or (single_id and key != single_id):\n-            continue\n-        labels = []\n-        data = []\n-        for commit, results in picked:\n-            labels.append(shorten_sha(commit))\n-            data.append(results[key])\n-        ax = plt.axes()\n-        ax.set_title(key)\n-        if isinstance(data[0], list):\n-            violin_plot(ax, data)\n-        else:\n-            width = 0.6\n-            pos = [x - (width / 2) for x in range(len(data))]\n-            ax.bar(pos, data, width=width)\n-        ax.set_xticks(range(len(data)))\n-        ax.set_xticklabels(labels, rotation=30)\n-        plt.tight_layout()\n-        plt.show()\n+            self._method = self.methods[value]\n+        except KeyError:\n+            msg = 'Vis has no method {}.'\n+            raise AttributeError(msg.format(value))\n+\n+    def select_data(self, commits=None, metrics=None):\n+        \"\"\"\n+        Select data to plot. Processing is handed off to the `select_data`\n+        method of the current state.\n+\n+        Args:","path":"tehuti-vis.py","position":120,"original_position":120,"commit_id":"392662dd34aaefa1d78aad2e3af061b721a972c9","original_commit_id":"392662dd34aaefa1d78aad2e3af061b721a972c9","user":{"login":"bjlittle","id":2051656,"avatar_url":"https://avatars.githubusercontent.com/u/2051656?v=3","gravatar_id":"","url":"https://api.github.com/users/bjlittle","html_url":"https://github.com/bjlittle","followers_url":"https://api.github.com/users/bjlittle/followers","following_url":"https://api.github.com/users/bjlittle/following{/other_user}","gists_url":"https://api.github.com/users/bjlittle/gists{/gist_id}","starred_url":"https://api.github.com/users/bjlittle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bjlittle/subscriptions","organizations_url":"https://api.github.com/users/bjlittle/orgs","repos_url":"https://api.github.com/users/bjlittle/repos","events_url":"https://api.github.com/users/bjlittle/events{/privacy}","received_events_url":"https://api.github.com/users/bjlittle/received_events","type":"User","site_admin":false},"body":"@dkillick These are `Kwargs` ...","created_at":"2015-07-15T09:53:42Z","updated_at":"2015-07-15T09:53:42Z","html_url":"https://github.com/SciTools/tehuti/pull/10#discussion_r34662976","pull_request_url":"https://api.github.com/repos/SciTools/tehuti/pulls/10","_links":{"self":{"href":"https://api.github.com/repos/SciTools/tehuti/pulls/comments/34662976"},"html":{"href":"https://github.com/SciTools/tehuti/pull/10#discussion_r34662976"},"pull_request":{"href":"https://api.github.com/repos/SciTools/tehuti/pulls/10"}}},"pull_request":{"url":"https://api.github.com/repos/SciTools/tehuti/pulls/10","id":39897594,"html_url":"https://github.com/SciTools/tehuti/pull/10","diff_url":"https://github.com/SciTools/tehuti/pull/10.diff","patch_url":"https://github.com/SciTools/tehuti/pull/10.patch","issue_url":"https://api.github.com/repos/SciTools/tehuti/issues/10","number":10,"state":"open","locked":false,"title":"Improve tehuti-vis plotting","user":{"login":"dkillick","id":3473068,"avatar_url":"https://avatars.githubusercontent.com/u/3473068?v=3","gravatar_id":"","url":"https://api.github.com/users/dkillick","html_url":"https://github.com/dkillick","followers_url":"https://api.github.com/users/dkillick/followers","following_url":"https://api.github.com/users/dkillick/following{/other_user}","gists_url":"https://api.github.com/users/dkillick/gists{/gist_id}","starred_url":"https://api.github.com/users/dkillick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkillick/subscriptions","organizations_url":"https://api.github.com/users/dkillick/orgs","repos_url":"https://api.github.com/users/dkillick/repos","events_url":"https://api.github.com/users/dkillick/events{/privacy}","received_events_url":"https://api.github.com/users/dkillick/received_events","type":"User","site_admin":false},"body":"Improve the tehuti-vis plotting functionality, primarily so that any number of commits can be plotted in a single plot.\r\n\r\nThe plotting module has been re-designed to follow the OO state pattern so that new plotting methods (states) can be easily added. State classes are included in the new file `vis_methods`.","created_at":"2015-07-14T09:32:46Z","updated_at":"2015-07-15T09:53:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5430e403a44534073a30d3bda3b94d8d2cabd423","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/SciTools/tehuti/pulls/10/commits","review_comments_url":"https://api.github.com/repos/SciTools/tehuti/pulls/10/comments","review_comment_url":"https://api.github.com/repos/SciTools/tehuti/pulls/comments{/number}","comments_url":"https://api.github.com/repos/SciTools/tehuti/issues/10/comments","statuses_url":"https://api.github.com/repos/SciTools/tehuti/statuses/392662dd34aaefa1d78aad2e3af061b721a972c9","head":{"label":"dkillick:improve_vis","ref":"improve_vis","sha":"392662dd34aaefa1d78aad2e3af061b721a972c9","user":{"login":"dkillick","id":3473068,"avatar_url":"https://avatars.githubusercontent.com/u/3473068?v=3","gravatar_id":"","url":"https://api.github.com/users/dkillick","html_url":"https://github.com/dkillick","followers_url":"https://api.github.com/users/dkillick/followers","following_url":"https://api.github.com/users/dkillick/following{/other_user}","gists_url":"https://api.github.com/users/dkillick/gists{/gist_id}","starred_url":"https://api.github.com/users/dkillick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkillick/subscriptions","organizations_url":"https://api.github.com/users/dkillick/orgs","repos_url":"https://api.github.com/users/dkillick/repos","events_url":"https://api.github.com/users/dkillick/events{/privacy}","received_events_url":"https://api.github.com/users/dkillick/received_events","type":"User","site_admin":false},"repo":{"id":19315114,"name":"tehuti","full_name":"dkillick/tehuti","owner":{"login":"dkillick","id":3473068,"avatar_url":"https://avatars.githubusercontent.com/u/3473068?v=3","gravatar_id":"","url":"https://api.github.com/users/dkillick","html_url":"https://github.com/dkillick","followers_url":"https://api.github.com/users/dkillick/followers","following_url":"https://api.github.com/users/dkillick/following{/other_user}","gists_url":"https://api.github.com/users/dkillick/gists{/gist_id}","starred_url":"https://api.github.com/users/dkillick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkillick/subscriptions","organizations_url":"https://api.github.com/users/dkillick/orgs","repos_url":"https://api.github.com/users/dkillick/repos","events_url":"https://api.github.com/users/dkillick/events{/privacy}","received_events_url":"https://api.github.com/users/dkillick/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dkillick/tehuti","description":"","fork":true,"url":"https://api.github.com/repos/dkillick/tehuti","forks_url":"https://api.github.com/repos/dkillick/tehuti/forks","keys_url":"https://api.github.com/repos/dkillick/tehuti/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dkillick/tehuti/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dkillick/tehuti/teams","hooks_url":"https://api.github.com/repos/dkillick/tehuti/hooks","issue_events_url":"https://api.github.com/repos/dkillick/tehuti/issues/events{/number}","events_url":"https://api.github.com/repos/dkillick/tehuti/events","assignees_url":"https://api.github.com/repos/dkillick/tehuti/assignees{/user}","branches_url":"https://api.github.com/repos/dkillick/tehuti/branches{/branch}","tags_url":"https://api.github.com/repos/dkillick/tehuti/tags","blobs_url":"https://api.github.com/repos/dkillick/tehuti/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dkillick/tehuti/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dkillick/tehuti/git/refs{/sha}","trees_url":"https://api.github.com/repos/dkillick/tehuti/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dkillick/tehuti/statuses/{sha}","languages_url":"https://api.github.com/repos/dkillick/tehuti/languages","stargazers_url":"https://api.github.com/repos/dkillick/tehuti/stargazers","contributors_url":"https://api.github.com/repos/dkillick/tehuti/contributors","subscribers_url":"https://api.github.com/repos/dkillick/tehuti/subscribers","subscription_url":"https://api.github.com/repos/dkillick/tehuti/subscription","commits_url":"https://api.github.com/repos/dkillick/tehuti/commits{/sha}","git_commits_url":"https://api.github.com/repos/dkillick/tehuti/git/commits{/sha}","comments_url":"https://api.github.com/repos/dkillick/tehuti/comments{/number}","issue_comment_url":"https://api.github.com/repos/dkillick/tehuti/issues/comments{/number}","contents_url":"https://api.github.com/repos/dkillick/tehuti/contents/{+path}","compare_url":"https://api.github.com/repos/dkillick/tehuti/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dkillick/tehuti/merges","archive_url":"https://api.github.com/repos/dkillick/tehuti/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dkillick/tehuti/downloads","issues_url":"https://api.github.com/repos/dkillick/tehuti/issues{/number}","pulls_url":"https://api.github.com/repos/dkillick/tehuti/pulls{/number}","milestones_url":"https://api.github.com/repos/dkillick/tehuti/milestones{/number}","notifications_url":"https://api.github.com/repos/dkillick/tehuti/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dkillick/tehuti/labels{/name}","releases_url":"https://api.github.com/repos/dkillick/tehuti/releases{/id}","created_at":"2014-04-30T13:52:51Z","updated_at":"2014-05-21T12:43:29Z","pushed_at":"2015-07-14T09:21:16Z","git_url":"git://github.com/dkillick/tehuti.git","ssh_url":"git@github.com:dkillick/tehuti.git","clone_url":"https://github.com/dkillick/tehuti.git","svn_url":"https://github.com/dkillick/tehuti","homepage":null,"size":173,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"SciTools:master","ref":"master","sha":"72f41b72e63f3b915bb11871fd7630596f0c49a4","user":{"login":"SciTools","id":1391487,"avatar_url":"https://avatars.githubusercontent.com/u/1391487?v=3","gravatar_id":"","url":"https://api.github.com/users/SciTools","html_url":"https://github.com/SciTools","followers_url":"https://api.github.com/users/SciTools/followers","following_url":"https://api.github.com/users/SciTools/following{/other_user}","gists_url":"https://api.github.com/users/SciTools/gists{/gist_id}","starred_url":"https://api.github.com/users/SciTools/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SciTools/subscriptions","organizations_url":"https://api.github.com/users/SciTools/orgs","repos_url":"https://api.github.com/users/SciTools/repos","events_url":"https://api.github.com/users/SciTools/events{/privacy}","received_events_url":"https://api.github.com/users/SciTools/received_events","type":"Organization","site_admin":false},"repo":{"id":16983432,"name":"tehuti","full_name":"SciTools/tehuti","owner":{"login":"SciTools","id":1391487,"avatar_url":"https://avatars.githubusercontent.com/u/1391487?v=3","gravatar_id":"","url":"https://api.github.com/users/SciTools","html_url":"https://github.com/SciTools","followers_url":"https://api.github.com/users/SciTools/followers","following_url":"https://api.github.com/users/SciTools/following{/other_user}","gists_url":"https://api.github.com/users/SciTools/gists{/gist_id}","starred_url":"https://api.github.com/users/SciTools/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SciTools/subscriptions","organizations_url":"https://api.github.com/users/SciTools/orgs","repos_url":"https://api.github.com/users/SciTools/repos","events_url":"https://api.github.com/users/SciTools/events{/privacy}","received_events_url":"https://api.github.com/users/SciTools/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SciTools/tehuti","description":"","fork":false,"url":"https://api.github.com/repos/SciTools/tehuti","forks_url":"https://api.github.com/repos/SciTools/tehuti/forks","keys_url":"https://api.github.com/repos/SciTools/tehuti/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SciTools/tehuti/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SciTools/tehuti/teams","hooks_url":"https://api.github.com/repos/SciTools/tehuti/hooks","issue_events_url":"https://api.github.com/repos/SciTools/tehuti/issues/events{/number}","events_url":"https://api.github.com/repos/SciTools/tehuti/events","assignees_url":"https://api.github.com/repos/SciTools/tehuti/assignees{/user}","branches_url":"https://api.github.com/repos/SciTools/tehuti/branches{/branch}","tags_url":"https://api.github.com/repos/SciTools/tehuti/tags","blobs_url":"https://api.github.com/repos/SciTools/tehuti/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SciTools/tehuti/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SciTools/tehuti/git/refs{/sha}","trees_url":"https://api.github.com/repos/SciTools/tehuti/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SciTools/tehuti/statuses/{sha}","languages_url":"https://api.github.com/repos/SciTools/tehuti/languages","stargazers_url":"https://api.github.com/repos/SciTools/tehuti/stargazers","contributors_url":"https://api.github.com/repos/SciTools/tehuti/contributors","subscribers_url":"https://api.github.com/repos/SciTools/tehuti/subscribers","subscription_url":"https://api.github.com/repos/SciTools/tehuti/subscription","commits_url":"https://api.github.com/repos/SciTools/tehuti/commits{/sha}","git_commits_url":"https://api.github.com/repos/SciTools/tehuti/git/commits{/sha}","comments_url":"https://api.github.com/repos/SciTools/tehuti/comments{/number}","issue_comment_url":"https://api.github.com/repos/SciTools/tehuti/issues/comments{/number}","contents_url":"https://api.github.com/repos/SciTools/tehuti/contents/{+path}","compare_url":"https://api.github.com/repos/SciTools/tehuti/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SciTools/tehuti/merges","archive_url":"https://api.github.com/repos/SciTools/tehuti/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SciTools/tehuti/downloads","issues_url":"https://api.github.com/repos/SciTools/tehuti/issues{/number}","pulls_url":"https://api.github.com/repos/SciTools/tehuti/pulls{/number}","milestones_url":"https://api.github.com/repos/SciTools/tehuti/milestones{/number}","notifications_url":"https://api.github.com/repos/SciTools/tehuti/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SciTools/tehuti/labels{/name}","releases_url":"https://api.github.com/repos/SciTools/tehuti/releases{/id}","created_at":"2014-02-19T12:26:40Z","updated_at":"2015-07-03T07:02:37Z","pushed_at":"2015-07-14T09:32:46Z","git_url":"git://github.com/SciTools/tehuti.git","ssh_url":"git@github.com:SciTools/tehuti.git","clone_url":"https://github.com/SciTools/tehuti.git","svn_url":"https://github.com/SciTools/tehuti","homepage":null,"size":340,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":4,"forks":6,"open_issues":4,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SciTools/tehuti/pulls/10"},"html":{"href":"https://github.com/SciTools/tehuti/pull/10"},"issue":{"href":"https://api.github.com/repos/SciTools/tehuti/issues/10"},"comments":{"href":"https://api.github.com/repos/SciTools/tehuti/issues/10/comments"},"review_comments":{"href":"https://api.github.com/repos/SciTools/tehuti/pulls/10/comments"},"review_comment":{"href":"https://api.github.com/repos/SciTools/tehuti/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/SciTools/tehuti/pulls/10/commits"},"statuses":{"href":"https://api.github.com/repos/SciTools/tehuti/statuses/392662dd34aaefa1d78aad2e3af061b721a972c9"}}}}