From 3e4248c7b6f1b2d045dde9024f9fcba9df00b5a0 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sun, 31 Dec 2023 06:15:45 +0200 Subject: Redo gnosis-dev.el --- gnosis-dev.el | 99 ++++++++++++++++++++++++++++++++++------------------------- gnosis.el | 1 + 2 files changed, 59 insertions(+), 41 deletions(-) diff --git a/gnosis-dev.el b/gnosis-dev.el index 793c4ee..a8346e6 100644 --- a/gnosis-dev.el +++ b/gnosis-dev.el @@ -21,62 +21,79 @@ (setq shuffled-list (append (butlast shuffled-list index) (nthcdr (1+ index) shuffled-list))))) selected-items)) -(defun gnosis-dev-add-fields () +(defun gnosis-dev-add-fields (&optional num deck) "Add random inputs to test." - (when (y-or-n-p "Add MCQ type?") - (dotimes (_ 3) - (gnosis-add-note--mcq :deck "Anatomy" - :question "A 37-year-old man is admitted to the + (let ((num (or num (string-to-number (read-string "Number of random inputs: ")))) + (testing-deck (or deck "testing"))) + (gnosis-add-deck testing-deck) + (when (y-or-n-p "Add MCQ type?") + (dotimes (_ num) + (gnosis-add-note--mcq :deck testing-deck + :question "A 37-year-old man is admitted to the emergency department after a severe car crash. After examining the patient the emergency medicine physician concludes that the serratus anterior muscle is damaged. Which of the following nerves innervates the serratus anterior muscle?" - :choices '("Long thoracic" "Axillary" "Spinal accessory" "Dorsal scapular" "Thoracodorsal") - :correct-answer 1 - :extra "The long thoracic is the only nerve that + :choices '("Long thoracic" "Axillary" "Spinal accessory" "Dorsal scapular" "Thoracodorsal") + :correct-answer 1 + :extra "The long thoracic is the only nerve that innervates the serratus anterior. The axillary nerve innervates the deltoid, the spinal accessory nerve innervates the sternocleidomastoid and trapezius, the dorsal scapular nerve supplies the rhomboid muscles and levator scapulae, and the latissimus dorsi is the muscle supplied by the thoracodorsal nerve." - :tags (gnosis-dev-random-items gnosis-dev-tags 2)))) - (when (y-or-n-p "Add Basic type questions?") - (dotimes (_ 3) - (gnosis-add-note--basic :deck "Anatomy" - :question "A question" - :hint "hint" - :answer "answer" - :extra "extra" :tags (gnosis-dev-random-items gnosis-dev-tags 2)))) - (when (y-or-n-p "Add single cloze type?") - (dotimes (_ 3) - (gnosis-add-note--cloze :deck "Anatomy" - :note "this is a {c1:note}" - :hint "note" - :tags (gnosis-dev-random-items gnosis-dev-tags 2) - :extra "extra"))) - (when (y-or-n-p "Add mulit cloze type?") - (dotimes (_ 3) - (gnosis-add-note--cloze :deck "Anatomy" - :note "this is a {c1:note} with multiple {c1:clozes}" - :hint "note" - :tags (gnosis-dev-random-items gnosis-dev-tags 2) - :extra "extra")))) + (when (y-or-n-p "Add Basic type questions?") + (dotimes (_ num) + (gnosis-add-note--basic :deck testing-deck + :question "A question" + :hint "hint" + :answer "answer" + :extra "extra" + :tags (gnosis-dev-random-items gnosis-dev-tags 2)))) + (when (y-or-n-p "Add single cloze type?") + (dotimes (_ num) + (gnosis-add-note--cloze :deck testing-deck + :note "this is a {c1:note}" + :hint "note" + :tags (gnosis-dev-random-items gnosis-dev-tags 2) + :extra "extra"))) + (when (y-or-n-p "Add mulit cloze type?") + (dotimes (_ num) + (gnosis-add-note--cloze :deck testing-deck + :note "this is a {c1:note} with multiple {c1:clozes}" + :hint "note" + :tags (gnosis-dev-random-items gnosis-dev-tags 2) + :extra "extra"))))) (defun gnosis-dev-test () - "Start testing env." + "Begin/End testing env. + +If ask nil, leave development env" (interactive) - (let ((ask (y-or-n-p "Start development env?"))) + (let ((ask (y-or-n-p "Start development env?")) + (testing-dir (concat gnosis-dir "/testing"))) (if ask - (progn (setf gnosis-testing-dir (concat gnosis-dir "/testing")) - (unless (file-exists-p gnosis-testing-dir) - (make-directory gnosis-testing-dir)) - (setf gnosis-db (emacsql-sqlite-open (concat gnosis-testing-dir "/testing.db"))) - (gnosis-init)) - (setf gnosis-db (emacsql-sqlite-open (concat gnosis-dir "/" "gnosis.db")))) - (message "Adding testing values...") - (gnosis-dev-add-fields) - (message "Done."))) + (progn (unless (file-exists-p testing-dir) + (make-directory testing-dir)) + (setf gnosis-db (emacsql-sqlite (concat testing-dir "/testing.db"))) + (setf gnosis-testing t) + (gnosis-db-init) + (gnosis-dev-add-fields) + (message "Adding testing values...") + (message "Development env is ready for testing.")) + (setf gnosis-db (emacsql-sqlite-open (concat gnosis-dir "/" "gnosis.db"))) + (setf gnosis-testing nil) + (message "Exited development env.")))) + +(defun gnosis-dev-reinit () + "Redo database." + (interactive) + (dolist (table '(notes decks review review-log extras)) + (condition-case nil + (gnosis--drop-table table) + (error (message "No %s table to drop." table)))) + (gnosis-db-init)) (provide 'gnosis-dev) ;;; gnosis-dev.el ends here diff --git a/gnosis.el b/gnosis.el index 4e7b577..a0bfc9d 100644 --- a/gnosis.el +++ b/gnosis.el @@ -822,6 +822,7 @@ Used to reveal all clozes left with `gnosis-face-cloze-unanswered' face." (unless (length= (emacsql gnosis-db [:select name :from sqlite-master :where (= type table)]) 6) ;; Enable foreign keys (emacsql gnosis-db "PRAGMA foreign_keys = ON") + ;; Gnosis version (emacsql gnosis-db (format "PRAGMA user_version = %s" gnosis-db-version)) ;; Create decks table (gnosis--create-table 'decks gnosis-db-schema-decks) -- cgit v1.2.3