|
|
@@ -7,7 +7,7 @@ |
|
|
|
[tservice.lib.files :as ff] |
|
|
|
[tservice.lib.fs :as fs-lib] |
|
|
|
[tservice.plugins.corrplot.common :as corrplot] |
|
|
|
[tservice.api.task :refer [publish-event! make-plugin-metadata make-events-init create-task! update-process!]])) |
|
|
|
[tservice.api.task :refer [make-routes publish-event! make-events-init create-task! update-process!]])) |
|
|
|
|
|
|
|
;;; ------------------------------------------------ Event Specs ------------------------------------------------ |
|
|
|
(s/def ::datafile |
|
|
@@ -73,51 +73,65 @@ |
|
|
|
:opt-un [::sig_level ::hc_order ::hc_method ::corr_type ::method])) |
|
|
|
|
|
|
|
;;; ------------------------------------------------ Event Metadata ------------------------------------------------ |
|
|
|
;; Handlers |
|
|
|
(defn get-handler |
|
|
|
[{{:keys [config-dir]} :plugin-env}] |
|
|
|
(let [plugin-schema (fs-lib/join-paths config-dir "templates/plugin-schema.json.mustache")] |
|
|
|
{:data (slurp plugin-schema)})) |
|
|
|
|
|
|
|
(defn post-handler |
|
|
|
[{:keys [datafile corr_vars sig_level hc_order hc_method corr_type method plugin-env] |
|
|
|
:or {sig_level 0.05 |
|
|
|
hc_order true |
|
|
|
hc_method "complete" |
|
|
|
corr_type "full" |
|
|
|
method "square"} |
|
|
|
:as payload}] |
|
|
|
(log/info "Make a correlation plot with %s" payload) |
|
|
|
(let [workdir (ff/get-workdir) |
|
|
|
log-path (fs-lib/join-paths workdir "log") |
|
|
|
response {:files [(fs-lib/join-paths workdir "plotly.json") |
|
|
|
(fs-lib/join-paths workdir "result.md")] |
|
|
|
:log log-path |
|
|
|
:response-type :data2files} |
|
|
|
task-id (create-task! {:name (str "corrplot" (u/datetime)) |
|
|
|
:description "Make a correlation plot." |
|
|
|
:payload payload |
|
|
|
:plugin-name (:plugin-name plugin-env) |
|
|
|
:plugin-type (:plugin-type plugin-env) |
|
|
|
:plugin-version (:plugin-version plugin-env) |
|
|
|
:response response})] |
|
|
|
(fs-lib/create-directories! workdir) |
|
|
|
(spit log-path (json/write-str {:status "Running" :msg ""})) |
|
|
|
(update-process! task-id 0) |
|
|
|
(publish-event! "corrplot" |
|
|
|
{:context {:datafile datafile |
|
|
|
:corr_vars corr_vars |
|
|
|
:sig_level sig_level |
|
|
|
:hc_order hc_order |
|
|
|
:hc_method hc_method |
|
|
|
:corr_type corr_type |
|
|
|
:method method |
|
|
|
:title "Correlation Plot"} |
|
|
|
:template-dir (fs-lib/join-paths (:config-dir plugin-env) "templates") |
|
|
|
:env-dir (:env-dir plugin-env) |
|
|
|
:dest-dir workdir |
|
|
|
:task-id task-id}) |
|
|
|
response)) |
|
|
|
|
|
|
|
(def metadata |
|
|
|
(make-plugin-metadata |
|
|
|
{:name "corrplot" |
|
|
|
:summary "It is used to investigate the dependence between multiple variables at the same time and to highlight the most correlated variables in a data table." |
|
|
|
:params-schema corrplot-params-body |
|
|
|
:handler (fn [{:keys [datafile corr_vars sig_level hc_order hc_method corr_type method plugin-env] |
|
|
|
:or {sig_level 0.05 |
|
|
|
hc_order true |
|
|
|
hc_method "complete" |
|
|
|
corr_type "full" |
|
|
|
method "square"} |
|
|
|
:as payload}] |
|
|
|
(log/info "Make a correlation plot with %s" payload) |
|
|
|
(let [workdir (ff/get-workdir) |
|
|
|
log-path (fs-lib/join-paths workdir "log") |
|
|
|
response {:files [(fs-lib/join-paths workdir "plotly.json") |
|
|
|
(fs-lib/join-paths workdir "result.md")] |
|
|
|
:log log-path |
|
|
|
:response-type :data2files} |
|
|
|
task-id (create-task! {:name (str "corrplot" (u/datetime)) |
|
|
|
:description "Make a correlation plot." |
|
|
|
:payload payload |
|
|
|
:plugin-name (:plugin-name plugin-env) |
|
|
|
:plugin-type (:plugin-type plugin-env) |
|
|
|
:plugin-version (:plugin-version plugin-env) |
|
|
|
:response response})] |
|
|
|
(fs-lib/create-directories! workdir) |
|
|
|
(spit log-path (json/write-str {:status "Running" :msg ""})) |
|
|
|
(update-process! task-id 0) |
|
|
|
(publish-event! "corrplot" |
|
|
|
{:context {:datafile datafile |
|
|
|
:corr_vars corr_vars |
|
|
|
:sig_level sig_level |
|
|
|
:hc_order hc_order |
|
|
|
:hc_method hc_method |
|
|
|
:corr_type corr_type |
|
|
|
:method method |
|
|
|
:title "Correlation Plot"} |
|
|
|
:template-dir (fs-lib/join-paths (:config-dir plugin-env) "templates") |
|
|
|
:env-dir (:env-dir plugin-env) |
|
|
|
:dest-dir workdir |
|
|
|
:task-id task-id}) |
|
|
|
response)) |
|
|
|
:plugin-type :ChartPlugin |
|
|
|
:response-type :data2files})) |
|
|
|
(make-routes "corrplot" :ChartPlugin |
|
|
|
{:method-type :get |
|
|
|
:summary "A json schema for corrplot plugin." |
|
|
|
:query-schema nil |
|
|
|
:path-schema nil |
|
|
|
:response-schema map? |
|
|
|
:handler get-handler} |
|
|
|
{:method-type :post |
|
|
|
:summary "It is used to investigate the dependence between multiple variables at the same time and to highlight the most correlated variables in a data table." |
|
|
|
:body-schema corrplot-params-body |
|
|
|
:handler post-handler |
|
|
|
:response-type :data2files})) |
|
|
|
|
|
|
|
;;; ------------------------------------------------ Event Processing ------------------------------------------------ |
|
|
|
(defn- corrplot! |