loganpowell / census-geojson

Census cartography files available in GeoJSON format (various geographies and vintages from 1990 - 2019)
82 stars 18 forks source link

Before loop/merging the list of `?geos`, put the first element in the last position #12

Closed loganpowell closed 5 years ago

loganpowell commented 6 years ago

https://github.com/loganpowell/census-geojson/blob/augmentation/src/discovery/core.cljs#L29

(defn digest-one-index
  [url-str]
  (let [todo                   (s/strip-prefix url-str "https://api.census.gov/data/")
        [pI pII]               (s/split todo #"\?get=")
        [vintage & sourcePath] (s/split pI #"/")
        [pIII & pIV]           (s/split pII #"&")
-       [& values]             (s/split pIII #",")
+       values                 (s/split pIII #",")
        [& ?geos]              (map #(s/split % #"=") pIV)]
    (loop [args {:vintage      (s/parse-number vintage)
-                :values       (vec values)
+                :values       values
                 :sourcePath   (vec sourcePath)}
-          geos ?geos]
+          geos (conj (vec (rest ?geos)) (vec (first ?geos)))]
      (if (empty? geos)
          args
          (let [[i ii] (first geos)
                [k val-]  (s/split ii #":")
                key-   (keyword (ut/strs->keys k))] ; convert strings to edn keys
            (if (or (= "in" i) (= "for" i))
                (recur (merge-with into args {:geoHierarchy {key- val-}}) (rest geos))
                (recur (merge-with into args {:predicates {(keyword i) ii}}) (rest geos))))))))