forked from zhef/cl-eshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwolfor-stuff.lisp
199 lines (171 loc) · 6.98 KB
/
wolfor-stuff.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
(defpackage #:wolfor-stuff
(:use #:cl))
(in-package #:wolfor-stuff)
(defun num-active-product (products)
(let ((num 0))
(mapcar #'(lambda (p)
(if (eshop::active p)
(incf num)))
products)
num))
(defun sum-siteprices-product (products)
(let ((sum 0))
(mapcar #'(lambda (p)
(if (eshop::active p)
(setf sum (+
(eshop::siteprice p)
sum))))
products)
sum))
(defun sum-prices-product (products)
(let ((sum 0))
(mapcar #'(lambda (p)
(if (eshop::active p)
(setf sum (+
(eshop::price p)
sum))))
products)
sum))
(defun get-products-list ()
(let ((product-list))
(maphash #'(lambda (k v)
(declare (ignore k))
(if (equal (type-of v)
'eshop::product)
(setf product-list (cons v product-list ))))
eshop:*storage* )
product-list))
(defun get-group-routs ()
(let ((routs))
(maphash #'(lambda (k g)
(declare (ignore k))
(if (and (equal (type-of g)
'eshop::group)
(null (eshop::parent g)))
(setf routs (cons g routs))))
eshop:*storage*)
routs))
(defun get-group-active ()
(let ((routs))
(maphash #'(lambda (k g)
(declare (ignore k))
(if (and (equal (type-of g)
'eshop::group)
(eshop::active g))
(setf routs (cons g routs))))
eshop:*storage*)
routs))
(defun get-group-ymlshow ()
(let ((routs))
(maphash #'(lambda (k g)
(declare (ignore k))
(if (and (equal (type-of g)
'eshop::group)
(eshop::ymlshow g))
(setf routs (cons g routs))))
eshop:*storage*)
routs))
(defun show-group (g n)
(format t "~&~Va: ~a | yml:~a active:~a продуктов:~a (key:~a)"
n
""
(eshop::name g)
(eshop::ymlshow g)
(eshop::active g)
(length (eshop::get-recursive-products g))
(eshop::key g))
(mapcar #'(lambda (g)
(show-group g (+ n 5)))
(eshop::childs g)))
(defun num-product-in-groups (groups)
(let ((num 0))
(mapcar #'(lambda (g)
(setf num (+ num
(length (remove-if
#'(lambda(g)
(not (eshop::active g)))
(eshop::products g))))))
groups)
num))
(defun num-active-product-with-bad-price ()
(length (remove-if #'(lambda(p) (or (not (eshop::active p))
(and (not (null (eshop::price p)))
(> (eshop::siteprice p) 0))))
(get-products-list))))
(defun get-group-ymlshow()
(let ((result))
(maphash #'(lambda(k g)
(declare (ignore k))
(if (and (equal (type-of g)
'eshop::group)
(eshop::ymlshow g))
(push g result)))
eshop:*storage*)
result))
(defun get-groups-products(groups)
(let ((result))
(mapcar #'(lambda(g)
(setf result
(append result
(eshop::products g))))
groups)
result))
(defun statistics ()
(mapcar #'(lambda (g) (show-group g 0)) (get-group-routs))
(format t "~&Количество товаров на сайте: ~a" (list-length (get-products-list)))
(format t "~&Количество активных товаров: ~a" (num-active-product (get-products-list)))
(format t "~&Количество товаров для YML: ~a" (num-product-in-groups (get-group-ymlshow)))
(format t "~&Средняя цена товара в магазине: ~5$" (let ((n (num-active-product (get-products-list))))
(if (not (= n 0))
(/ (sum-prices-product (get-products-list))
n)
0)))
(format t "~&Средняя цена товара на сайте: ~5$" (let ((n (num-active-product (get-products-list))))
(if (not (= n 0))
(/ (sum-siteprices-product (get-products-list))
n)
0)))
(format t "~&Количество групп: ~a" (let ((num 0))
(maphash #'(lambda(k v)
(declare (ignore k))
(if (equal (type-of v)
'eshop::group)
(incf num)))
eshop:*storage*)
num))
(format t "~&Количество активных групп: ~a" (length (get-group-active)))
(format t "~&Количество YML групп: ~a" (length (get-group-ymlshow)))
(format t "~&Количество активных товаров с нулевой ценой: ~a" (num-active-product-with-bad-price))
(format t "~&~a" ""))
;; (let ((num 0))
;; (maphash
;; #'(lambda (k product)
;; (if (and (not (null (product:parent product)))
;; (group:ymlshow (product:parent product))
;; (product:active product)
;; (not (null (product:price product)))
;; (> (product:price product) 0))
;; (incf num)))
;; trans:*product*) num)
;; (maphash #'(lambda (k v)
;; (if (not (= (num-products-in-group v)
;; (length (group:products v))))
;; (format t "~&~a ~a:~a"
;; (group:key v)
;; (num-products-in-group v)
;; (length (group:products v)))))
;; trans:*group*)
;; (length
;; (mapcar #'(lambda (v)
;; (format nil "> ~a" (product:parent v)))
;; (group:products (gethash "pamyat-dlya-noutbukov" trans:*group*))))
;; :keywords (format nil "" )
;; :description (format nil "")
;; :title (format nil "")
;; (defvar *test-request*)
(defun set-recursive-yml (group flag)
(mapcar #'(lambda (g)
(format t "~&~a" (eshop::name g))
(setf (eshop::ymlshow g) flag)
(set-recursive-yml g flag))
(eshop::childs group)))