Files
pivot-table/pivot-table.el

57 lines
1.9 KiB
EmacsLisp

;;; pivot-table.el --- Build org-mode pivot tables
;; Copyright (C) 2025 Jonathan Lamothe
;; Author: Jonathan Lamothe <jonathan@jlamothe.net>
;; Package-Version: 0.0
;; This file is not part of GNU Emacs.
;; This program is free software: you can redistribute it and/or
;; modify it under the terms of the GNU Affero 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
;; Affero General Public License for more details.
;; You should have received a copy of the GNU Affero General Public
;; License along with this program. If not, see
;; <https://www.gnu.org/licenses/>.
;;; Code:
(defun pt-build (source &key rows cols vals)
"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)))
(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))))
;; Local Variables:
;; read-symbol-shorthands: (("pt-" . "pivot-table-"))
;; End:
;;; pivot-table.el ends here