{"action":"created","comment":{"url":"https://api.github.com/repos/democracyworks/usps-processor/pulls/comments/72093675","id":72093675,"diff_hunk":"@@ -33,24 +34,117 @@\n   \"Takes the time in the USPS string format, and a timezone id like\n    'America/New_York', and returns a DateTime in UTC for that time.\"\n   [time-string timezone-id]\n-  (let [timezone (timezone-id->timezone timezone-id)\n-        formatter (format/formatter usps-time-format-pattern timezone)\n-        time-in-zone (format/parse formatter time-string)]\n-    (time/to-time-zone time-in-zone time/utc)))\n+  (try\n+    (let [timezone (timezone-id->timezone timezone-id)\n+          formatter (format/formatter usps-time-format-pattern timezone)\n+          time-in-zone (format/parse formatter time-string)]\n+      (time/to-time-zone time-in-zone time/utc))\n+    (catch Exception ex\n+      (log/warn \"Exception parsing scan time\" ex))))\n+\n+(defn datetime->date\n+  \"Converts a datetime to date, or returns nil if datetime is nil\"\n+  [datetime]\n+  (when datetime\n+    (coerce/to-date datetime)))\n+\n+(defn ->imb-data\n+  \"Combines the structure-digits and routing code and\n+   splits them into the possible mailer-ids and\n+   serial numbers\"\n+  [structure-digits routing-code]\n+  (when (and structure-digits\n+             (= 20 (count structure-digits)))\n+    (imb/split-structure-digits\n+     (str structure-digits routing-code))))\n+\n+(defn valid-number?\n+  [count number]\n+  (let [pattern (str \"\\\\d{\" count \"}?\")\n+        regex (re-pattern pattern)]\n+    (not (nil? (re-matches regex number)))))\n+\n+(defn valid-barcode?\n+  [zip]\n+  (valid-number? 2 zip))\n+\n+(defn valid-facility-zip?\n+  [zip]\n+  (valid-number? 5 zip))\n+\n+(defn valid-scan-time?\n+  [scan-time]\n+  (isa? (class scan-time) java.util.Date))\n+\n+(defn valid-customer-number?\n+  [customer-number]\n+  (valid-number? 15 customer-number))\n+\n+(defn valid-number-3?\n+  [number]\n+  (valid-number? 3 number))\n+\n+(defn valid-number-6?\n+  [number]\n+  (valid-number? 6 number))\n+\n+(defn valid-number-9?\n+  [number]\n+  (valid-number? 9 number))\n+\n+(defn valid-routing-number?\n+  [number]\n+  (and (not (nil? number))\n+       (not (nil? (re-matches #\"\\d*?\" number)))\n+       (#{0 5 9 11} (count number))))\n+\n+(def inbound-schema\n+  {:barcode (s/pred valid-barcode?)\n+   :service (s/pred valid-number-3?)\n+   :routing s/Str\n+   :customer-number (s/pred valid-customer-number?)})\n+\n+(def outbound-schema\n+  {:barcode (s/pred valid-barcode?)\n+   :service (s/pred valid-number-3?)\n+   :routing s/Str\n+   :9-digit-mailer\n+   {:mailer-id (s/pred valid-number-9?)\n+    :serial-number (s/pred valid-number-6?)}\n+   :6-digit-mailer\n+   {:mailer-id (s/pred valid-number-6?)\n+    :serial-number (s/pred valid-number-9?)}})","path":"src/usps_processor/parse.clj","position":103,"original_position":103,"commit_id":"291d6efb531da0eb7aa3841b049823c4fd9da204","original_commit_id":"291d6efb531da0eb7aa3841b049823c4fd9da204","user":{"login":"cap10morgan","id":59748,"avatar_url":"https://avatars.githubusercontent.com/u/59748?v=3","gravatar_id":"","url":"https://api.github.com/users/cap10morgan","html_url":"https://github.com/cap10morgan","followers_url":"https://api.github.com/users/cap10morgan/followers","following_url":"https://api.github.com/users/cap10morgan/following{/other_user}","gists_url":"https://api.github.com/users/cap10morgan/gists{/gist_id}","starred_url":"https://api.github.com/users/cap10morgan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cap10morgan/subscriptions","organizations_url":"https://api.github.com/users/cap10morgan/orgs","repos_url":"https://api.github.com/users/cap10morgan/repos","events_url":"https://api.github.com/users/cap10morgan/events{/privacy}","received_events_url":"https://api.github.com/users/cap10morgan/received_events","type":"User","site_admin":false},"body":"Or would it be better to just do something like `(s/pred (partial valid-number? 9) \"9 digit number\")` here and in the other places we're using this to validate number-with-N-digits?","created_at":"2016-07-25T16:10:06Z","updated_at":"2016-07-25T16:10:06Z","html_url":"https://github.com/democracyworks/usps-processor/pull/33#discussion_r72093675","pull_request_url":"https://api.github.com/repos/democracyworks/usps-processor/pulls/33","_links":{"self":{"href":"https://api.github.com/repos/democracyworks/usps-processor/pulls/comments/72093675"},"html":{"href":"https://github.com/democracyworks/usps-processor/pull/33#discussion_r72093675"},"pull_request":{"href":"https://api.github.com/repos/democracyworks/usps-processor/pulls/33"}}},"pull_request":{"url":"https://api.github.com/repos/democracyworks/usps-processor/pulls/33","id":78232509,"html_url":"https://github.com/democracyworks/usps-processor/pull/33","diff_url":"https://github.com/democracyworks/usps-processor/pull/33.diff","patch_url":"https://github.com/democracyworks/usps-processor/pull/33.patch","issue_url":"https://api.github.com/repos/democracyworks/usps-processor/issues/33","number":33,"state":"open","locked":false,"title":"More stable file processing","user":{"login":"tank157","id":4147,"avatar_url":"https://avatars.githubusercontent.com/u/4147?v=3","gravatar_id":"","url":"https://api.github.com/users/tank157","html_url":"https://github.com/tank157","followers_url":"https://api.github.com/users/tank157/followers","following_url":"https://api.github.com/users/tank157/following{/other_user}","gists_url":"https://api.github.com/users/tank157/gists{/gist_id}","starred_url":"https://api.github.com/users/tank157/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tank157/subscriptions","organizations_url":"https://api.github.com/users/tank157/orgs","repos_url":"https://api.github.com/users/tank157/repos","events_url":"https://api.github.com/users/tank157/events{/privacy}","received_events_url":"https://api.github.com/users/tank157/received_events","type":"User","site_admin":false},"body":"[Pivotal Card](https://www.pivotaltracker.com/story/show/121451243)\r\n\r\nAssigning to @cap10morgan \r\n\r\nProblematic lines will be logged, followed by the exception from prismatic when they don't pass validations.\r\n\r\nIf we want to alert on that, we can do it from papertrail (and maybe should intentionally tell it to process a bad file after deployment so we can add the alerts we want)","created_at":"2016-07-20T22:46:42Z","updated_at":"2016-07-25T16:10:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a5baa135f1765df48f6c969f16d12865ed67d4d2","assignee":{"login":"cap10morgan","id":59748,"avatar_url":"https://avatars.githubusercontent.com/u/59748?v=3","gravatar_id":"","url":"https://api.github.com/users/cap10morgan","html_url":"https://github.com/cap10morgan","followers_url":"https://api.github.com/users/cap10morgan/followers","following_url":"https://api.github.com/users/cap10morgan/following{/other_user}","gists_url":"https://api.github.com/users/cap10morgan/gists{/gist_id}","starred_url":"https://api.github.com/users/cap10morgan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cap10morgan/subscriptions","organizations_url":"https://api.github.com/users/cap10morgan/orgs","repos_url":"https://api.github.com/users/cap10morgan/repos","events_url":"https://api.github.com/users/cap10morgan/events{/privacy}","received_events_url":"https://api.github.com/users/cap10morgan/received_events","type":"User","site_admin":false},"assignees":[{"login":"cap10morgan","id":59748,"avatar_url":"https://avatars.githubusercontent.com/u/59748?v=3","gravatar_id":"","url":"https://api.github.com/users/cap10morgan","html_url":"https://github.com/cap10morgan","followers_url":"https://api.github.com/users/cap10morgan/followers","following_url":"https://api.github.com/users/cap10morgan/following{/other_user}","gists_url":"https://api.github.com/users/cap10morgan/gists{/gist_id}","starred_url":"https://api.github.com/users/cap10morgan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cap10morgan/subscriptions","organizations_url":"https://api.github.com/users/cap10morgan/orgs","repos_url":"https://api.github.com/users/cap10morgan/repos","events_url":"https://api.github.com/users/cap10morgan/events{/privacy}","received_events_url":"https://api.github.com/users/cap10morgan/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/democracyworks/usps-processor/pulls/33/commits","review_comments_url":"https://api.github.com/repos/democracyworks/usps-processor/pulls/33/comments","review_comment_url":"https://api.github.com/repos/democracyworks/usps-processor/pulls/comments{/number}","comments_url":"https://api.github.com/repos/democracyworks/usps-processor/issues/33/comments","statuses_url":"https://api.github.com/repos/democracyworks/usps-processor/statuses/291d6efb531da0eb7aa3841b049823c4fd9da204","head":{"label":"democracyworks:more-stable-file-processing","ref":"more-stable-file-processing","sha":"291d6efb531da0eb7aa3841b049823c4fd9da204","user":{"login":"democracyworks","id":1373557,"avatar_url":"https://avatars.githubusercontent.com/u/1373557?v=3","gravatar_id":"","url":"https://api.github.com/users/democracyworks","html_url":"https://github.com/democracyworks","followers_url":"https://api.github.com/users/democracyworks/followers","following_url":"https://api.github.com/users/democracyworks/following{/other_user}","gists_url":"https://api.github.com/users/democracyworks/gists{/gist_id}","starred_url":"https://api.github.com/users/democracyworks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/democracyworks/subscriptions","organizations_url":"https://api.github.com/users/democracyworks/orgs","repos_url":"https://api.github.com/users/democracyworks/repos","events_url":"https://api.github.com/users/democracyworks/events{/privacy}","received_events_url":"https://api.github.com/users/democracyworks/received_events","type":"Organization","site_admin":false},"repo":{"id":17921554,"name":"usps-processor","full_name":"democracyworks/usps-processor","owner":{"login":"democracyworks","id":1373557,"avatar_url":"https://avatars.githubusercontent.com/u/1373557?v=3","gravatar_id":"","url":"https://api.github.com/users/democracyworks","html_url":"https://github.com/democracyworks","followers_url":"https://api.github.com/users/democracyworks/followers","following_url":"https://api.github.com/users/democracyworks/following{/other_user}","gists_url":"https://api.github.com/users/democracyworks/gists{/gist_id}","starred_url":"https://api.github.com/users/democracyworks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/democracyworks/subscriptions","organizations_url":"https://api.github.com/users/democracyworks/orgs","repos_url":"https://api.github.com/users/democracyworks/repos","events_url":"https://api.github.com/users/democracyworks/events{/privacy}","received_events_url":"https://api.github.com/users/democracyworks/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/democracyworks/usps-processor","description":"USPS IMb record processor","fork":false,"url":"https://api.github.com/repos/democracyworks/usps-processor","forks_url":"https://api.github.com/repos/democracyworks/usps-processor/forks","keys_url":"https://api.github.com/repos/democracyworks/usps-processor/keys{/key_id}","collaborators_url":"https://api.github.com/repos/democracyworks/usps-processor/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/democracyworks/usps-processor/teams","hooks_url":"https://api.github.com/repos/democracyworks/usps-processor/hooks","issue_events_url":"https://api.github.com/repos/democracyworks/usps-processor/issues/events{/number}","events_url":"https://api.github.com/repos/democracyworks/usps-processor/events","assignees_url":"https://api.github.com/repos/democracyworks/usps-processor/assignees{/user}","branches_url":"https://api.github.com/repos/democracyworks/usps-processor/branches{/branch}","tags_url":"https://api.github.com/repos/democracyworks/usps-processor/tags","blobs_url":"https://api.github.com/repos/democracyworks/usps-processor/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/democracyworks/usps-processor/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/democracyworks/usps-processor/git/refs{/sha}","trees_url":"https://api.github.com/repos/democracyworks/usps-processor/git/trees{/sha}","statuses_url":"https://api.github.com/repos/democracyworks/usps-processor/statuses/{sha}","languages_url":"https://api.github.com/repos/democracyworks/usps-processor/languages","stargazers_url":"https://api.github.com/repos/democracyworks/usps-processor/stargazers","contributors_url":"https://api.github.com/repos/democracyworks/usps-processor/contributors","subscribers_url":"https://api.github.com/repos/democracyworks/usps-processor/subscribers","subscription_url":"https://api.github.com/repos/democracyworks/usps-processor/subscription","commits_url":"https://api.github.com/repos/democracyworks/usps-processor/commits{/sha}","git_commits_url":"https://api.github.com/repos/democracyworks/usps-processor/git/commits{/sha}","comments_url":"https://api.github.com/repos/democracyworks/usps-processor/comments{/number}","issue_comment_url":"https://api.github.com/repos/democracyworks/usps-processor/issues/comments{/number}","contents_url":"https://api.github.com/repos/democracyworks/usps-processor/contents/{+path}","compare_url":"https://api.github.com/repos/democracyworks/usps-processor/compare/{base}...{head}","merges_url":"https://api.github.com/repos/democracyworks/usps-processor/merges","archive_url":"https://api.github.com/repos/democracyworks/usps-processor/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/democracyworks/usps-processor/downloads","issues_url":"https://api.github.com/repos/democracyworks/usps-processor/issues{/number}","pulls_url":"https://api.github.com/repos/democracyworks/usps-processor/pulls{/number}","milestones_url":"https://api.github.com/repos/democracyworks/usps-processor/milestones{/number}","notifications_url":"https://api.github.com/repos/democracyworks/usps-processor/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/democracyworks/usps-processor/labels{/name}","releases_url":"https://api.github.com/repos/democracyworks/usps-processor/releases{/id}","deployments_url":"https://api.github.com/repos/democracyworks/usps-processor/deployments","created_at":"2014-03-19T21:46:01Z","updated_at":"2016-02-18T20:27:20Z","pushed_at":"2016-07-20T22:46:42Z","git_url":"git://github.com/democracyworks/usps-processor.git","ssh_url":"git@github.com:democracyworks/usps-processor.git","clone_url":"https://github.com/democracyworks/usps-processor.git","svn_url":"https://github.com/democracyworks/usps-processor","homepage":null,"size":999,"stargazers_count":2,"watchers_count":2,"language":"Clojure","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":2,"default_branch":"master"}},"base":{"label":"democracyworks:master","ref":"master","sha":"6cd8e701c95b7bf93ccb3ef78603d98b53cdefd3","user":{"login":"democracyworks","id":1373557,"avatar_url":"https://avatars.githubusercontent.com/u/1373557?v=3","gravatar_id":"","url":"https://api.github.com/users/democracyworks","html_url":"https://github.com/democracyworks","followers_url":"https://api.github.com/users/democracyworks/followers","following_url":"https://api.github.com/users/democracyworks/following{/other_user}","gists_url":"https://api.github.com/users/democracyworks/gists{/gist_id}","starred_url":"https://api.github.com/users/democracyworks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/democracyworks/subscriptions","organizations_url":"https://api.github.com/users/democracyworks/orgs","repos_url":"https://api.github.com/users/democracyworks/repos","events_url":"https://api.github.com/users/democracyworks/events{/privacy}","received_events_url":"https://api.github.com/users/democracyworks/received_events","type":"Organization","site_admin":false},"repo":{"id":17921554,"name":"usps-processor","full_name":"democracyworks/usps-processor","owner":{"login":"democracyworks","id":1373557,"avatar_url":"https://avatars.githubusercontent.com/u/1373557?v=3","gravatar_id":"","url":"https://api.github.com/users/democracyworks","html_url":"https://github.com/democracyworks","followers_url":"https://api.github.com/users/democracyworks/followers","following_url":"https://api.github.com/users/democracyworks/following{/other_user}","gists_url":"https://api.github.com/users/democracyworks/gists{/gist_id}","starred_url":"https://api.github.com/users/democracyworks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/democracyworks/subscriptions","organizations_url":"https://api.github.com/users/democracyworks/orgs","repos_url":"https://api.github.com/users/democracyworks/repos","events_url":"https://api.github.com/users/democracyworks/events{/privacy}","received_events_url":"https://api.github.com/users/democracyworks/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/democracyworks/usps-processor","description":"USPS IMb record processor","fork":false,"url":"https://api.github.com/repos/democracyworks/usps-processor","forks_url":"https://api.github.com/repos/democracyworks/usps-processor/forks","keys_url":"https://api.github.com/repos/democracyworks/usps-processor/keys{/key_id}","collaborators_url":"https://api.github.com/repos/democracyworks/usps-processor/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/democracyworks/usps-processor/teams","hooks_url":"https://api.github.com/repos/democracyworks/usps-processor/hooks","issue_events_url":"https://api.github.com/repos/democracyworks/usps-processor/issues/events{/number}","events_url":"https://api.github.com/repos/democracyworks/usps-processor/events","assignees_url":"https://api.github.com/repos/democracyworks/usps-processor/assignees{/user}","branches_url":"https://api.github.com/repos/democracyworks/usps-processor/branches{/branch}","tags_url":"https://api.github.com/repos/democracyworks/usps-processor/tags","blobs_url":"https://api.github.com/repos/democracyworks/usps-processor/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/democracyworks/usps-processor/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/democracyworks/usps-processor/git/refs{/sha}","trees_url":"https://api.github.com/repos/democracyworks/usps-processor/git/trees{/sha}","statuses_url":"https://api.github.com/repos/democracyworks/usps-processor/statuses/{sha}","languages_url":"https://api.github.com/repos/democracyworks/usps-processor/languages","stargazers_url":"https://api.github.com/repos/democracyworks/usps-processor/stargazers","contributors_url":"https://api.github.com/repos/democracyworks/usps-processor/contributors","subscribers_url":"https://api.github.com/repos/democracyworks/usps-processor/subscribers","subscription_url":"https://api.github.com/repos/democracyworks/usps-processor/subscription","commits_url":"https://api.github.com/repos/democracyworks/usps-processor/commits{/sha}","git_commits_url":"https://api.github.com/repos/democracyworks/usps-processor/git/commits{/sha}","comments_url":"https://api.github.com/repos/democracyworks/usps-processor/comments{/number}","issue_comment_url":"https://api.github.com/repos/democracyworks/usps-processor/issues/comments{/number}","contents_url":"https://api.github.com/repos/democracyworks/usps-processor/contents/{+path}","compare_url":"https://api.github.com/repos/democracyworks/usps-processor/compare/{base}...{head}","merges_url":"https://api.github.com/repos/democracyworks/usps-processor/merges","archive_url":"https://api.github.com/repos/democracyworks/usps-processor/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/democracyworks/usps-processor/downloads","issues_url":"https://api.github.com/repos/democracyworks/usps-processor/issues{/number}","pulls_url":"https://api.github.com/repos/democracyworks/usps-processor/pulls{/number}","milestones_url":"https://api.github.com/repos/democracyworks/usps-processor/milestones{/number}","notifications_url":"https://api.github.com/repos/democracyworks/usps-processor/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/democracyworks/usps-processor/labels{/name}","releases_url":"https://api.github.com/repos/democracyworks/usps-processor/releases{/id}","deployments_url":"https://api.github.com/repos/democracyworks/usps-processor/deployments","created_at":"2014-03-19T21:46:01Z","updated_at":"2016-02-18T20:27:20Z","pushed_at":"2016-07-20T22:46:42Z","git_url":"git://github.com/democracyworks/usps-processor.git","ssh_url":"git@github.com:democracyworks/usps-processor.git","clone_url":"https://github.com/democracyworks/usps-processor.git","svn_url":"https://github.com/democracyworks/usps-processor","homepage":null,"size":999,"stargazers_count":2,"watchers_count":2,"language":"Clojure","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/democracyworks/usps-processor/pulls/33"},"html":{"href":"https://github.com/democracyworks/usps-processor/pull/33"},"issue":{"href":"https://api.github.com/repos/democracyworks/usps-processor/issues/33"},"comments":{"href":"https://api.github.com/repos/democracyworks/usps-processor/issues/33/comments"},"review_comments":{"href":"https://api.github.com/repos/democracyworks/usps-processor/pulls/33/comments"},"review_comment":{"href":"https://api.github.com/repos/democracyworks/usps-processor/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/democracyworks/usps-processor/pulls/33/commits"},"statuses":{"href":"https://api.github.com/repos/democracyworks/usps-processor/statuses/291d6efb531da0eb7aa3841b049823c4fd9da204"}}}}
{"actor":{"display_login":"cap10morgan"}}