-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresultset-extracter.lisp
40 lines (30 loc) · 1.33 KB
/
resultset-extracter.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(defpackage :rs-extracter
(:use :cl :data :utils)
(:export :get-basic-resultset
:after
:get-resultset))
(in-package :rs-extracter)
(defun get-basic-resultset (order-list &key headers)
(cons headers (get-index+values order-list)))
(defun get-resultset (headers &rest predicates)
(let* ((filtered-orders (remove-if-not (lambda (order) (test order predicates)) *orders*))
(resultset (mapcar #'data:order->list filtered-orders ))
(indexed-resultset (add-index-to-row resultset))
(resultset-with-headers (cons headers indexed-resultset))
(sum (data:calculate-sum filtered-orders))
(resultset-with-sum-appended (reverse
(cons (list "" "Сумма:" (write-to-string sum) "")
(reverse resultset-with-headers)))))
resultset-with-sum-appended))
(defun test (arg predicates)
(let ((result t))
(loop for p in predicates do
(setf result (and result (funcall p arg))))
result))
(defun add-index-to-row (resultset)
(let ((index 0))
(mapcar (lambda (row) (cons (write-to-string (incf index)) row)) resultset)))
(defun after (timestamp)
(lambda (order) (> (data::timestamp-of order) timestamp)))
(defun name-like (name)
(lambda (order) (equal (data::name-of order) name)))