[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/pyim d40bdc4b75 1/3: Add pyim-proportion.
From: |
ELPA Syncer |
Subject: |
[elpa] externals/pyim d40bdc4b75 1/3: Add pyim-proportion. |
Date: |
Sun, 9 Jan 2022 05:57:41 -0500 (EST) |
branch: externals/pyim
commit d40bdc4b750c70e1a450963a75ccbcc6d0fc310a
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>
Add pyim-proportion.
* tests/pyim-tests.el (pyim-test-pyim-proportion): New test.
* pyim-dhashcache.el (pyim-dhashcache-count-types): Use
pyim-proportion.
* pyim-common.el (pyim-proportion): New function.
---
pyim-common.el | 8 ++++++++
pyim-dhashcache.el | 7 +------
tests/pyim-tests.el | 4 ++++
3 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/pyim-common.el b/pyim-common.el
index ae171e3dd0..64a5777d0a 100644
--- a/pyim-common.el
+++ b/pyim-common.el
@@ -167,6 +167,14 @@ When CARE-FIRST-ONE is no-nil, ((a b c) (d e)) => (a d)."
(funcall in (1- i) (1- j)))))))
(funcall in l1 l2))))
+(defun pyim-proportion (nums)
+ "计算 NUMS 所占比例。"
+ (let ((sum (float (apply #'+ nums))))
+ (mapcar
+ (lambda (n)
+ (/ n sum))
+ nums)))
+
(defun pyim-add-unread-command-events (key &optional reset)
"This function is a fork of `quail-add-unread-command-events'."
(when reset
diff --git a/pyim-dhashcache.el b/pyim-dhashcache.el
index 423c03b07f..ac5e65c4a7 100644
--- a/pyim-dhashcache.el
+++ b/pyim-dhashcache.el
@@ -47,12 +47,7 @@
;; 最多保存七天 count 到缓存。
:max-save-length 7
;; 计算排序综合指标时,最近七天 count 对应的权重。
- :weights ,(let* ((nums '(1 2 3 5 8 13 21))
- (sum (float (apply #'+ nums))))
- (mapcar
- (lambda (n)
- (/ n sum))
- (reverse nums)))
+ :weights ,(pyim-proportion (reverse '(1 2 3 5 8 13 21)))
;; 获取前一天需要减去的天数。
:delta -1
;; 计算100天平均 count 需要乘的数字。
diff --git a/tests/pyim-tests.el b/tests/pyim-tests.el
index abc95a8e39..2b67654416 100644
--- a/tests/pyim-tests.el
+++ b/tests/pyim-tests.el
@@ -158,6 +158,10 @@
t)
(should (< (float-time (time-since time)) (* limit 2)))))
+(ert-deftest pyim-test-pyim-proportion ()
+ (should (equal (pyim-proportion '(1 2 3 4))
+ '(0.1 0.2 0.3 0.4))))
+
;; ** pyim-pymap 相关单元测试
(ert-deftest pyim-tests-pyim-pymap ()
(should-not (cl-find-if-not