小编ben*_*kay的帖子

从Datomic中检索最新实体

我对实体及其时间戳感兴趣.基本上,我想要一个按时间排序的实体列表.

为此,我编写了以下功能:

(defn return-posts
  "grabs all posts from Datomic"
  []
  (d/q '[:find ?title ?body ?slug
         :where
         [?e :post/title ?title]
         [?e :post/slug ?slug]
         [?e :post/body ?body]] (d/db connection)))

(defn get-postid-from-slug
  [slug]
  (d/q '[:find ?e
         :in $ ?slug
         :where [?e :post/slug ?slug]] (d/db connection) slug))

(defn get-post-timestamp
  "given an entid, returns the most recent timestamp"
  [entid]
  (->
   (d/q '[:find ?ts
          :in $ ?e
          :where
          [?e _ _ _]
          [?e :db/txInstant ?ts]] (d/db connection) entid)
   (sort)
   (reverse)
   (first)))
Run Code Online (Sandbox Code Playgroud)

我认为必须是一个植根于无知的黑客.

有人会更熟练地使用惯用的Datomic使用并升级我的范例吗?

clojure datomic

13
推荐指数
1
解决办法
1526
查看次数

用pyplot绘制不等轴上的圆

我想在自动缩放的pyplot生成的图形上绘制一个圆圈.我跑的时候

ax.get_aspect()
Run Code Online (Sandbox Code Playgroud)

希望得到一个可以操纵椭圆轴的值,pyplot返回:

auto
Run Code Online (Sandbox Code Playgroud)

这不太有用.您会建议在不等轴的情节图上绘制圆形图?

python matplotlib

10
推荐指数
2
解决办法
6267
查看次数

openCV RunningAvg实现

我正在编写一个小脚本(用Python编写),用于生成和更新摄像机源的运行平均值.当我调用cv.RunningAvg时,它返回:

cv2.error: func != 0
Run Code Online (Sandbox Code Playgroud)

我在实施cv.RunningAvg方面遇到了什么磕磕绊?脚本如下:

import cv

feed = cv.CaptureFromCAM(0)
frame = cv.QueryFrame(feed)
moving_average = cv.QueryFrame(feed)
cv.NamedWindow('live', cv.CV_WINDOW_AUTOSIZE)

def loop():
    frame = cv.QueryFrame(feed)
    cv.ShowImage('live', frame)
    c = cv.WaitKey(10)

    cv.RunningAvg(frame, moving_average, 0.020, None)

while True:
    loop()
Run Code Online (Sandbox Code Playgroud)

opencv python-2.7 ubuntu-12.04

1
推荐指数
1
解决办法
4644
查看次数