summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--biometry.asy38
-rw-r--r--ksh-report.el76
2 files changed, 37 insertions, 77 deletions
diff --git a/biometry.asy b/biometry.asy
deleted file mode 100644
index 294c212..0000000
--- a/biometry.asy
+++ /dev/null
@@ -1,38 +0,0 @@
-pair pair_ratio(pair a, pair b, real fraction) {
- return a + (b - a)*fraction;
-}
-real real_ratio(real a, real b, real fraction) {
- return a + (b - a)*fraction;
-}
-void draw_tic(pair a, pair b, real fraction, real tic_height, bool label) {
- pair pt1 = pair_ratio(a, b, fraction);
- pair pt2 = pt1 - (0, tic_height);
- draw(pt1 -- pt2);
- if (label) {
- label(format("%f\%", fraction*100), pt2, S);
- }
-}
-void draw_marker(pair a, pair b, real value, real marker_height) {
- pair markpt = pair_ratio(a, b, value);
- pair pt = (markpt.x, markpt.y + marker_height);
- label("*", pt);
-}
-void draw_scale(pair a, pair b, real value, real tic_height) {
- draw(pair_ratio(a, b, 0) -- pair_ratio(a, b, 1));
- draw_tic(a, b, 0.05, tic_height, true);
- draw_tic(a, b, 0.5, tic_height, true);
- draw_tic(a, b, 0.95, tic_height, true);
- draw_tic(a, b, 0.25, 0.5*tic_height, false);
- draw_tic(a, b, 0.75, 0.5*tic_height, false);
- draw_marker(a, b, value, 0.5*tic_height);
-}
-void draw_biometry(string param, string param_age, real percentile) {
- real width = 100;
- real height = 75;
-
- label(param, (width/2, 2*height/3), N);
- label(param_age, (width/2, 2*height/3), S);
- pair scale1 = (0.1*width, 0.25*height);
- pair scale2 = (0.9*width, 0.25*height);
- draw_scale(scale1, scale2, percentile/100, 0.1*height);
-} \ No newline at end of file
diff --git a/ksh-report.el b/ksh-report.el
index 722e4f6..ac31a62 100644
--- a/ksh-report.el
+++ b/ksh-report.el
@@ -1,53 +1,45 @@
(require 'seq)
-(defun draw-biometry (param-name param param-age percentile)
- (let ((temp-script-file (make-temp-script
- (format "%s %s" param-name param)
- param-age (string-to-number percentile))))
- (message "Drawing %s..." temp-script-file)
- (shell-command
- (format "asy -f pdf -o %s %s" (file-name-directory temp-script-file) temp-script-file))
- (delete-file temp-script-file)
- (format "%s.pdf" temp-script-file)))
-(defun make-temp-script (param param-age percentile)
- (let ((temp-script-file (make-temp-file "biometry")))
- (with-temp-file temp-script-file
- (insert "include \"biometry\";\n")
- (insert (format
- "draw_biometry(\"%s\", \"%s\", %d);"
- param param-age percentile)))
- temp-script-file))
+(defun biometry-subfloat (param-name param param-age percentile)
+ (format
+ "\\subfloat {
+ \\begin{tikzpicture}
+ \\coordinate (O) at (0,0);
+ \\coordinate (A) at (2,0);
+ \\coordinate (B) at ($0.5*(A)$);
+ \\draw (O) -- (A);
+ \\draw ($(O) + 0.05*(A)$) -- +(0,-\\tickheight) node [below] {5\\%%};
+ \\draw ($(O) + 0.25*(A)$) -- +($0.5*(0,-\\tickheight)$);
+ \\draw ($(O) + 0.5*(A)$) -- +(0,-\\tickheight) node [below] {50\\%%};
+ \\draw ($(O) + 0.75*(A)$) -- +($0.5*(0,-\\tickheight)$);
+ \\draw ($(O) + 0.95*(A)$) -- +(0,-\\tickheight) node [below] {95\\%%};
+ \\node [above] at ($(O) + %s*0.01*(A)$) {*};
+ \\node at ($0.5*(A) + (0,\\parameterheight)$) {%s %s};
+ \\node at ($0.5*(A) + (0,\\parameterageheight)$) {%s};
+ \\end{tikzpicture}
+ }
+" percentile param-name param param-age))
(defun insert-biometry (readings)
- (princ
- (format "[[%s]]\n"
- (crop-pdf
- (combine-pdfs
- (mapcar (lambda (reading)
- (apply 'draw-biometry
- (mapcar 'get-field reading)))
- readings))))))
-
-(defun combine-pdfs (pdfs)
- (let ((temp-combination (make-temp-file "pdfjam" nil ".pdf")))
- (apply 'call-process "pdfjam" nil nil nil
- "--nup" "4x1"
- "--outfile" temp-combination pdfs)
- (mapc 'delete-file pdfs)
- temp-combination))
-
-(defun crop-pdf (pdf)
- (message "Cropping %s..." pdf)
- (let ((output-pdf (format "%s-crop.pdf" (file-name-sans-extension pdf))))
- (shell-command (format "pdfcrop %s %s" pdf output-pdf))
- (delete-file pdf) output-pdf))
+ (princ "#+BEGIN_EXPORT latex\n")
+ (princ "\\begin{figure}\n")
+ (princ "\\centering\n")
+ (seq-do (lambda (reading)
+ (princ (apply 'biometry-subfloat
+ (seq-map 'get-field reading))))
+ readings)
+ (princ "\\end{figure}\n")
+ (princ "#+END_EXPORT\n"))
(defun latex-use-package (package &optional arguments)
(if arguments
(format "\\usepackage[%s]{%s}" arguments package)
(format "\\usepackage{%s}" package)))
+(defun latex-macro (name value)
+ (format "\\newcommand{\\%s}{%s}" name value))
+
(defun make-report-header (title)
(seq-do 'ksh-forms-org-keyword
'(("TITLE" . "Kuzhanthai Sanjeevi Hospital")
@@ -56,7 +48,13 @@
(list (latex-use-package "fullpage")
(latex-use-package "nopageno")
(latex-use-package "datetime" "ddmmyyyy")
+ (latex-use-package "subfig")
+ (latex-use-package "tikz")
+ "\\usetikzlibrary{calc}"
"\\renewcommand{\\dateseparator}{-}"
+ (latex-macro "tickheight" "0.3")
+ (latex-macro "parameterheight" "1")
+ (latex-macro "parameterageheight" "0.6")
"\\setlength{\\parindent}{0cm}"
(latex-use-package "titlesec" "tiny")
(latex-use-package "wasysym")