Compare commits
8
Commits
e5b0de99e2
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df2a9a70b3 | ||
|
|
7e2b9f3dde | ||
|
|
f253c63db3 | ||
|
|
accb675a7e | ||
|
|
03277714ba | ||
|
|
9c84a8153a | ||
|
|
3d0c20a5dd | ||
|
|
a2beb6635a |
+31
-17
@@ -23,25 +23,16 @@
|
||||
|
||||
;;; Code:
|
||||
|
||||
(defun pt-build (source &key rows cols vals)
|
||||
(defun pt-build (source &rest params)
|
||||
"Build a pivot table
|
||||
|
||||
The SOURCE value should be the table the data is being taken
|
||||
from. ROWS and COLS should be lists of column references from
|
||||
the source table to be used as rows and columns for the pivot
|
||||
table. These can either be integers representing the column
|
||||
number, or strings representing column names.
|
||||
|
||||
VALUES should be a list containing information about the values
|
||||
in the body of the pivot table. Each element of the list should
|
||||
be in the following format (REF FUNC &optional LABEL).
|
||||
|
||||
TODO: more documentation"
|
||||
(let ((col-index (pt-get-columns source))
|
||||
(index (pt-column-names source))
|
||||
src-cols
|
||||
(src-body (pt-get-body source))
|
||||
(buckets (make-hash-table)))
|
||||
(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)
|
||||
@@ -49,6 +40,29 @@ TODO: more documentation"
|
||||
(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:
|
||||
|
||||
Reference in New Issue
Block a user