Last active
March 24, 2016 23:08
-
-
Save raymcdermott/3a11d76fcd286fd889d6 to your computer and use it in GitHub Desktop.
Obtain diff between source data and golden view
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def api-data {:source-data {:fname "Ray", :last "McDermott", :e-mail "[email protected]"}, | |
:golden-view {:first "Ray", :last "McDermott", :email "[email protected]", :dob "29/04/2004"}, | |
:mapping {:email :e-mail, :first :fname, :last :last}}) | |
;=> #'user/api-data | |
(defn source-golden-diff [source-data golden-view source-map] | |
(let [common-keys (let [keys (clojure.set/intersection (set (keys golden-view)) | |
(set (keys source-data)))] | |
(into {} (map #(vec [% %]) keys))) | |
all-keys (merge common-keys source-map) | |
diffs (let [golden-view-of-source (into {} (map #(assoc {} (first %) (get source-data (last %))) all-keys))] | |
(into {} (clojure.set/difference (set golden-view-of-source) (set golden-view))))] | |
(into [] (map (fn [diff-key] (let [src-key (get all-keys diff-key) | |
new-src-value (get golden-view diff-key) | |
old-src-value (get source-data src-key)] | |
{:new [src-key new-src-value] | |
:old [src-key old-src-value] | |
:golden [diff-key new-src-value]})) (keys diffs))))) | |
;=> #'user/source-golden-diff | |
(source-golden-diff (:source-data api-data) (:golden-view api-data) (:mapping api-data)) | |
;=> {:new [:e-mail "[email protected]"], :old [:e-mail "[email protected]"], :golden [:email "[email protected]"]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The mapping is the non-matching elements that map between the source and golden view.
In this case the source system does not hold DOB. The :last field is common.
Small fix to use all-keys in the final form.