summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--awk/stats_reviews.awk2
-rw-r--r--org-fc-awk.el2
-rw-r--r--org-fc-dashboard.el24
-rw-r--r--org-fc-review.el50
4 files changed, 46 insertions, 32 deletions
diff --git a/awk/stats_reviews.awk b/awk/stats_reviews.awk
index 4dcfa74..eb5605a 100644
--- a/awk/stats_reviews.awk
+++ b/awk/stats_reviews.awk
@@ -47,7 +47,7 @@ function report(values, n) {
if (n == 0) {
print 0 "\t" 0 "\t" 0 "\t" 0 "\t" 0;
} else {
- print n "\t" values["again"] / n "\t" values["hard"] / n "\t" values["good"] /n "\t" values["easy"] / n;
+ print n "\t" values["again"] "\t" values["hard"] "\t" values["good"] "\t" values["easy"] ;
}
}
diff --git a/org-fc-awk.el b/org-fc-awk.el
index 94787bf..131b432 100644
--- a/org-fc-awk.el
+++ b/org-fc-awk.el
@@ -127,7 +127,7 @@ parsing each element with its header specification."
"Headers of the position indexer")
(defvar org-fc-awk-review-stats-headers
- '((:reviews . number) (:again . number) (:hard . number) (:good . number) (:easy . number))
+ '((:total . number) (:again . number) (:hard . number) (:good . number) (:easy . number))
"Headers of the review stat aggregator")
;;; AWK wrapper functions
diff --git a/org-fc-dashboard.el b/org-fc-dashboard.el
index 936e4ea..d1f27de 100644
--- a/org-fc-dashboard.el
+++ b/org-fc-dashboard.el
@@ -42,11 +42,12 @@
"Generate a svg bar-chart for the plist STAT"
(let* ((width org-fc-dashboard-bar-chart-width)
(height org-fc-dashboard-bar-chart-height)
+ (total (plist-get stat :total))
(values
- `((,(or (plist-get stat :again) 0.0) . "red")
- (,(or (plist-get stat :hard) 0.0) . "yellow")
- (,(or (plist-get stat :good) 0.0) . "green")
- (,(or (plist-get stat :easy) 0.0) . "darkgreen")))
+ `((,(/ (plist-get stat :again) total) . "red")
+ (,(/ (plist-get stat :hard) total) . "yellow")
+ (,(/ (plist-get stat :good) total) . "green")
+ (,(/ (plist-get stat :easy) total) . "darkgreen")))
(svg (svg-create width height)))
(do ((values values (cdr values))
(pos 0 (+ pos (* width (caar values)))))
@@ -55,11 +56,12 @@
(svg-image svg)))
(defun org-fc-dashboard-percent-right (stats)
- (format " %5.2f | %5.2f | %5.2f | %5.2f"
- (or (* 100 (plist-get stats :again)) 0.0)
- (or (* 100 (plist-get stats :hard)) 0.0)
- (or (* 100 (plist-get stats :good)) 0.0)
- (or (* 100 (plist-get stats :easy)) 0.0)))
+ (let ((total (plist-get stats :total)))
+ (format " %5.2f | %5.2f | %5.2f | %5.2f"
+ (or (* 100 (/ (plist-get stats :again) total)) 0.0)
+ (or (* 100 (/ (plist-get stats :hard) total)) 0.0)
+ (or (* 100 (/ (plist-get stats :good) total)) 0.0)
+ (or (* 100 (/ (plist-get stats :easy) total)) 0.0))))
;;; Main View
@@ -121,8 +123,8 @@
(:month . "Month")
(:all . "All")))
(when-let (stat (plist-get reviews-stats (car scope)))
- (when (plusp (plist-get stat :reviews))
- (insert (propertize (format " %s (%d)\n" (cdr scope) (plist-get stat :reviews)) 'face 'org-level-1))
+ (when (plusp (plist-get stat :total))
+ (insert (propertize (format " %s (%d)\n" (cdr scope) (plist-get stat :total)) 'face 'org-level-1))
(insert " ")
(insert-image (org-fc-dashboard-bar-chart stat))
(insert (org-fc-dashboard-percent-right stat))
diff --git a/org-fc-review.el b/org-fc-review.el
index 1e6addb..f914c97 100644
--- a/org-fc-review.el
+++ b/org-fc-review.el
@@ -30,8 +30,14 @@
(defclass org-fc-review-session ()
((current-item :initform nil)
- (ratings :initform nil)
- (cards :initform nil)))
+ (ratings :initform nil :initarg :ratings)
+ (cards :initform nil :initarg :cards)))
+
+(defun org-fc-make-review-session (cards)
+ (make-instance
+ 'org-fc-review-session
+ :ratings (plist-get (org-fc-awk-stats-reviews) :day)
+ :cards cards))
(defun org-fc-session-cards-pending-p (session)
(not (null (oref session cards))))
@@ -42,17 +48,23 @@
card))
(defun org-fc-session-add-rating (session rating)
- (push rating (oref session ratings)))
+ (with-slots (ratings) session
+ (case rating
+ ('again (incf (getf ratings :again) 1))
+ ('hard (incf (getf ratings :hard) 1))
+ ('good (incf (getf ratings :good) 1))
+ ('easy (incf (getf ratings :easy) 1)))
+ (incf (getf ratings :total 1))))
(defun org-fc-session-stats-string (session)
(with-slots (ratings) session
- (let ((len (length ratings)))
- (if (plusp len)
+ (let ((total (plist-get ratings :total)))
+ (if (plusp total)
(format "%.2f again, %.2f hard, %.2f good, %.2f easy"
- (/ (* 100.0 (count 'again ratings)) len)
- (/ (* 100.0 (count 'hard ratings)) len)
- (/ (* 100.0 (count 'good ratings)) len)
- (/ (* 100.0 (count 'easy ratings)) len))
+ (/ (* 100.0 (plist-get ratings :again)) total)
+ (/ (* 100.0 (plist-get ratings :hard)) total)
+ (/ (* 100.0 (plist-get ratings :good)) total)
+ (/ (* 100.0 (plist-get ratings :easy)) total))
"No ratings yet"))))
(defvar org-fc-review--current-session nil
@@ -79,15 +91,15 @@
;;; Reviewing Cards
(defun org-fc-review--context (context)
- (let* ((session (make-instance 'org-fc-review-session))
- (cards (org-fc-due-positions context)))
- (if org-fc-review--current-session
- (message "Flashcards are already being reviewed")
+ "Start a review session for all cards in CONTEXT."
+ (if org-fc-review--current-session
+ (message "Flashcards are already being reviewed")
+ (let ((cards (org-fc-due-positions context)))
(if (null cards)
(message "No cards due right now")
(progn
- (setq org-fc-review--current-session session)
- (setf (oref session cards) cards)
+ (setq org-fc-review--current-session
+ (org-fc-make-review-session cards))
(org-fc-review-next-card))))))
;;;###autoload
@@ -112,8 +124,8 @@
(with-current-buffer (find-file path)
;; If buffer was already open, don't kill it after rating the card
(if buffer
- (setq-local org-fc-reviewing-existing-buffer t)
- (setq-local org-fc-reviewing-existing-buffer nil))
+ (setq-local org-fc-reviewing-existing-buffer t)
+ (setq-local org-fc-reviewing-existing-buffer nil))
(goto-char (point-min))
(org-fc-show-all)
(org-fc-id-goto id path)
@@ -128,7 +140,7 @@
(setq org-fc-review--current-session nil)
(org-fc-show-all))))
-(defhydra org-fc-review-rate-hydra (:foreign-keys run)
+(defhydra org-fc-review-rate-hydra ()
"
%(length (oref org-fc-review--current-session cards)) cards remaining
%s(org-fc-session-stats-string org-fc-review--current-session)
@@ -140,7 +152,7 @@
("e" (org-fc-review-rate-card 'easy) "Rate as easy" :exit t)
("q" org-fc-review-quit "Quit" :exit t))
-(defhydra org-fc-review-flip-hydra (:foreign-keys run)
+(defhydra org-fc-review-flip-hydra ()
"
%(length (oref org-fc-review--current-session cards)) cards remaining
%s(org-fc-session-stats-string org-fc-review--current-session)