{"action":"created","comment":{"url":"https://api.github.com/repos/QCoDeS/Qcodes/pulls/comments/116942999","pull_request_review_id":38604191,"id":116942999,"diff_hunk":"@@ -0,0 +1,231 @@\n+import asyncio\n+import socket\n+from typing import Dict, Union\n+import time\n+import json\n+import logging\n+\n+from aiohttp import web\n+from aiohttp.hdrs import METH_POST\n+import websockets\n+\n+import qcodes\n+from qcodes.instrument_drivers.oxford.triton import Triton\n+from qcodes.instrument_drivers.oxford.mock_triton import MockTriton\n+\n+log = logging.getLogger(__name__)\n+use_mock_triton = qcodes.config['fridgeserver']['usemocktriton']\n+triton_address = qcodes.config['fridgeserver']['tritonaddress']\n+triton_name = qcodes.config['fridgeserver']['tritonname']\n+\n+class FridgeHttpServer:\n+\n+    def __init__(self, name=triton_name, triton_address=triton_address, use_mock_triton=use_mock_triton, triton_port=33576):\n+\n+        self._send_websockets = False\n+        if use_mock_triton:\n+            self.triton = MockTriton()\n+        else:\n+            self.triton = Triton(name=name, address=triton_address, port=triton_port)\n+\n+    async def handle_parameter(self, request):\n+        \"\"\"\n+        Handler for qcodes parameters, Can expose the value, unit, name and label of a parameter via get\n+        or allow the setting of a parameter via a POST request.\n+        \"\"\"\n+        parametername = request.match_info.get('parametername', None)\n+        query = request.query\n+        valid_attributes = ('value', 'unit', 'name', 'label')\n+        if parametername in self.triton.parameters:\n+            parameter = getattr(self.triton, parametername)\n+            if request.method == METH_POST:\n+                data = await request.json()\n+                try:\n+                    parameter.set(data['setpoint'])\n+                except ValueError:\n+                    return web.Response(status=405)\n+                return web.Response(text='OK')\n+            attribute = query.get('attribute', None)\n+            if attribute in valid_attributes:\n+                if attribute == 'value':\n+                    data = parameter()\n+                else:\n+                    data = getattr(parameter, attribute)\n+\n+                return web.Response(text=str(data))\n+            elif attribute == None:\n+                return web.Response(status=404, text=\"Usage ip/parameter?attribute=attributes i.e. \"\n+                                                     \"ip/T1/attribute=value. \"\n+                                                     \"Valid attributes are {}\".format(valid_attributes))\n+            else:\n+                return web.Response(status=404, text=\"Parameter {} does not have attribute {}\".format(parameter, attribute))\n+        else:\n+            return web.Response(status=404, text=\"Parameter {} not found\".format(parametername))\n+\n+    async def index(self, request):\n+        \"\"\"\n+        Handler for a very basic index page that just tells you how to use the html api.\n+        \"\"\"\n+        return web.Response(text=\"Usage ip/parameter?attribute=value i.e. ip/T1/attribute=value\")\n+\n+    async def handle_hostname(self, request):\n+        host =  socket.gethostname()\n+        return web.Response(text=host)\n+\n+    @staticmethod\n+    def prepare_monitor_data(triton) -> Dict[str, Union[list, float]]:\n+        \"\"\"\n+        Return a dict that contains the parameter from the Triton to be monitored.\n+        \"\"\"\n+\n+        def get_data(triton, parametername):\n+            parameter = getattr(triton, parametername)\n+            parameter.get()\n+            temp = parameter._latest()\n+            temp['unit'] = parameter.unit\n+            # replace with reading directly from reg database once running on fridge computer\n+            namedict = triton.chan_temp_names.get(parametername, None)\n+            if namedict:\n+                fullname = namedict['name']\n+            else:\n+                fullname = None\n+            temp['name'] = fullname or parameter.label or parameter.name\n+            temp['value'] = str(temp['value'])\n+            if temp[\"ts\"] is not None:\n+                temp[\"ts\"] = time.mktime(temp[\"ts\"].timetuple())\n+\n+            return temp\n+\n+        triton_parameters = []\n+        for parametername in triton.parameters:\n+            temp = get_data(triton, parametername)\n+            triton_parameters.append(temp)\n+\n+        triton_parameters.append(get_data(triton, 'action'))\n+        triton_parameters.append(get_data(triton, 'status'))\n+\n+        parameters_dict = {\"instrument\": triton.name, \"parameters\": triton_parameters}\n+        state = {\"ts\": time.time(), \"parameters\": [parameters_dict]}\n+\n+        return state\n+\n+    @staticmethod\n+    def prepare_ws_data(triton) -> Dict[str, Union[list, float]]:\n+        \"\"\"\n+        Return a dict that contains the parameter from the Triton to be exported via WS. This includes a read only copy\n+        of all parametes exposed by the driver.\n+        \"\"\"\n+\n+        triton_parameters = []\n+        for parametername in triton.parameters:\n+            parameter = getattr(triton, parametername)\n+            temp = {}\n+            temp['value'] = parameter.get()","path":"qcodes/instrument_drivers/oxford/fridge_http_server.py","position":123,"original_position":123,"commit_id":"657a095c4f385d3ad739017817e4a143f62f3df7","original_commit_id":"657a095c4f385d3ad739017817e4a143f62f3df7","user":{"login":"jenshnielsen","id":548266,"avatar_url":"https://avatars1.githubusercontent.com/u/548266?v=3","gravatar_id":"","url":"https://api.github.com/users/jenshnielsen","html_url":"https://github.com/jenshnielsen","followers_url":"https://api.github.com/users/jenshnielsen/followers","following_url":"https://api.github.com/users/jenshnielsen/following{/other_user}","gists_url":"https://api.github.com/users/jenshnielsen/gists{/gist_id}","starred_url":"https://api.github.com/users/jenshnielsen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jenshnielsen/subscriptions","organizations_url":"https://api.github.com/users/jenshnielsen/orgs","repos_url":"https://api.github.com/users/jenshnielsen/repos","events_url":"https://api.github.com/users/jenshnielsen/events{/privacy}","received_events_url":"https://api.github.com/users/jenshnielsen/received_events","type":"User","site_admin":false},"body":"Maybe, not sure. If it's a get_latest and nothing else is reading from the remote driver then it will never be updated?","created_at":"2017-05-17T08:44:54Z","updated_at":"2017-05-17T08:44:54Z","html_url":"https://github.com/QCoDeS/Qcodes/pull/590#discussion_r116942999","pull_request_url":"https://api.github.com/repos/QCoDeS/Qcodes/pulls/590","_links":{"self":{"href":"https://api.github.com/repos/QCoDeS/Qcodes/pulls/comments/116942999"},"html":{"href":"https://github.com/QCoDeS/Qcodes/pull/590#discussion_r116942999"},"pull_request":{"href":"https://api.github.com/repos/QCoDeS/Qcodes/pulls/590"}}},"pull_request":{"url":"https://api.github.com/repos/QCoDeS/Qcodes/pulls/590","id":118588363,"html_url":"https://github.com/QCoDeS/Qcodes/pull/590","diff_url":"https://github.com/QCoDeS/Qcodes/pull/590.diff","patch_url":"https://github.com/QCoDeS/Qcodes/pull/590.patch","issue_url":"https://api.github.com/repos/QCoDeS/Qcodes/issues/590","number":590,"state":"open","locked":false,"title":"Triton Http proxy server","user":{"login":"jenshnielsen","id":548266,"avatar_url":"https://avatars1.githubusercontent.com/u/548266?v=3","gravatar_id":"","url":"https://api.github.com/users/jenshnielsen","html_url":"https://github.com/jenshnielsen","followers_url":"https://api.github.com/users/jenshnielsen/followers","following_url":"https://api.github.com/users/jenshnielsen/following{/other_user}","gists_url":"https://api.github.com/users/jenshnielsen/gists{/gist_id}","starred_url":"https://api.github.com/users/jenshnielsen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jenshnielsen/subscriptions","organizations_url":"https://api.github.com/users/jenshnielsen/orgs","repos_url":"https://api.github.com/users/jenshnielsen/repos","events_url":"https://api.github.com/users/jenshnielsen/events{/privacy}","received_events_url":"https://api.github.com/users/jenshnielsen/received_events","type":"User","site_admin":false},"body":"- [x] Basic aiohttp server for setting and getting Triton parameters, with GET and POST\r\n- [x] RemoteTriton driver. Should be a drop in replacement for the current driver to use the proxy. \r\n- [x] Websockets exposing Json representation of the data\r\n- [x] Endpoint to start/stop ws\r\n- [x] Config for Triton location, ports, wait times etc.\r\n- [x] Testing locally on real Triton computer\r\n- [ ] Benchmarking. Requires Local testing\r\n- [ ] Finish reading of Parameter names from regdatabase on local Triton.\r\n","created_at":"2017-05-02T15:59:27Z","updated_at":"2017-05-17T08:44:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e0f880599c28ad59b7ede0f88878a59a3ce889f4","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/QCoDeS/Qcodes/pulls/590/commits","review_comments_url":"https://api.github.com/repos/QCoDeS/Qcodes/pulls/590/comments","review_comment_url":"https://api.github.com/repos/QCoDeS/Qcodes/pulls/comments{/number}","comments_url":"https://api.github.com/repos/QCoDeS/Qcodes/issues/590/comments","statuses_url":"https://api.github.com/repos/QCoDeS/Qcodes/statuses/657a095c4f385d3ad739017817e4a143f62f3df7","head":{"label":"jenshnielsen:fridge_server","ref":"fridge_server","sha":"657a095c4f385d3ad739017817e4a143f62f3df7","user":{"login":"jenshnielsen","id":548266,"avatar_url":"https://avatars1.githubusercontent.com/u/548266?v=3","gravatar_id":"","url":"https://api.github.com/users/jenshnielsen","html_url":"https://github.com/jenshnielsen","followers_url":"https://api.github.com/users/jenshnielsen/followers","following_url":"https://api.github.com/users/jenshnielsen/following{/other_user}","gists_url":"https://api.github.com/users/jenshnielsen/gists{/gist_id}","starred_url":"https://api.github.com/users/jenshnielsen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jenshnielsen/subscriptions","organizations_url":"https://api.github.com/users/jenshnielsen/orgs","repos_url":"https://api.github.com/users/jenshnielsen/repos","events_url":"https://api.github.com/users/jenshnielsen/events{/privacy}","received_events_url":"https://api.github.com/users/jenshnielsen/received_events","type":"User","site_admin":false},"repo":{"id":76858940,"name":"Qcodes","full_name":"jenshnielsen/Qcodes","owner":{"login":"jenshnielsen","id":548266,"avatar_url":"https://avatars1.githubusercontent.com/u/548266?v=3","gravatar_id":"","url":"https://api.github.com/users/jenshnielsen","html_url":"https://github.com/jenshnielsen","followers_url":"https://api.github.com/users/jenshnielsen/followers","following_url":"https://api.github.com/users/jenshnielsen/following{/other_user}","gists_url":"https://api.github.com/users/jenshnielsen/gists{/gist_id}","starred_url":"https://api.github.com/users/jenshnielsen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jenshnielsen/subscriptions","organizations_url":"https://api.github.com/users/jenshnielsen/orgs","repos_url":"https://api.github.com/users/jenshnielsen/repos","events_url":"https://api.github.com/users/jenshnielsen/events{/privacy}","received_events_url":"https://api.github.com/users/jenshnielsen/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jenshnielsen/Qcodes","description":"Modular data acquisition and analysis framework","fork":true,"url":"https://api.github.com/repos/jenshnielsen/Qcodes","forks_url":"https://api.github.com/repos/jenshnielsen/Qcodes/forks","keys_url":"https://api.github.com/repos/jenshnielsen/Qcodes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jenshnielsen/Qcodes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jenshnielsen/Qcodes/teams","hooks_url":"https://api.github.com/repos/jenshnielsen/Qcodes/hooks","issue_events_url":"https://api.github.com/repos/jenshnielsen/Qcodes/issues/events{/number}","events_url":"https://api.github.com/repos/jenshnielsen/Qcodes/events","assignees_url":"https://api.github.com/repos/jenshnielsen/Qcodes/assignees{/user}","branches_url":"https://api.github.com/repos/jenshnielsen/Qcodes/branches{/branch}","tags_url":"https://api.github.com/repos/jenshnielsen/Qcodes/tags","blobs_url":"https://api.github.com/repos/jenshnielsen/Qcodes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jenshnielsen/Qcodes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jenshnielsen/Qcodes/git/refs{/sha}","trees_url":"https://api.github.com/repos/jenshnielsen/Qcodes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jenshnielsen/Qcodes/statuses/{sha}","languages_url":"https://api.github.com/repos/jenshnielsen/Qcodes/languages","stargazers_url":"https://api.github.com/repos/jenshnielsen/Qcodes/stargazers","contributors_url":"https://api.github.com/repos/jenshnielsen/Qcodes/contributors","subscribers_url":"https://api.github.com/repos/jenshnielsen/Qcodes/subscribers","subscription_url":"https://api.github.com/repos/jenshnielsen/Qcodes/subscription","commits_url":"https://api.github.com/repos/jenshnielsen/Qcodes/commits{/sha}","git_commits_url":"https://api.github.com/repos/jenshnielsen/Qcodes/git/commits{/sha}","comments_url":"https://api.github.com/repos/jenshnielsen/Qcodes/comments{/number}","issue_comment_url":"https://api.github.com/repos/jenshnielsen/Qcodes/issues/comments{/number}","contents_url":"https://api.github.com/repos/jenshnielsen/Qcodes/contents/{+path}","compare_url":"https://api.github.com/repos/jenshnielsen/Qcodes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jenshnielsen/Qcodes/merges","archive_url":"https://api.github.com/repos/jenshnielsen/Qcodes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jenshnielsen/Qcodes/downloads","issues_url":"https://api.github.com/repos/jenshnielsen/Qcodes/issues{/number}","pulls_url":"https://api.github.com/repos/jenshnielsen/Qcodes/pulls{/number}","milestones_url":"https://api.github.com/repos/jenshnielsen/Qcodes/milestones{/number}","notifications_url":"https://api.github.com/repos/jenshnielsen/Qcodes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jenshnielsen/Qcodes/labels{/name}","releases_url":"https://api.github.com/repos/jenshnielsen/Qcodes/releases{/id}","deployments_url":"https://api.github.com/repos/jenshnielsen/Qcodes/deployments","created_at":"2016-12-19T12:08:42Z","updated_at":"2016-12-19T12:08:43Z","pushed_at":"2017-05-17T08:26:54Z","git_url":"git://github.com/jenshnielsen/Qcodes.git","ssh_url":"git@github.com:jenshnielsen/Qcodes.git","clone_url":"https://github.com/jenshnielsen/Qcodes.git","svn_url":"https://github.com/jenshnielsen/Qcodes","homepage":"http://qcodes.github.io/Qcodes","size":10617,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"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":"QCoDeS:master","ref":"master","sha":"e9578f3f4d16440c781c5929de2935add9b93958","user":{"login":"QCoDeS","id":20478252,"avatar_url":"https://avatars0.githubusercontent.com/u/20478252?v=3","gravatar_id":"","url":"https://api.github.com/users/QCoDeS","html_url":"https://github.com/QCoDeS","followers_url":"https://api.github.com/users/QCoDeS/followers","following_url":"https://api.github.com/users/QCoDeS/following{/other_user}","gists_url":"https://api.github.com/users/QCoDeS/gists{/gist_id}","starred_url":"https://api.github.com/users/QCoDeS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/QCoDeS/subscriptions","organizations_url":"https://api.github.com/users/QCoDeS/orgs","repos_url":"https://api.github.com/users/QCoDeS/repos","events_url":"https://api.github.com/users/QCoDeS/events{/privacy}","received_events_url":"https://api.github.com/users/QCoDeS/received_events","type":"Organization","site_admin":false},"repo":{"id":37137879,"name":"Qcodes","full_name":"QCoDeS/Qcodes","owner":{"login":"QCoDeS","id":20478252,"avatar_url":"https://avatars0.githubusercontent.com/u/20478252?v=3","gravatar_id":"","url":"https://api.github.com/users/QCoDeS","html_url":"https://github.com/QCoDeS","followers_url":"https://api.github.com/users/QCoDeS/followers","following_url":"https://api.github.com/users/QCoDeS/following{/other_user}","gists_url":"https://api.github.com/users/QCoDeS/gists{/gist_id}","starred_url":"https://api.github.com/users/QCoDeS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/QCoDeS/subscriptions","organizations_url":"https://api.github.com/users/QCoDeS/orgs","repos_url":"https://api.github.com/users/QCoDeS/repos","events_url":"https://api.github.com/users/QCoDeS/events{/privacy}","received_events_url":"https://api.github.com/users/QCoDeS/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/QCoDeS/Qcodes","description":"Modular data acquisition framework","fork":false,"url":"https://api.github.com/repos/QCoDeS/Qcodes","forks_url":"https://api.github.com/repos/QCoDeS/Qcodes/forks","keys_url":"https://api.github.com/repos/QCoDeS/Qcodes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/QCoDeS/Qcodes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/QCoDeS/Qcodes/teams","hooks_url":"https://api.github.com/repos/QCoDeS/Qcodes/hooks","issue_events_url":"https://api.github.com/repos/QCoDeS/Qcodes/issues/events{/number}","events_url":"https://api.github.com/repos/QCoDeS/Qcodes/events","assignees_url":"https://api.github.com/repos/QCoDeS/Qcodes/assignees{/user}","branches_url":"https://api.github.com/repos/QCoDeS/Qcodes/branches{/branch}","tags_url":"https://api.github.com/repos/QCoDeS/Qcodes/tags","blobs_url":"https://api.github.com/repos/QCoDeS/Qcodes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/QCoDeS/Qcodes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/QCoDeS/Qcodes/git/refs{/sha}","trees_url":"https://api.github.com/repos/QCoDeS/Qcodes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/QCoDeS/Qcodes/statuses/{sha}","languages_url":"https://api.github.com/repos/QCoDeS/Qcodes/languages","stargazers_url":"https://api.github.com/repos/QCoDeS/Qcodes/stargazers","contributors_url":"https://api.github.com/repos/QCoDeS/Qcodes/contributors","subscribers_url":"https://api.github.com/repos/QCoDeS/Qcodes/subscribers","subscription_url":"https://api.github.com/repos/QCoDeS/Qcodes/subscription","commits_url":"https://api.github.com/repos/QCoDeS/Qcodes/commits{/sha}","git_commits_url":"https://api.github.com/repos/QCoDeS/Qcodes/git/commits{/sha}","comments_url":"https://api.github.com/repos/QCoDeS/Qcodes/comments{/number}","issue_comment_url":"https://api.github.com/repos/QCoDeS/Qcodes/issues/comments{/number}","contents_url":"https://api.github.com/repos/QCoDeS/Qcodes/contents/{+path}","compare_url":"https://api.github.com/repos/QCoDeS/Qcodes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/QCoDeS/Qcodes/merges","archive_url":"https://api.github.com/repos/QCoDeS/Qcodes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/QCoDeS/Qcodes/downloads","issues_url":"https://api.github.com/repos/QCoDeS/Qcodes/issues{/number}","pulls_url":"https://api.github.com/repos/QCoDeS/Qcodes/pulls{/number}","milestones_url":"https://api.github.com/repos/QCoDeS/Qcodes/milestones{/number}","notifications_url":"https://api.github.com/repos/QCoDeS/Qcodes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/QCoDeS/Qcodes/labels{/name}","releases_url":"https://api.github.com/repos/QCoDeS/Qcodes/releases{/id}","deployments_url":"https://api.github.com/repos/QCoDeS/Qcodes/deployments","created_at":"2015-06-09T14:42:14Z","updated_at":"2017-04-10T14:19:11Z","pushed_at":"2017-05-17T08:26:56Z","git_url":"git://github.com/QCoDeS/Qcodes.git","ssh_url":"git@github.com:QCoDeS/Qcodes.git","clone_url":"https://github.com/QCoDeS/Qcodes.git","svn_url":"https://github.com/QCoDeS/Qcodes","homepage":"http://qcodes.github.io/Qcodes","size":13749,"stargazers_count":19,"watchers_count":19,"language":"Python","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":23,"mirror_url":null,"open_issues_count":111,"forks":23,"open_issues":111,"watchers":19,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/QCoDeS/Qcodes/pulls/590"},"html":{"href":"https://github.com/QCoDeS/Qcodes/pull/590"},"issue":{"href":"https://api.github.com/repos/QCoDeS/Qcodes/issues/590"},"comments":{"href":"https://api.github.com/repos/QCoDeS/Qcodes/issues/590/comments"},"review_comments":{"href":"https://api.github.com/repos/QCoDeS/Qcodes/pulls/590/comments"},"review_comment":{"href":"https://api.github.com/repos/QCoDeS/Qcodes/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/QCoDeS/Qcodes/pulls/590/commits"},"statuses":{"href":"https://api.github.com/repos/QCoDeS/Qcodes/statuses/657a095c4f385d3ad739017817e4a143f62f3df7"}}}}
{"actor":{"display_login":"jenshnielsen"}}