Skip to content

Commit ba5f1f9

Browse files
author
Bastien Guerry
committed
src/codegouvfr-output-data.clj: Update annuaire_sup.json
1 parent 35bd384 commit ba5f1f9

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/codegouvfr-output-data.clj

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,12 @@
287287
(doseq [b (filter #(= (:type_hierarchie %) "Service Fils") (:hierarchie s_data))]
288288
(swap! annuaire update-in [(:service b)]
289289
conj
290-
{:service_sup_id s_id
291-
:service_sup_nom (get-name-from-annuaire-id s_id)}))))
290+
{:service_sup {:id s_id :nom (get-name-from-annuaire-id s_id)}}))))
292291

293292
(defn- get-ancestor [service_sup_id]
294293
(let [seen (atom #{})]
295294
(loop [s_id service_sup_id]
296-
(let [sup (:service_sup_id (get @annuaire s_id))]
295+
(let [sup (:id (:service_sup (get @annuaire s_id)))]
297296
(if (or (nil? sup)
298297
(contains? @seen s_id)
299298
(some #{s_id} @annuaire_tops))
@@ -302,22 +301,18 @@
302301
(recur sup)))))))
303302

304303
(defn- add-service-top! []
305-
(doseq [[s_id s_data] (filter #(seq (:service_sup_id (val %))) @annuaire)]
306-
(let [ancestor (get-ancestor (:service_sup_id s_data))]
307-
(swap! annuaire
308-
update-in
309-
[s_id]
304+
(doseq [[s_id s_data] (filter #(seq (:id (:service_sup (val %)))) @annuaire)]
305+
(let [ancestor (get-ancestor (:id (:service_sup s_data)))]
306+
(swap! annuaire update-in [s_id]
310307
conj
311-
{:service_top_id ancestor
312-
:service_top_nom (get-name-from-annuaire-id ancestor)}))))
308+
{:service_top {:id ancestor :nom (get-name-from-annuaire-id ancestor)}}))))
313309

314310
(defn- set-annuaire! []
315311
;; First download annuaire.json
316312
(fetch-annuaire-zip)
317-
;; Then set the @annuaire atom with a subset of annuaire.json
318313
(->> (json/parse-string (slurp "annuaire.json") true)
319314
:service
320-
(map (fn [a] [(:id a) (select-keys a [:hierarchie :nom :sigle])]))
315+
(map (fn [a] [(:id a) a]))
321316
(into {})
322317
(reset! annuaire))
323318
;; Then set annuaire tops
@@ -363,7 +358,7 @@
363358
;; Add top_id and top_id_name to owners
364359
(doseq [[k {:keys [pso_id]}] (filter #(:pso_id (val %)) @owners)]
365360
(let [top_id (or (some #{pso_id} @annuaire_tops)
366-
(:service_top_id (get @annuaire pso_id)))
361+
(:id (:service_top (get @annuaire pso_id))))
367362
top_id_name (:nom (get @annuaire top_id))]
368363
(swap! owners update-in [k]
369364
conj {:pso_top_id top_id

0 commit comments

Comments
 (0)