Skip to content

Commit 2a6d52a

Browse files
committed
Start work on integrating bluepylons data
1 parent f545788 commit 2a6d52a

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

Diff for: .gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "resources/theremingoat"]
22
path = resources/theremingoat
33
url = https://github.com/ThereminGoat/force-curves
4+
[submodule "resources/bluepylons"]
5+
path = resources/bluepylons
6+
url = https://github.com/bluepylons/Open-Switch-Curve-Meter.git

Diff for: deps.edn

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
org.clojure/clojurescript {:mvn/version "1.10.520"}
44
cjohansen/dumdom {:mvn/version "2022.09.28"}
55
com.bhauman/figwheel-main {:mvn/version "0.2.18"}
6-
cjohansen/gadget-inspector {:mvn/version "0.2020.09.10"}}
6+
cjohansen/gadget-inspector {:mvn/version "0.2020.09.10"}
7+
babashka/fs {:mvn/version "0.3.17"}
8+
org.clojure/data.csv {:mvn/version "1.0.1"}
9+
com.github.miachm.sods/SODS {:mvn/version "1.5.2"}}
710
:aliases {:serve {:deps {org.babashka/http-server {:mvn/version "0.1.11"}}
811
:main-opts ["-m" "babashka.http-server"]
912
:exec-fn babashka.http-server/exec}}}

Diff for: resources/bluepylons

Submodule bluepylons added at 5ac04b4

Diff for: src/switchesdb/parser/bluepylons.clj

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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

Comments
 (0)