|
|
|
|
|
|
|
|
(:require [clojure.data.json :as json] |
|
|
(:require [clojure.data.json :as json] |
|
|
[clojure.spec.alpha :as s] |
|
|
[clojure.spec.alpha :as s] |
|
|
[clojure.tools.logging :as log] |
|
|
[clojure.tools.logging :as log] |
|
|
[babashka.curl :as curl] |
|
|
|
|
|
[spec-tools.core :as st] |
|
|
[spec-tools.core :as st] |
|
|
[tservice.util :as u] |
|
|
[tservice.util :as u] |
|
|
[clojure.string :as clj-str] |
|
|
|
|
|
[tservice.lib.fs :as fs-lib] |
|
|
[tservice.lib.fs :as fs-lib] |
|
|
[clojure.java.io :as io] |
|
|
|
|
|
|
|
|
[tservice.api.storage.fs :as fs-api] |
|
|
[tservice.plugins.corrplot.common :as corrplot] |
|
|
[tservice.plugins.corrplot.common :as corrplot] |
|
|
[tservice.api.task :refer [make-routes publish-event! make-events-init create-task! update-process!]])) |
|
|
[tservice.api.task :refer [make-routes publish-event! make-events-init create-task! update-process!]])) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(let [plugin-schema (fs-lib/join-paths config-dir "templates/plugin-schema.handlebars.json")] |
|
|
(let [plugin-schema (fs-lib/join-paths config-dir "templates/plugin-schema.handlebars.json")] |
|
|
{:schema (json/read-str (slurp plugin-schema))})) |
|
|
{: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 |
|
|
(defn post-handler |
|
|
[{:keys [datafile corr_vars sig_level hc_order |
|
|
[{:keys [datafile corr_vars sig_level hc_order |
|
|
hc_method corr_type method plugin-context |
|
|
hc_method corr_type method plugin-context |
|
|
|
|
|
|
|
|
:as payload}] |
|
|
:as payload}] |
|
|
(log/info "Make a correlation plot with %s" payload) |
|
|
(log/info "Make a correlation plot with %s" payload) |
|
|
(fs-lib/create-directories! workdir) |
|
|
(fs-lib/create-directories! workdir) |
|
|
(let [datafile (download-file datafile (fs-lib/join-paths workdir "data.csv")) |
|
|
|
|
|
|
|
|
(let [datafile (fs-api/download-file! datafile workdir) |
|
|
log-path (fs-lib/join-paths workdir "log") |
|
|
log-path (fs-lib/join-paths workdir "log") |
|
|
response {:charts [(fs-lib/join-paths workdir "plotly.json")] |
|
|
response {:charts [(fs-lib/join-paths workdir "plotly.json")] |
|
|
:results [] |
|
|
:results [] |