clojure - 如何解决药物持有率(MPR)问题?
问题描述
我正在尝试解决药物持有配给问题。
我尝试使用间隔,然后将它们与观察期进行比较。
(ns clara-rules.mpr-new
(:require [clj-time.core :as t]
[clj-time.format :as f]))
(defn observe [interval]
(def start (map #(f/parse (f/formatter "dd MM yyyy") (% :start_)) interval))
(def end (map #(f/parse (f/formatter "dd MM yyyy") (% :end_)) interval))
)
(observe '({:start_ "20 01 2012" :end_ "20 02 2012"}
{:start_ "20 02 2012" :end_ "20 03 2012"}
{:start_ "20 04 2012" :end_ "20 05 2012"}
{:start_ "20 06 2012" :end_ "20 07 2012"}))
(defn calc[a b]
(def start_date (f/parse (f/formatter "dd MM yyyy") a)
)
(def end_date (f/parse (f/formatter "dd MM yyyy")b)
)
(def observation_period(t/in-days(t/interval start_date end_date)))
(println observation_period)
)
(calc "01 02 2012" "01 12 2012")
(defn mpr_ratio[]
(def overlp (map #(t/overlap (t/interval start_date end_date) (t/interval %1 %2))start end))
(def x (map #(t/in-days %)overlp))
(println x)
(def ratio (reduce +(map #(float(*(/ % observation_period)100))x)))
(println ratio)
)
(mpr_ratio)
我期望所有间隔和观察期的计算比率。
解决方案
这就是天间隔函数的样子:
(defn process []
(let [from ["20 01 2012"
"20 03 2012"
"20 06 2012"
"20 08 2012"]
to ["20 02 2012"
"20 05 2012"
"20 07 2012"
"20 09 2012"]
get-date (partial f/parse (f/formatter "dd MM yyyy"))
days (map #(t/in-days (t/interval (get-date %1) (get-date %2)))
from to)]
days))
user> (process)
;;=> (31 61 30 31)
不过,我建议你阅读一些关于 clojure 的介绍
推荐阅读
- azure - 如何从多个 Azure 服务中删除标签?
- ios - UIImage initWithCGImage 导致 Obj-C 中的内存问题
- python - Django - CreateView 将创建的对象 id 传递给另一个 CreateView
- pyspark - pyspark中不相等的运算符给出错误的结果
- ios - iOS 应用签名期间的预填充分发清单信息
- jmeter - JMeter:在“用户”之间划分数据集
- python - 如何从 chalice 应用程序调用 sagemaker xgboost 端点?
- arrays - 如何从数组中的数组创建列
- html - XML 数据不会在页面上居中
- sql-server - 查询在指定日期范围内活动的记录