Compare commits

..
10 Commits
Author SHA1 Message Date
jlamothe df2a9a70b3 defined pt-get-body 2025-05-12 18:01:59 -04:00
jlamothe 7e2b9f3dde variable rename 2025-05-12 16:14:19 -04:00
jlamothe f253c63db3 minor stylistic change 2025-05-12 10:15:17 -04:00
jlamothe accb675a7e fixed pt-get-columns 2025-05-12 09:51:10 -04:00
jlamothe 03277714ba partial implementation of pt-get-columns 2025-05-12 00:04:24 -04:00
jlamothe 9c84a8153a removed unnecessary variable 2025-05-12 00:04:03 -04:00
jlamothe 3d0c20a5dd params is a plist 2025-05-11 22:33:52 -04:00
jlamothe a2beb6635a &key isn't valid? 2025-05-11 22:04:45 -04:00
jlamothe e5b0de99e2 partial definition of pt-build 2025-05-11 21:43:50 -04:00
jlamothe 9ec5c5ea6f prefix shorthand 2025-05-11 15:10:31 -04:00
+44
View File
@@ -23,4 +23,48 @@
;;; Code: ;;; Code:
(defun pt-build (source &rest params)
"Build a pivot table
TODO: more documentation"
(let* ((rows (plist-get params :rows))
(cols (plist-get params :cols))
(vals (plist-get params :vals))
(col-index (pt-get-columns source))
src-cols
(src-body (pt-get-body source))
(buckets (make-hash-table)))
(pt--index-columns rows)
(pt--index-columns cols)
(pt--index-columns vals car)
(sort src-cols #'<)
(dolist (record src-body)
(pt--process-record record source-cols buckets))))
(defun pt-get-columns (table)
"Extract the column names from a table"
(let (result)
(dolist (row table)
(when (and (listp row) (equal (car row) "!"))
(let ((n 2))
(dolist (cell (cdr row))
(unless (equal cell "")
(push (cons (format "%s" cell) n) result))
(setq n (1+ n))))))
result))
(defun pt-get-body (source)
"Discards all rows from a table before the first hline (if present)
If there is no hline, the table is instead returned unaltered."
(catch :return
(let ((remain source))
(while remain
(when (eq (car remain) 'hline)
(throw :return (cdr remain)))
(pop remain))
source)))
;; Local Variables:
;; read-symbol-shorthands: (("pt-" . "pivot-table-"))
;; End:
;;; pivot-table.el ends here ;;; pivot-table.el ends here