{"action":"created","comment":{"url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/pulls/comments/236225111","pull_request_review_id":178252396,"id":236225111,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzNjIyNTExMQ==","diff_hunk":"@@ -0,0 +1,390 @@\n+from decimal import Decimal\n+import json\n+import logging\n+import os\n+\n+from structlog import wrap_logger\n+\n+from transform.settings import (\n+    SDX_FTP_DATA_PATH,\n+    SDX_FTP_IMAGE_PATH,\n+    SDX_FTP_RECEIPT_PATH,\n+    SDX_RESPONSE_JSON_PATH,\n+)\n+from transform.transformers.cord.cord_formatter import CORDFormatter\n+from transform.transformers.survey import Survey\n+from transform.transformers.image_transformer import ImageTransformer\n+from transform.utilities.general import merge_dicts\n+\n+logger = wrap_logger(logging.getLogger(__name__))\n+\n+\n+class EcommerceTransformer(Survey):\n+    \"\"\"Perform the transforms and formatting for the MBS survey.\"\"\"\n+\n+    def __init__(self, response, seq_nr=0):\n+\n+        self.response = response\n+        self.ids = self.identifiers(self.response, seq_nr=seq_nr, log=logger)\n+\n+        survey_file = \"./transform/surveys/{}.{}.json\".format(\n+            self.ids.survey_id, self.ids.inst_id\n+        )\n+\n+        with open(survey_file) as fp:\n+            logger.info(\"Loading {}\".format(survey_file))\n+            self.survey = json.load(fp)\n+\n+        self.image_transformer = ImageTransformer(\n+            logger,\n+            self.survey,\n+            self.response,\n+            sequence_no=self.ids.seq_nr,\n+            base_image_path=SDX_FTP_IMAGE_PATH,\n+        )\n+\n+    def get_qcode(self, qcode):\n+        \"\"\" Return the value of a qcode, or if it isn't present, then return None\n+        \"\"\"\n+        return self.response['data'].get(qcode, None)\n+\n+    def yes_no_question(self, qcode):\n+        \"\"\" Handles optional Yes / No radio questions\n+        Gets the question value from the submission via qcode\n+        Returns '10' if value is \"Yes\", '01' if value is 'No' and '0' otherwise\n+        \"\"\"\n+        value = self.get_qcode(qcode)\n+        return \"10\" if value == \"Yes\" else \"01\" if value == \"No\" else \"0\"\n+\n+    def checkbox_question(self, qcode):\n+        \"\"\" Handles checkbox question type\n+        Returns a checked or unchecked value depending on whether the answer is present.\n+        Defaults to unchecked value.\n+        If qcode '010' is 'No' then it returns '0' as it's impossible to get to this question when that is true.\n+        \"\"\"\n+        if self.get_qcode('010') == \"No\":\n+            return \"0\"\n+        return '10' if self.get_qcode(qcode) is not None else \"01\"\n+\n+    @staticmethod\n+    def convert_percentage(percentage):\n+        \"\"\" Converts a percentage with possible decimal places into a 0 padded string of length 4. The final string should\n+        represent 1 decimal place. All inputs will be rounded to 1 decimal place.\n+\n+            e.g. 10 -> 0100, 0.1 -> 0001, 23.4 -> 0234, 29.949 -> 0299, 29.950 -> 0300\n+\n+        \"\"\"\n+        value = Decimal(percentage) * 10\n+        value = round(value)\n+        value = str(value).replace('.', '')\n+        return value.rjust(4, '0')\n+\n+    def percentage_question(self, qcode):\n+        \"\"\"\n+        Percentage type question. Will transform to a four digit answer\n+        If answer does not exist in submission, output will be '0'\n+        \"\"\"\n+        value = self.get_qcode(qcode)\n+\n+        if not value:\n+            return '0'","path":"transform/transformers/cord/ecommerce_transformer.py","position":null,"original_position":90,"commit_id":"410dea601aeb1699152be5e188ccac8bfba6dca0","original_commit_id":"6eb11725919780c6f373214da28303c293cda0c6","user":{"login":"insacuri","id":3965382,"node_id":"MDQ6VXNlcjM5NjUzODI=","avatar_url":"https://avatars2.githubusercontent.com/u/3965382?v=4","gravatar_id":"","url":"https://api.github.com/users/insacuri","html_url":"https://github.com/insacuri","followers_url":"https://api.github.com/users/insacuri/followers","following_url":"https://api.github.com/users/insacuri/following{/other_user}","gists_url":"https://api.github.com/users/insacuri/gists{/gist_id}","starred_url":"https://api.github.com/users/insacuri/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/insacuri/subscriptions","organizations_url":"https://api.github.com/users/insacuri/orgs","repos_url":"https://api.github.com/users/insacuri/repos","events_url":"https://api.github.com/users/insacuri/events{/privacy}","received_events_url":"https://api.github.com/users/insacuri/received_events","type":"User","site_admin":false},"body":"Fixed","created_at":"2018-11-26T11:56:07Z","updated_at":"2018-11-26T11:56:07Z","html_url":"https://github.com/ONSdigital/sdx-transform-cs/pull/173#discussion_r236225111","pull_request_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/pulls/173","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/pulls/comments/236225111"},"html":{"href":"https://github.com/ONSdigital/sdx-transform-cs/pull/173#discussion_r236225111"},"pull_request":{"href":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/pulls/173"}},"in_reply_to_id":235982331},"pull_request":{"url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/pulls/173","id":232633294,"node_id":"MDExOlB1bGxSZXF1ZXN0MjMyNjMzMjk0","html_url":"https://github.com/ONSdigital/sdx-transform-cs/pull/173","diff_url":"https://github.com/ONSdigital/sdx-transform-cs/pull/173.diff","patch_url":"https://github.com/ONSdigital/sdx-transform-cs/pull/173.patch","issue_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/issues/173","number":173,"state":"open","locked":false,"title":"Enable transformation for e-commerce","user":{"login":"insacuri","id":3965382,"node_id":"MDQ6VXNlcjM5NjUzODI=","avatar_url":"https://avatars2.githubusercontent.com/u/3965382?v=4","gravatar_id":"","url":"https://api.github.com/users/insacuri","html_url":"https://github.com/insacuri","followers_url":"https://api.github.com/users/insacuri/followers","following_url":"https://api.github.com/users/insacuri/following{/other_user}","gists_url":"https://api.github.com/users/insacuri/gists{/gist_id}","starred_url":"https://api.github.com/users/insacuri/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/insacuri/subscriptions","organizations_url":"https://api.github.com/users/insacuri/orgs","repos_url":"https://api.github.com/users/insacuri/repos","events_url":"https://api.github.com/users/insacuri/events{/privacy}","received_events_url":"https://api.github.com/users/insacuri/received_events","type":"User","site_admin":false},"body":"## What? and Why?\r\nhttps://trello.com/c/LJXexVU2/2591-e-commerce-sdx-transformation-for-openroad\r\n\r\nAdded transformation for e-commerce survey.  Also created framework to handle additional surveys destined for CORD.\r\n\r\n## How to test:\r\nCheck out the branch of the same name in the following repos:\r\nsdx-validate\r\nsdx-console\r\nsdx-downstream\r\nsdx-transform-cs\r\n\r\nSubmit example submission in console (187.0001).  Ensure the the files look sensible (PCK, IDBR receipt, images).  The PCK format is vastly different from previous ones so that needs to be verified.  Every qcode should be present regardless of the answer (unanswered questions are '0') so this needs to be tested.\r\nAdditionally, the image needs to be reviewed too.  The images generated by the transformer have historically been not excellent (to put it lightly) but as long as they conveyed the information, it's been fine.\r\n\r\n## Checklist\r\n  - [x] CHANGELOG.md updated? (if required)\r\n","created_at":"2018-11-21T11:42:12Z","updated_at":"2018-11-26T11:56:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2852749b3864696976c347c8aac9400ba061d824","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/pulls/173/commits","review_comments_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/pulls/173/comments","review_comment_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/issues/173/comments","statuses_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/statuses/410dea601aeb1699152be5e188ccac8bfba6dca0","head":{"label":"ONSdigital:e-commerce-sdx-transformation-for-openroad","ref":"e-commerce-sdx-transformation-for-openroad","sha":"410dea601aeb1699152be5e188ccac8bfba6dca0","user":{"login":"ONSdigital","id":6865137,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY4NjUxMzc=","avatar_url":"https://avatars0.githubusercontent.com/u/6865137?v=4","gravatar_id":"","url":"https://api.github.com/users/ONSdigital","html_url":"https://github.com/ONSdigital","followers_url":"https://api.github.com/users/ONSdigital/followers","following_url":"https://api.github.com/users/ONSdigital/following{/other_user}","gists_url":"https://api.github.com/users/ONSdigital/gists{/gist_id}","starred_url":"https://api.github.com/users/ONSdigital/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ONSdigital/subscriptions","organizations_url":"https://api.github.com/users/ONSdigital/orgs","repos_url":"https://api.github.com/users/ONSdigital/repos","events_url":"https://api.github.com/users/ONSdigital/events{/privacy}","received_events_url":"https://api.github.com/users/ONSdigital/received_events","type":"Organization","site_admin":false},"repo":{"id":59762598,"node_id":"MDEwOlJlcG9zaXRvcnk1OTc2MjU5OA==","name":"sdx-transform-cs","full_name":"ONSdigital/sdx-transform-cs","private":false,"owner":{"login":"ONSdigital","id":6865137,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY4NjUxMzc=","avatar_url":"https://avatars0.githubusercontent.com/u/6865137?v=4","gravatar_id":"","url":"https://api.github.com/users/ONSdigital","html_url":"https://github.com/ONSdigital","followers_url":"https://api.github.com/users/ONSdigital/followers","following_url":"https://api.github.com/users/ONSdigital/following{/other_user}","gists_url":"https://api.github.com/users/ONSdigital/gists{/gist_id}","starred_url":"https://api.github.com/users/ONSdigital/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ONSdigital/subscriptions","organizations_url":"https://api.github.com/users/ONSdigital/orgs","repos_url":"https://api.github.com/users/ONSdigital/repos","events_url":"https://api.github.com/users/ONSdigital/events{/privacy}","received_events_url":"https://api.github.com/users/ONSdigital/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/ONSdigital/sdx-transform-cs","description":null,"fork":false,"url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs","forks_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/forks","keys_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/teams","hooks_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/hooks","issue_events_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/issues/events{/number}","events_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/events","assignees_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/assignees{/user}","branches_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/branches{/branch}","tags_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/tags","blobs_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/git/refs{/sha}","trees_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/statuses/{sha}","languages_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/languages","stargazers_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/stargazers","contributors_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/contributors","subscribers_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/subscribers","subscription_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/subscription","commits_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/commits{/sha}","git_commits_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/git/commits{/sha}","comments_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/comments{/number}","issue_comment_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/issues/comments{/number}","contents_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/contents/{+path}","compare_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/merges","archive_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/downloads","issues_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/issues{/number}","pulls_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/pulls{/number}","milestones_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/milestones{/number}","notifications_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/labels{/name}","releases_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/releases{/id}","deployments_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/deployments","created_at":"2016-05-26T15:41:26Z","updated_at":"2018-10-04T07:31:38Z","pushed_at":"2018-11-26T11:49:46Z","git_url":"git://github.com/ONSdigital/sdx-transform-cs.git","ssh_url":"git@github.com:ONSdigital/sdx-transform-cs.git","clone_url":"https://github.com/ONSdigital/sdx-transform-cs.git","svn_url":"https://github.com/ONSdigital/sdx-transform-cs","homepage":null,"size":680,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":2,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":2,"watchers":1,"default_branch":"master"}},"base":{"label":"ONSdigital:master","ref":"master","sha":"b54a523eae9a8a14b1ebf249c8ce86fc1612e428","user":{"login":"ONSdigital","id":6865137,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY4NjUxMzc=","avatar_url":"https://avatars0.githubusercontent.com/u/6865137?v=4","gravatar_id":"","url":"https://api.github.com/users/ONSdigital","html_url":"https://github.com/ONSdigital","followers_url":"https://api.github.com/users/ONSdigital/followers","following_url":"https://api.github.com/users/ONSdigital/following{/other_user}","gists_url":"https://api.github.com/users/ONSdigital/gists{/gist_id}","starred_url":"https://api.github.com/users/ONSdigital/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ONSdigital/subscriptions","organizations_url":"https://api.github.com/users/ONSdigital/orgs","repos_url":"https://api.github.com/users/ONSdigital/repos","events_url":"https://api.github.com/users/ONSdigital/events{/privacy}","received_events_url":"https://api.github.com/users/ONSdigital/received_events","type":"Organization","site_admin":false},"repo":{"id":59762598,"node_id":"MDEwOlJlcG9zaXRvcnk1OTc2MjU5OA==","name":"sdx-transform-cs","full_name":"ONSdigital/sdx-transform-cs","private":false,"owner":{"login":"ONSdigital","id":6865137,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY4NjUxMzc=","avatar_url":"https://avatars0.githubusercontent.com/u/6865137?v=4","gravatar_id":"","url":"https://api.github.com/users/ONSdigital","html_url":"https://github.com/ONSdigital","followers_url":"https://api.github.com/users/ONSdigital/followers","following_url":"https://api.github.com/users/ONSdigital/following{/other_user}","gists_url":"https://api.github.com/users/ONSdigital/gists{/gist_id}","starred_url":"https://api.github.com/users/ONSdigital/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ONSdigital/subscriptions","organizations_url":"https://api.github.com/users/ONSdigital/orgs","repos_url":"https://api.github.com/users/ONSdigital/repos","events_url":"https://api.github.com/users/ONSdigital/events{/privacy}","received_events_url":"https://api.github.com/users/ONSdigital/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/ONSdigital/sdx-transform-cs","description":null,"fork":false,"url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs","forks_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/forks","keys_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/teams","hooks_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/hooks","issue_events_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/issues/events{/number}","events_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/events","assignees_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/assignees{/user}","branches_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/branches{/branch}","tags_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/tags","blobs_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/git/refs{/sha}","trees_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/statuses/{sha}","languages_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/languages","stargazers_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/stargazers","contributors_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/contributors","subscribers_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/subscribers","subscription_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/subscription","commits_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/commits{/sha}","git_commits_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/git/commits{/sha}","comments_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/comments{/number}","issue_comment_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/issues/comments{/number}","contents_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/contents/{+path}","compare_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/merges","archive_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/downloads","issues_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/issues{/number}","pulls_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/pulls{/number}","milestones_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/milestones{/number}","notifications_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/labels{/name}","releases_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/releases{/id}","deployments_url":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/deployments","created_at":"2016-05-26T15:41:26Z","updated_at":"2018-10-04T07:31:38Z","pushed_at":"2018-11-26T11:49:46Z","git_url":"git://github.com/ONSdigital/sdx-transform-cs.git","ssh_url":"git@github.com:ONSdigital/sdx-transform-cs.git","clone_url":"https://github.com/ONSdigital/sdx-transform-cs.git","svn_url":"https://github.com/ONSdigital/sdx-transform-cs","homepage":null,"size":680,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":2,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":2,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/pulls/173"},"html":{"href":"https://github.com/ONSdigital/sdx-transform-cs/pull/173"},"issue":{"href":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/issues/173"},"comments":{"href":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/issues/173/comments"},"review_comments":{"href":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/pulls/173/comments"},"review_comment":{"href":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/pulls/173/commits"},"statuses":{"href":"https://api.github.com/repos/ONSdigital/sdx-transform-cs/statuses/410dea601aeb1699152be5e188ccac8bfba6dca0"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"insacuri"}}