|
|
@@ -10,6 +10,22 @@ |
|
|
|
[tservice.api.task :refer [make-routes publish-event! make-events-init create-task! update-process!]])) |
|
|
|
|
|
|
|
;;; ------------------------------------------------ Event Specs ------------------------------------------------ |
|
|
|
(s/def ::name |
|
|
|
(st/spec |
|
|
|
{:spec string? |
|
|
|
:type :string |
|
|
|
:description "A name for the corrplot task." |
|
|
|
:swagger/default (str "corrplot" (u/datetime)) |
|
|
|
:reason "The name must be string."})) |
|
|
|
|
|
|
|
(s/def ::description |
|
|
|
(st/spec |
|
|
|
{:spec string? |
|
|
|
:type :string |
|
|
|
:description "A description for the corrplot task." |
|
|
|
:swagger/default "Make a correlation plot." |
|
|
|
:reason "The description must be string."})) |
|
|
|
|
|
|
|
(s/def ::datafile |
|
|
|
(st/spec |
|
|
|
{:spec string? |
|
|
@@ -76,31 +92,35 @@ |
|
|
|
;;; ------------------------------------------------ Event Metadata ------------------------------------------------ |
|
|
|
;; Handlers |
|
|
|
(defn get-handler |
|
|
|
[{{:keys [config-dir]} :plugin-env}] |
|
|
|
[{{:keys [config-dir]} :plugin-context}] |
|
|
|
(let [plugin-schema (fs-lib/join-paths config-dir "templates/plugin-schema.handlebars.json")] |
|
|
|
{:schema (json/read-str (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"} |
|
|
|
[{:keys [datafile corr_vars sig_level hc_order |
|
|
|
hc_method corr_type method plugin-context |
|
|
|
uuid workdir owner name description] |
|
|
|
:or {sig_level 0.05 |
|
|
|
hc_order true |
|
|
|
hc_method "complete" |
|
|
|
corr_type "full" |
|
|
|
method "square" |
|
|
|
name (str "corrplot" (u/datetime)) |
|
|
|
description "Make a correlation plot."} |
|
|
|
: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." |
|
|
|
(let [log-path (fs-lib/join-paths workdir "log") |
|
|
|
response {:data {:charts [(fs-lib/join-paths workdir "plotly.json")] |
|
|
|
:results []} |
|
|
|
:log log-path} |
|
|
|
task-id (create-task! {:id uuid |
|
|
|
:name name |
|
|
|
:description description |
|
|
|
:payload payload |
|
|
|
:plugin-name (:plugin-name plugin-env) |
|
|
|
:plugin-type (:plugin-type plugin-env) |
|
|
|
:plugin-version (:plugin-version plugin-env) |
|
|
|
:owner owner |
|
|
|
:plugin-name (:plugin-name plugin-context) |
|
|
|
:plugin-type (:plugin-type plugin-context) |
|
|
|
:plugin-version (:plugin-version plugin-context) |
|
|
|
:response response})] |
|
|
|
(fs-lib/create-directories! workdir) |
|
|
|
(spit log-path (json/write-str {:status "Running" :msg ""})) |
|
|
@@ -114,8 +134,8 @@ |
|
|
|
: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) |
|
|
|
:template-dir (fs-lib/join-paths (:config-dir plugin-context) "templates") |
|
|
|
:env-dir (:env-dir plugin-context) |
|
|
|
:dest-dir workdir |
|
|
|
:task-id task-id}) |
|
|
|
(merge response {:task-id task-id}))) |
|
|
@@ -133,7 +153,7 @@ |
|
|
|
: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})) |
|
|
|
:response-type :data2charts})) |
|
|
|
|
|
|
|
;;; ------------------------------------------------ Event Processing ------------------------------------------------ |
|
|
|
(defn- corrplot! |