|
|
@@ -2,10 +2,12 @@ |
|
|
|
(:require [clojure.data.json :as json] |
|
|
|
[clojure.spec.alpha :as s] |
|
|
|
[clojure.tools.logging :as log] |
|
|
|
[babashka.curl :as curl] |
|
|
|
[spec-tools.core :as st] |
|
|
|
[tservice.util :as u] |
|
|
|
[tservice.lib.files :as ff] |
|
|
|
[clojure.string :as clj-str] |
|
|
|
[tservice.lib.fs :as fs-lib] |
|
|
|
[clojure.java.io :as io] |
|
|
|
[tservice.plugins.corrplot.common :as corrplot] |
|
|
|
[tservice.api.task :refer [make-routes publish-event! make-events-init create-task! update-process!]])) |
|
|
|
|
|
|
@@ -96,6 +98,26 @@ |
|
|
|
(let [plugin-schema (fs-lib/join-paths config-dir "templates/plugin-schema.handlebars.json")] |
|
|
|
{:schema (json/read-str (slurp plugin-schema))})) |
|
|
|
|
|
|
|
(defn download-file |
|
|
|
[datafile dest-file] |
|
|
|
(cond |
|
|
|
(re-matches #"^oss:\/\/\/.*" datafile) |
|
|
|
(comment "Download by oss client") |
|
|
|
|
|
|
|
(re-matches #"^minio:\/\/\..*" datafile) |
|
|
|
(comment "Download by minio client") |
|
|
|
|
|
|
|
(re-matches #"^file:\/\/.*" datafile) |
|
|
|
(clj-str/replace datafile #"^file:\/\/" "") |
|
|
|
|
|
|
|
(re-matches #"^https?:\/\/.*" datafile) |
|
|
|
(or (-> (curl/get datafile {:as :stream}) |
|
|
|
(:body) |
|
|
|
(io/copy (io/file dest-file))) |
|
|
|
dest-file) |
|
|
|
|
|
|
|
:else datafile)) |
|
|
|
|
|
|
|
(defn post-handler |
|
|
|
[{:keys [datafile corr_vars sig_level hc_order |
|
|
|
hc_method corr_type method plugin-context |
|
|
@@ -109,7 +131,9 @@ |
|
|
|
description "Make a correlation plot."} |
|
|
|
:as payload}] |
|
|
|
(log/info "Make a correlation plot with %s" payload) |
|
|
|
(let [log-path (fs-lib/join-paths workdir "log") |
|
|
|
(fs-lib/create-directories! workdir) |
|
|
|
(let [datafile (download-file datafile (fs-lib/join-paths workdir "data.csv")) |
|
|
|
log-path (fs-lib/join-paths workdir "log") |
|
|
|
response {:charts [(fs-lib/join-paths workdir "plotly.json")] |
|
|
|
:results [] |
|
|
|
:log log-path |
|
|
@@ -124,7 +148,6 @@ |
|
|
|
: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 ""})) |
|
|
|
(update-process! uuid 0) |
|
|
|
(publish-event! "corrplot" |