Created
May 13, 2014 11:55
-
-
Save rc1/99cc54929808c987f603 to your computer and use it in GitHub Desktop.
Dave's challenge
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
| (ns sorter.core | |
| (:require [clojure.java.io :refer :all] | |
| [clojure.string :as string] | |
| [clojure.pprint :as pprint])) | |
| (def faces-by-img | |
| "This is a vector containing each image with a nested vector of faces found in the image" | |
| (reduce | |
| (fn [acc [[img] data]] | |
| (merge acc { :img img :faces (reduce | |
| (fn [acc [lx ly rx ry age gender]] (merge acc { :left-eye [lx ly] :right-eye [rx ry] :age age :gender gender })) | |
| [] | |
| (partition 6 data))})) | |
| [] | |
| (partition 2 | |
| (partition-by | |
| ;; if it only contains numbers, it is not an image | |
| #(if (re-matches #".*jpg" %) % nil) | |
| (flatten (-> | |
| ;; Load the file | |
| (slurp "/Users/ross/Dropbox/Dropbox/SketchBook/20140400_learning_clojure/04 Daves Challenge/sorter/PersonData_short.txt") | |
| ;; Get a vector splitting it by white space | |
| (clojure.string/split #"\s+"))))))) | |
| ;; (clojure.pprint/pprint | |
| ;; faces-by-img) | |
| (def faces | |
| "All the faces with the reference images" | |
| (flatten | |
| (reduce | |
| (fn [acc img] | |
| (merge acc (map (fn [f] (conj f {:img (:img img)})) (:faces img)))) | |
| [] | |
| faces-by-img))) | |
| (def faces-by-age-group | |
| "Grouped by age" | |
| (group-by #(:age %) faces)) | |
| (clojure.pprint/pprint | |
| age-group) | |
| (def faces-by-gender | |
| "Grouped by gender" | |
| (group-by #(:gender %) faces)) | |
| (clojure.pprint/pprint | |
| faces-by-gender) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment