summaryrefslogtreecommitdiff
path: root/gnosis-test.el
blob: 50b8ba2a90a70be905da13ed409aaf5bd46d7b50 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
;;; gnosis-algorithm.el --- Gnosis testing module  -*- lexical-binding: t; -*-

;; Copyright (C) 2023  Thanos Apollo

;; Author: Thanos Apollo <[email protected]>
;; Keywords: extensions
;; URL: https://git.thanosapollo.org/gnosis
;; Version: 0.0.1

;; Package-Requires: ((emacs "27.2") (compat "29.1.4.2"))

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;; Development module for gnosis, make testing of gnosis
;; easier by creating a testing environment with random inputs.

;;; Code:

(require 'gnosis)

(defvar gnosis-test-tags '("anatomy" "thoracic" "serratus-anterior"
			  "biochemistry" "informatics" "amino-acids"
			  "microbiology" "gram-positive" "gram-negative"
			  "fungi" "parasites"))

(defvar gnosis-test-image "anatomy/typic-vertebra-superior-01.png"
  "Random image for testing")

(defun gnosis-test-random-items (list x)
  "Select X random items from LIST."
  (let ((shuffled-list (copy-sequence list))
        selected-items)
    (dotimes (_ x)
      (let* ((index (random (length shuffled-list)))
             (item (nth index shuffled-list)))
        (setq selected-items (cons item selected-items))
        (setq shuffled-list (append (butlast shuffled-list index) (nthcdr (1+ index) shuffled-list)))))
    selected-items))

(defun gnosis-test-add-fields (&optional num deck)
  "Add random inputs to test.

NUM: Number of random inputs to add.
DECK: Deck to add the inputs to."
  (let ((num (or num (string-to-number (read-string "Number of random inputs: "))))
	(testing-deck (or deck "testing")))
    (unless (gnosis-get 'name 'decks `(= name ,testing-deck))
      (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
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."
			      :images (cons gnosis-test-image gnosis-test-image)
			      :tags (gnosis-test-random-items gnosis-test-tags 2))))
    (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"
				:images (cons gnosis-test-image gnosis-test-image)
				:tags (gnosis-test-random-items gnosis-test-tags 2))))
    (when (y-or-n-p "Add single Cloze type?")
      (dotimes (_ num)
	;; TODO: Update tests for include hints.
	(gnosis-add-note--cloze :deck testing-deck
				:note "this is a {c1:note}"
				:tags (gnosis-test-random-items gnosis-test-tags 2)
				:images (cons gnosis-test-image gnosis-test-image)
				:extra "extra")))
    (when (y-or-n-p "Add multimple Clozes note?")
      (dotimes (_ num)
	(gnosis-add-note--cloze :deck testing-deck
				:note "this is a {c1:note}, a note with multiple {c1:clozes::what}"
				:tags (gnosis-test-random-items gnosis-test-tags 2)
				:images (cons gnosis-test-image gnosis-test-image)
				:extra "extra")))
    (when (y-or-n-p "Add y-or-n note type?")
      (dotimes (_ num)
	(gnosis-add-note--y-or-n :deck testing-deck
				 :question "Is Codeine recommended in breastfeeding mothers?"
				 :hint "hint"
				 :answer 110
				 :extra "extra"
				 :images (cons gnosis-test-image gnosis-test-image)
				 :tags (gnosis-test-random-items gnosis-test-tags 2))))))

(defun gnosis-test-start (&optional note-num)
  "Begin/End testing env.

If ask nil, leave testing env"
  (interactive)
  (let ((ask (y-or-n-p "Start development env (n for exit)?"))
	(testing-dir (expand-file-name "testing" gnosis-dir)))
    (if ask
	(progn
	  (unless (file-exists-p testing-dir)
	    (make-directory testing-dir))
	  (setf gnosis-db (emacsql-sqlite-open (expand-file-name "testing.db" testing-dir)))
	  (setf gnosis-testing t)
	  (dolist (table '(notes decks review review-log extras activity-log))
	    (condition-case nil
		(gnosis--drop-table table)
	      (error (message "No %s table to drop." table))))
	  (gnosis-db-init)
	  (gnosis-test-add-fields note-num)
	  (message "Adding testing values...")
	  (message "Development env is ready for testing."))
      (setf gnosis-db (emacsql-sqlite-open (expand-file-name "gnosis.db" gnosis-dir)))
      (setf gnosis-testing nil)
      (message "Exited development env."))))


(provide 'gnosis-test)
;;; gnosis-test.el ends here