瀏覽代碼

Support datafile from http server.

master
YJC 3 年之前
父節點
當前提交
21ed06bdd1
共有 3 個檔案被更改,包括 31 行新增7 行删除
  1. +4
    -3
      project.clj
  2. +1
    -1
      resources/templates/plugin-schema.handlebars.json
  3. +26
    -3
      src/tservice/plugins/corrplot.clj

+ 4
- 3
project.clj 查看文件



:dependencies :dependencies
[[org.clojure/tools.logging "1.1.0"] [[org.clojure/tools.logging "1.1.0"]
[selmer "1.12.27"]]
[selmer "1.12.27"]
[babashka/babashka.curl "0.0.3"]]


:profiles :profiles
{:provided {:provided
{:dependencies {:dependencies
[[org.clojure/clojure "1.10.1"] [[org.clojure/clojure "1.10.1"]
[org.clojars.yjcyxky/tservice "0.6.0"]]} [org.clojars.yjcyxky/tservice "0.6.0"]]}
:uberjar
:uberjar
{:auto-clean true {:auto-clean true
:aot :all :aot :all
:omit-source true :omit-source true

+ 1
- 1
resources/templates/plugin-schema.handlebars.json 查看文件

{ {
"key": "sig_level", "key": "sig_level",
"dataIndex": "sig_level", "dataIndex": "sig_level",
"valueType": "switch",
"valueType": "digit",
"title": "Significant Level", "title": "Significant Level",
"tooltip": "Significant level, greater than 0 and less than 1.", "tooltip": "Significant level, greater than 0 and less than 1.",
"fieldProps": { "fieldProps": {

+ 26
- 3
src/tservice/plugins/corrplot.clj 查看文件

(: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]
[tservice.lib.files :as ff]
[clojure.string :as clj-str]
[tservice.lib.fs :as fs-lib] [tservice.lib.fs :as fs-lib]
[clojure.java.io :as io]
[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
description "Make a correlation plot."} description "Make a correlation plot."}
:as payload}] :as payload}]
(log/info "Make a correlation plot with %s" 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")] response {:charts [(fs-lib/join-paths workdir "plotly.json")]
:results [] :results []
:log log-path :log log-path
:plugin-type (:plugin-type plugin-context) :plugin-type (:plugin-type plugin-context)
:plugin-version (:plugin-version plugin-context) :plugin-version (:plugin-version plugin-context)
:response response}) :response response})
(fs-lib/create-directories! workdir)
(spit log-path (json/write-str {:status "Running" :msg ""})) (spit log-path (json/write-str {:status "Running" :msg ""}))
(update-process! uuid 0) (update-process! uuid 0)
(publish-event! "corrplot" (publish-event! "corrplot"

Loading…
取消
儲存