Skip to content

Instantly share code, notes, and snippets.

@robinkraft
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robinkraft/9800089 to your computer and use it in GitHub Desktop.
Save robinkraft/9800089 to your computer and use it in GitHub Desktop.
(defn sum-xyz
[]
(<- [?x ?y ?z ?period ?count :> ?x2i ?y2i ?z-new ?sum]
(/ ?x 2 :> ?x2)
(/ ?y 2 :> ?y2)
(math/floor ?x2 :> ?x2i)
(math/floor ?y2 :> ?y2i)
(dec ?z :> ?z-new)
(c/sum ?count :> ?sum)))
(defbufferop sort-by-date
[tuples]
(let [sorted (sort-by first tuples)]
[[[(vec (map first sorted)) (vec (map second sorted))]]]))
(defn split-vec
[v]
[(first v) (second v)])
(defn vec->arr-str
"Format vector as string array format for PostgreSQL."
[v]
(-> (str v)
(clojure.string/replace "[" "{")
(clojure.string/replace "]" "}")
(clojure.string/replace " " ",")))
(defn arr-str->vec
"Convert PostgreSQL array string to vector. Reverses `array-ify`."
[s]
(-> s
(clojure.string/replace "{" "[")
(clojure.string/replace "}" "]")
(clojure.string/replace "," " ")
(read-string)))
(defn summed-up
[src summer-op]
(<- [?x2i ?y2i ?z-new ?period ?sum]
(src ?x ?y ?z ?period ?count)
(summer-op ?x ?y ?z ?period ?count :> ?x2i ?y2i ?z-new ?sum)))
(defn final-op
[src]
(<- [?x ?y ?z ?periods ?counts]
(src ?x ?y ?z ?period ?count)
(sort-by-date ?period ?count :> ?periods-counts)
(split-vec ?periods-counts :> ?periods ?counts)))
(let [src [[6258 9088N 14 71 1]
[6258 9088N 14 72 2]]]
(final-op src))
(let [src [[25032 36353 16 71 1]
[25032 36353 16 72 1]
[25032 36352N 16 72 1]]
summer (sum-xyz)
zoom-src (summed-up src summer)]
(summed-up summed-src summer))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment