get-local-data now working
This commit is contained in:
parent
6b44b70330
commit
d4f0f4aa5c
|
@ -1,13 +1,14 @@
|
||||||
(ns ^{:doc "Routes which handle data transfer to/from the canvasser app."
|
(ns ^{:doc "Routes which handle data transfer to/from the canvasser app."
|
||||||
:author "Simon Brooke"} youyesyet.routes.rest
|
:author "Simon Brooke"} youyesyet.routes.rest
|
||||||
(:require [clojure.walk :refer [keywordize-keys]]
|
(:require [clojure.core.memoize :as memo]
|
||||||
|
[clojure.java.io :as io]
|
||||||
|
[clojure.walk :refer [keywordize-keys]]
|
||||||
|
[compojure.core :refer [defroutes GET POST]]
|
||||||
[noir.response :as nresponse]
|
[noir.response :as nresponse]
|
||||||
[noir.util.route :as route]
|
[noir.util.route :as route]
|
||||||
[youyesyet.db.core :as db]
|
|
||||||
[compojure.core :refer [defroutes GET POST]]
|
|
||||||
[ring.util.http-response :as response]
|
[ring.util.http-response :as response]
|
||||||
[clojure.java.io :as io]
|
|
||||||
[youyesyet.locality :as l]
|
[youyesyet.locality :as l]
|
||||||
|
[youyesyet.db.core :as db]
|
||||||
[youyesyet.utils :refer :all]
|
[youyesyet.utils :refer :all]
|
||||||
))
|
))
|
||||||
|
|
||||||
|
@ -35,23 +36,50 @@
|
||||||
;;;;
|
;;;;
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
|
||||||
|
(def in-get-local-data
|
||||||
|
"Local data is volatile, because hopefully canvassers are updating it as they
|
||||||
|
work. So cache for only 90 seconds."
|
||||||
|
(memo/ttl
|
||||||
|
(fn [here]
|
||||||
|
(let [neighbourhood (l/neighbouring-localities here)
|
||||||
|
addresses (flatten
|
||||||
|
(map
|
||||||
|
#(db/list-addresses-by-locality db/*db* {:locality %})
|
||||||
|
neighbourhood))]
|
||||||
|
(map
|
||||||
|
(fn [a]
|
||||||
|
(assoc a
|
||||||
|
:dwellings
|
||||||
|
(map
|
||||||
|
(fn [d]
|
||||||
|
(assoc d
|
||||||
|
:electors
|
||||||
|
(map
|
||||||
|
(fn [e]
|
||||||
|
(assoc e
|
||||||
|
:intentions
|
||||||
|
(db/list-intentions-by-elector db/*db* {:id (:id e)})))
|
||||||
|
(db/list-electors-by-dwelling db/*db* {:id (:id d)}))))
|
||||||
|
(db/list-dwellings-by-address db/*db* {:id (:id a)}))))
|
||||||
|
addresses)))
|
||||||
|
:ttl/threshold
|
||||||
|
90000))
|
||||||
|
|
||||||
|
|
||||||
(defn get-local-data
|
(defn get-local-data
|
||||||
"Get data local to the user of the canvasser app. Expects arguments `lat` and
|
"Get data local to the user of the canvasser app. Expects arguments `latitude` and
|
||||||
`long`. Returns a block of data for that locality"
|
`longitude`, or `locality`. Returns a block of data for that locality"
|
||||||
[request]
|
[request]
|
||||||
(let
|
(let
|
||||||
[{latitude :latitude longitude :longitude} (keywordize-keys (:params request))
|
[{latitude :latitude longitude :longitude locality :locality}
|
||||||
neighbourhood (l/neighbouring-localities
|
(keywordize-keys (:params request))
|
||||||
(l/locality
|
here (if locality
|
||||||
|
(coerce-to-number locality)
|
||||||
|
(l/locality
|
||||||
(coerce-to-number latitude)
|
(coerce-to-number latitude)
|
||||||
(coerce-to-number longitude)))
|
(coerce-to-number longitude)))]
|
||||||
addresses (flatten
|
(in-get-local-data here)))
|
||||||
(map
|
|
||||||
#(db/list-addresses-by-locality db/*db* {:locality %})
|
|
||||||
neighbourhood))]
|
|
||||||
|
|
||||||
addresses
|
|
||||||
))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -272,6 +272,9 @@
|
||||||
<property name="current" type="boolean" default="true">
|
<property name="current" type="boolean" default="true">
|
||||||
<prompt prompt="Is current?" locale="en-GB"/>
|
<prompt prompt="Is current?" locale="en-GB"/>
|
||||||
</property>
|
</property>
|
||||||
|
<property type="text" name="brief">
|
||||||
|
<prompt prompt="Brief response to issue" locale="en-GB"/>
|
||||||
|
</property>
|
||||||
<list name="Issues" properties="all"/>
|
<list name="Issues" properties="all"/>
|
||||||
<form name="Issue" properties="all"/>
|
<form name="Issue" properties="all"/>
|
||||||
<permission group="canvassers" permission="read"/>
|
<permission group="canvassers" permission="read"/>
|
||||||
|
|
Loading…
Reference in a new issue