Last active
August 29, 2015 14:01
-
-
Save yayitswei/57d30195e798c371975f to your computer and use it in GitHub Desktop.
scanview data parser
This file contains 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 scanview.core | |
(:require [clojure.string :as string] | |
[clojure.data.csv :as csv] | |
[clojure.pprint :refer [pprint]] | |
[clojure.java.io :as io])) | |
(def regex #"[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?") | |
(defn trim-line? [s] | |
(when-let [extra-alpha-chars (re-seq #"[A-DF-df-z]" s)] | |
(> (count extra-alpha-chars) 1))) | |
(defn parse-line [s] | |
(when-not (trim-line? s) (ffirst (re-seq regex s)))) | |
(defn split-lines [filename] | |
(string/split (slurp filename) #"\n")) | |
(defn parse-file [filename] | |
(->> filename | |
split-lines | |
(map parse-line) | |
(remove nil?) | |
(partition 9))) | |
(defn write-csv [parsed-data filename] | |
(with-open [out-file (io/writer filename)] | |
(csv/write-csv out-file parsed-data))) | |
(defn run! [files base base-out] | |
(doseq [file files] | |
(-> (str base file) | |
parse-file | |
(write-csv (str base-out file ".csv"))))) | |
(comment (run! ["Ro_T_1.dvw" | |
"Ro_T_2.2.dvw" | |
"Ro_T_2.dvw" | |
"mtr5_L_1.dvw" | |
"mtr5_L_2.2.dvw" | |
"mtr5_T_1.dvw" | |
"mtr5_T_2.2.dvw" | |
"mtr5_T_2.dvw" | |
"ro_L_1.dvw" | |
"ro_L_2.2.dvw" | |
"ro_L_2.dvw"] | |
"/tmp/drw/" | |
"/tmp/converted/")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment