<commit_before>(ns amindblowingworld.rest
  (:require [amindblowingworld.world :refer :all]
            [amindblowingworld.history :refer :all]
            [amindblowingworld.civs :refer :all]
            [clojure.data.json :as json]))

(def users (atom []))

(defn add-user-request [name]
  (swap! users conj name)
  (json/write-str "OK"))

(defn users-request []
  (json/write-str @users))

(defn total-pop-request []
  (json/write-str (total-pop)))

(defn- tribe-info [tribe]
  {:id (:id tribe) :name (.name tribe) :settlements (:settlements tribe)})

(defn- settlement-info [s]
  {:id (:id s) :name (.name s) :pos (:pos s) :tribe (:owner s)})

(defn tribes-request []
  (json/write-str (map tribe-info (vals (:tribes @game)))))

(defn- settlements-of-tribe [tribe-id]
  (map get-settlement (:settlements (get-tribe tribe-id))))

(defn tribe-settlements-request [tribe-id]
  (json/write-str (map settlement-info (settlements-of-tribe tribe-id))))

(defn settlements-request []
  (json/write-str (map settlement-info (vals (:settlements @game)))))<commit_msg>Returning also settlement population through rest interface<commit_after>(ns amindblowingworld.rest
  (:require [amindblowingworld.world :refer :all]
            [amindblowingworld.history :refer :all]
            [amindblowingworld.civs :refer :all]
            [clojure.data.json :as json]))

(def users (atom []))

(defn add-user-request [name]
  (swap! users conj name)
  (json/write-str "OK"))

(defn users-request []
  (json/write-str @users))

(defn total-pop-request []
  (json/write-str (total-pop)))

(defn- tribe-info [tribe]
  {:id (:id tribe) :name (.name tribe) :settlements (:settlements tribe)})

(defn- settlement-info [s]
  {:id (:id s) :name (.name s) :pos (:pos s) :tribe (:owner s) :pop (:pop s)})

(defn tribes-request []
  (json/write-str (map tribe-info (vals (:tribes @game)))))

(defn- settlements-of-tribe [tribe-id]
  (map get-settlement (:settlements (get-tribe tribe-id))))

(defn tribe-settlements-request [tribe-id]
  (json/write-str (map settlement-info (settlements-of-tribe tribe-id))))

(defn settlements-request []
  (json/write-str (map settlement-info (vals (:settlements @game)))))
{'fraction_non_alphanumeric': 0.1759853345554537, 'fraction_numerical': 0.0, 'mean_word_length': 3.9840182648401825, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3285677', 'n_tokens_mistral': 839, 'n_tokens_neox': 787, 'n_words': 196}