Procházet zdrojové kódy

Add plugin schema.

master
YJC před 3 roky
rodič
revize
15a74f2c4c
4 změnil soubory, kde provedl 221 přidání a 45 odebrání
  1. +0
    -0
      resources/templates/args.json.selmer
  2. +162
    -0
      resources/templates/plugin-schema.json.mustache
  3. +0
    -0
      resources/templates/result.md.selmer
  4. +59
    -45
      src/tservice/plugins/corrplot.clj

resources/templates/args.json.template → resources/templates/args.json.selmer Zobrazit soubor


+ 162
- 0
resources/templates/plugin-schema.json.mustache Zobrazit soubor

@@ -0,0 +1,162 @@
{
"title": "Correlation Plot",
"maintainer": "Jingcheng Yang",
"description": "Correlation plots can be used to quickly find insights. 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.",
"logo": "https://store-images.s-microsoft.com/image/apps.30079.0034b9fb-e1fa-4c69-b5b7-de0750ba3098.c645c7e3-2d23-4418-9288-0bd1322b1070.9112ecd7-1c16-4a37-ab49-a5b2c2b61542.png",
"version": "v0.1.0",
"readme": "http: //nordata-cdn.oss-cn-shanghai.aliyuncs.com/test.md",
"tags": [
"R",
"Chart"
],
"fields": [
{
"key": "corr_vars",
"dataIndex": "corr_vars",
"valueType": "select",
"title": "Correlation Variables",
"tooltip": "Which variables do you want to analyze?",
"valueEnum": {{ columns }},
"fieldProps": {
"mode": "multiple",
},
"formItemProps": {
"rules": [
{
"required": true,
"message": "Please select several variables."
}
]
}
},
{
"key": "method",
"dataIndex": "method",
"valueType": "select",
"title": "Method",
"tooltip": "The visualization method of correlation matrix to be used. Allowed values are square (default), circle.",
"valueEnum": {
"square": {
"text": "Square"
},
"circle": {
"text": "Circle"
}
},
"formItemProps": {
"initialValue": "square"
}
},
{
"key": "corr_type",
"dataIndex": "corr_type",
"valueType": "select",
"title": "Correlation Type",
"tooltip": "full (default), lower or upper display.",
"valueEnum": {
"full": {
"text": "Full"
},
"lower": {
"text": "Lower"
},
"upper": {
"text": "Upper"
}
},
"formItemProps": {
"initialValue": "full"
}
},
{
"key": "hc_method",
"dataIndex": "hc_method",
"valueType": "select",
"title": "Cluster Method",
"tooltip": "The agglomeration method to be used in hclust (see ?hclust).",
"valueEnum": {
"ward.D": {
"text": "ward.D"
},
"ward.D2": {
"text": "ward.D2"
},
"single": {
"text": "single"
},
"complete": {
"text": "complete"
},
"average": {
"text": "average"
},
"mcquitty": {
"text": "mcquitty"
},
"median": {
"text": "median"
},
"centroid": {
"text": "centroid"
}
},
"formItemProps": {
"initialValue": "complete"
}
},
{
"key": "hc_order",
"dataIndex": "hc_order",
"valueType": "switch",
"title": "Cluster Ordered",
"tooltip": "Logical value. If TRUE, correlation matrix will be hc.ordered using hclust function.",
"formItemProps": {
"initialValue": true
}
},
{
"key": "sig_level",
"dataIndex": "sig_level",
"valueType": "switch",
"title": "Cluster Ordered",
"tooltip": "Significant level, greater than 0 and less than 1."
"fieldProps": {
"step": 0.01
},
"formItemProps": {
"initialValue": 0.05
}
}
],
"dataKey": {
"annoData": "Anno",
"data": "Data"
},
"examples": [
{
"title": "Example 1",
"key": "example-1",
"datafile": "",
"arguments": {
"corr_vars": [
"mpg",
"cyl",
"disp",
"hp",
"drat",
"wt",
"qsec",
"vs",
"am",
"gear",
"carb"
],
"sig_level": 0.05,
"hc_order": true,
"hc_method": "complete",
"corr_type": "full",
"method": "square"
}
}
]
}

resources/templates/result.md.template → resources/templates/result.md.selmer Zobrazit soubor


+ 59
- 45
src/tservice/plugins/corrplot.clj Zobrazit soubor

@@ -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!

Načítá se…
Zrušit
Uložit