summaryrefslogtreecommitdiff
path: root/ksh-biometry.el
diff options
context:
space:
mode:
authorArun Isaac2016-12-21 02:21:54 +0530
committerArun Isaac2016-12-21 02:21:54 +0530
commitb3484b533476aa6d6263775b7a79670bc9eec70e (patch)
treeb23b559f5aef54bcde689ee7307da762181dce9a /ksh-biometry.el
downloadksh-reports-b3484b533476aa6d6263775b7a79670bc9eec70e.tar.gz
ksh-reports-b3484b533476aa6d6263775b7a79670bc9eec70e.tar.lz
ksh-reports-b3484b533476aa6d6263775b7a79670bc9eec70e.zip
Initial commit
Diffstat (limited to 'ksh-biometry.el')
-rw-r--r--ksh-biometry.el41
1 files changed, 41 insertions, 0 deletions
diff --git a/ksh-biometry.el b/ksh-biometry.el
new file mode 100644
index 0000000..0e5f1d7
--- /dev/null
+++ b/ksh-biometry.el
@@ -0,0 +1,41 @@
+(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 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))