|
| 1 | +(ns switchesdb.parser.bluepylons |
| 2 | + (:require [clojure.string :as str] |
| 3 | + [babashka.fs :as fs]) |
| 4 | + (:import [com.github.miachm.sods SpreadSheet NotAnOdsException])) |
| 5 | + |
| 6 | +(defn reader-fn |
| 7 | + "Where `head` is a vector of cells F1 and G1, return the suitable function." |
| 8 | + [head] |
| 9 | + (cond |
| 10 | + (str/includes? (str/lower-case (first head)) "corrected downstroke") |
| 11 | + 'read-type-1 |
| 12 | + (= (first head) "Corrected downstroke X (mm)") |
| 13 | + 'read-type-2 |
| 14 | + (= (second head) "Corrected Upstroke") |
| 15 | + 'read-type-3)) |
| 16 | + |
| 17 | +(defn read-ods [ods-file] |
| 18 | + (try |
| 19 | + (-> ods-file fs/file SpreadSheet. .getSheets (nth 0) (.getRange 0 5 1 6) .getValues) |
| 20 | + (catch NotAnOdsException _ |
| 21 | + (println (str "Failed to read ODS file: " ods-file))))) |
| 22 | + |
| 23 | +(comment |
| 24 | + (fs/glob "resources/bluepylons/Force curve measurements" "{,Kailh Choc Switches/}*.ods") |
| 25 | + |
| 26 | + ;; There are 15 different arrangements the spreadsheets can be found in. |
| 27 | + (letfn [(read-ods-head [ods-file] |
| 28 | + (try (-> ods-file fs/file SpreadSheet. .getSheets (nth 0) (.getRange 0 5 1 2) .getValues) |
| 29 | + (catch NotAnOdsException _)))] |
| 30 | + (frequencies |
| 31 | + (map #(vec (map vec %)) |
| 32 | + (map read-ods-head |
| 33 | + (fs/glob "resources/bluepylons/Force curve measurements" "{,Kailh Choc Switches/}*.ods") |
| 34 | + #_(fs/glob "resources/bluepylons/Force curve measurements" "*.ods") |
| 35 | + #_(fs/glob "resources/bluepylons/Force curve measurements" "{,Kailh Choc Switches/,Springs/}*.ods"))))) |
| 36 | + ;; The most common ones are: |
| 37 | + [["Corrected Downstroke" nil "Corrected Upstroke"]] |
| 38 | + ;; 150 times (labels may include extra text) |
| 39 | + [["Corrected downstroke X (mm)" |
| 40 | + "Corrected downstroke force (gf)" |
| 41 | + "Corrected downstroke actuated?" |
| 42 | + "Corrected upstroke X (mm)" |
| 43 | + "Corrected upstroke force (gf)" |
| 44 | + "Corrected upstroke actuated?"]] |
| 45 | + ;; 117 times |
| 46 | + [[nil "Corrected Upstroke"]] |
| 47 | + ;; 39 times (similar to first but offset by 1 column) |
| 48 | + |
| 49 | + ;; The remaining arrangements total 7, each one having its own unique arrangement. |
| 50 | + ;; Only the 3 most common arrangements shown above will be handled. |
| 51 | + |
| 52 | + :end) |
0 commit comments