This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-05-28
Channels
- # announcements (11)
- # aws (30)
- # beginners (98)
- # calva (11)
- # cider (42)
- # clj-kondo (4)
- # cljdoc (1)
- # cljsrn (5)
- # clojure (132)
- # clojure-europe (4)
- # clojure-ireland (1)
- # clojure-italy (35)
- # clojure-japan (2)
- # clojure-nl (5)
- # clojure-spec (5)
- # clojure-uk (24)
- # clojurescript (71)
- # clojutre (1)
- # core-async (6)
- # cursive (9)
- # data-science (4)
- # datascript (3)
- # datomic (78)
- # duct (16)
- # emacs (14)
- # events (2)
- # fulcro (141)
- # graalvm (5)
- # hoplon (14)
- # hyperfiddle (2)
- # jobs-discuss (14)
- # joker (8)
- # luminus (2)
- # off-topic (7)
- # om (1)
- # pathom (4)
- # pedestal (7)
- # planck (2)
- # quil (1)
- # re-frame (14)
- # reagent (2)
- # reitit (14)
- # robots (1)
- # shadow-cljs (20)
- # spacemacs (25)
- # specter (1)
- # sql (122)
- # tools-deps (63)
- # unrepl (2)
- # yada (34)
grazie @reborg, vabbeh ho risolto mettendo in src/cljc alla fine per adesso
un po' di altre menate con i paths in docker ma ora va tutto, era cmq una soluzione temporanea visto che dovro' prenderli da S3 invece (con una cache magari)
Quesito della sera: ho una struttura come la seguente
[{:a 1 :b 1 :c 10} {:a 2 :b 1 :c 5} {:a 1 :b 1 :c 20}]
e voglio sommare e deduplicare i record con :a
e :b
uguali
ottenendo [{:a 1 :b 1 :c 30} {:a 2 :b 1 :c 5}]
user=> (vals (clojure.set/index d #{:a :b}))
(#{{:a 1, :b 1, :c 20} {:a 1, :b 1, :c 10}} #{{:a 2, :b 1, :c 5}})
dovrebbe darti un buono spunto :)Attualmente abbiamo fatto:
(-> (reduce
(fn [acc elem]
(let [k (select-keys elem [:a :b])
v (:c elem)
r (get acc k)]
(if r
(update-in acc [k :c] + v)
(assoc acc k elem))))
{}
ms)
vals)
(Scusate la formattazione)
Cioè, raggruppo per chiavi in una mappa e l'aggiorno... ma mi sembra un po' contorto
domanda, come faccio a “consumare” una reduce che prende una lazy seq?
che do
devo usare?
hmm mi sa che devo semplicemente usare do
😄
@reborg questa schifezza qua:
(defn insert-data
"multi inserts data and returns number of inserted rows"
[data]
(do
(reduce +
(for [d (partition-all config/multi-inserts-number data)]
(:updated (insert-rows d))))))
se non metto do
il programma si “blocca”
data è una lazy-seq
qua è dove mi arriva data
:
(def handle-data
"handles data sent by an async channel"
(async/go-loop []
;; get the data from the channel and the db
(let [channel-data (async/<!! config/chan)
data (set (:data channel-data))
bar (:progress-bar channel-data)
count-data (count (:data channel-data))
db-persons (set (select-persons data))
;; splitting it between to insert and to update data
to-insert-data (clj.set/difference data db-persons)
to-update-data (clj.set/intersection data db-persons)]
(do
;; keeping in memory how much data we handled
(swap! handled-data + count-data)
(swap! to-insert clj.set/union to-insert-data)
(swap! to-update clj.set/union to-update-data)
;; printing the progress bar
(pr/print (pr/tick bar @handled-data))
))
(recur))
)
e qui mando data
:
(defn run []
(let [xml-list (load-xml)
xml-list-partitioned (partition-all 100 xml-list)
xml-count (count xml-list)
progress-bar (pr/progress-bar xml-count)]
(swap! db/total-rows + xml-count)
(println "start processing" xml-count "xml members...")
(doseq [data xml-list-partitioned]
(async/>!! config/chan {:data data :progress-bar progress-bar}))))
(defn load-xml []
(println "loading xml")
(with-open [r (io/reader config/file-update-xml)]
(xml/parse-xml (first (line-seq r)))))
neanch’io 😄 ¯\(ツ)/¯
cmq si può considerare async come single threaded oppure no? perchè a quanto ho capito go
spawna un processo quindi non è come fare async su nodejs giusto?
perchè mi sono dimenticato di pastare questo:
(def finish-processing
(async/go-loop []
(println @handled-data " " @total-rows)
(when (and (not= @handled-data 0) (= @handled-data @total-rows))
(let [num-to-insert (count @to-insert)
num-to-update (count @to-update)
num-inserted (insert-data @to-insert)
num-updated (update-data @to-update)]
(println "finished processing")
;;(println "total lines db:" num-rows)
(println "to insert:" num-to-insert)
(println "inserted:" num-inserted)
(println "to update:" num-to-update)
(println "updated:" num-updated)
(println "total new rows:" (count-rows))
(close-connection)))
(recur)))
dunque, finish-processing esegue ad evaluation time, che normalmente e’ un no-no. Sei sicuro che non debba essere connesso ad un main?
hmm cosa intendi per no-no?
io pensavo che così “partisse subito” no?
e dato che il canale è vuoto ad evaluation time quello si blocca e rimane in ascolto fino a quando qualcosa viene messo nel canale
almeno questo è quello che penso io 🙂
hmm sembra funzionare invece, c’era il db un po’ impaltanato
vabbè intanto vado a letto
grazie cmq @reborg 🙂