<commit_before>(ns akvo.lumen.lib.public-impl
  (:require [akvo.lumen.lib.dashboard :as dashboard]
            [akvo.lumen.lib.dataset :as dataset]
            [akvo.lumen.lib.pivot :as pivot]
            [akvo.lumen.lib.visualisation :as visualisation]
            [cheshire.core :as json]
            [hugsql.core :as hugsql]
            [ring.util.response :refer [content-type not-found response]]))

(hugsql/def-db-fns "akvo/lumen/lib/public.sql")

(defn get-share [tenant-conn id]
  (public-by-id tenant-conn {:id id}))

(defmulti visualisation (fn [_ visualisation]
                          (:visualisationType visualisation)))

(defmethod visualisation "pivot table"
  [tenant-conn visualisation]
  (let [dataset-id (:datasetId visualisation)
        {:keys [status body]} (pivot/query tenant-conn dataset-id (:spec visualisation))]
    (when (= status 200)
      {"visualisations" {(:id visualisation) (assoc visualisation :data visualisation)}})))<commit_msg>[#532] Add correct data to pivot table shares<commit_after>(ns akvo.lumen.lib.public-impl
  (:require [akvo.lumen.lib.dashboard :as dashboard]
            [akvo.lumen.lib.dataset :as dataset]
            [akvo.lumen.lib.pivot :as pivot]
            [akvo.lumen.lib.visualisation :as visualisation]
            [cheshire.core :as json]
            [hugsql.core :as hugsql]
            [ring.util.response :refer [content-type not-found response]]))

(hugsql/def-db-fns "akvo/lumen/lib/public.sql")

(defn get-share [tenant-conn id]
  (public-by-id tenant-conn {:id id}))

(defmulti visualisation (fn [_ visualisation]
                          (:visualisationType visualisation)))

(defmethod visualisation "pivot table"
  [tenant-conn visualisation]
  (let [dataset-id (:datasetId visualisation)
        {:keys [status body]} (pivot/query tenant-conn dataset-id (:spec visualisation))]
    (when (= status 200)
      {"visualisations" {(:id visualisation) (assoc visualisation :data body)}})))
{'fraction_non_alphanumeric': 0.1360163015792155, 'fraction_numerical': 0.004584819154355578, 'mean_word_length': 3.0578512396694215, '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': '7546478', 'n_tokens_mistral': 651, 'n_tokens_neox': 622, 'n_words': 146}