|
@@ -196,32 +196,35 @@
|
|
|
usd eur gbp brent
|
|
usd eur gbp brent
|
|
|
(format-ts (local-time:unix-to-timestamp ts))))))
|
|
(format-ts (local-time:unix-to-timestamp ts))))))
|
|
|
|
|
|
|
|
|
|
+(defparameter +chart-ranges+ (list (cons "day" (* 24 60))
|
|
|
|
|
+ (cons "week" (* 7 24 60))
|
|
|
|
|
+ (cons "month" (* 30 24 60))
|
|
|
|
|
+ (cons "quarter" (* 91 24 60))
|
|
|
|
|
+ (cons "year" (* 365 24 60))))
|
|
|
|
|
+
|
|
|
(defun handle-cmd-charts (chat-id message-id args)
|
|
(defun handle-cmd-charts (chat-id message-id args)
|
|
|
(log:info "handle-cmd-charts" chat-id message-id args)
|
|
(log:info "handle-cmd-charts" chat-id message-id args)
|
|
|
(telegram-send-chat-action chat-id "upload_photo")
|
|
(telegram-send-chat-action chat-id "upload_photo")
|
|
|
(handler-case
|
|
(handler-case
|
|
|
- (let* ((usd (or (null args) (find "usd" args :test #'equal)))
|
|
|
|
|
- (eur (or (null args) (find "eur" args :test #'equal)))
|
|
|
|
|
- (gbp (or (null args) (find "gbp" args :test #'equal)))
|
|
|
|
|
- (brent (or (null args) (find "brent" args :test #'equal)))
|
|
|
|
|
- (avg (or (some #'(lambda (a)
|
|
|
|
|
- (when (find (princ-to-string a) args :test #'equal)
|
|
|
|
|
- (* a 60)))
|
|
|
|
|
- '(240 60 30 15 10 6 5 4 3 2 1))
|
|
|
|
|
- 60))
|
|
|
|
|
- (rates (multiple-value-list (db-get-last-finance))))
|
|
|
|
|
- (if (or usd eur gbp brent)
|
|
|
|
|
- (let ((data (db-get-series
|
|
|
|
|
- (local-time:timestamp- (local-time:now)
|
|
|
|
|
- (* 800 avg) :sec)
|
|
|
|
|
- usd eur gbp brent avg)))
|
|
|
|
|
- (telegram-send-photo chat-id
|
|
|
|
|
- (make-chart data :usd usd :eur eur :gbp gbp :brent brent)
|
|
|
|
|
- :caption
|
|
|
|
|
- (format nil "Зеленый ~,2F, гейро ~,2F, британец ~,2F, чёрная ~,2F @ ~A"
|
|
|
|
|
- (elt rates 1) (elt rates 2) (elt rates 3) (elt rates 4)
|
|
|
|
|
- (format-ts (local-time:unix-to-timestamp (elt rates 0))))))
|
|
|
|
|
- (telegram-send-message chat-id "Хуй тебе")))
|
|
|
|
|
|
|
+ (let* ((args (mapcar 'string-downcase args))
|
|
|
|
|
+ (all-fields (mapcar #'car +db-finance-map+))
|
|
|
|
|
+ (fields (or (intersection args all-fields :test 'equal) all-fields))
|
|
|
|
|
+ (day-range (some #'(lambda (a) (aget a +chart-ranges+)) args))
|
|
|
|
|
+ (number (some #'(lambda (a) (parse-integer a :junk-allowed t)) args))
|
|
|
|
|
+ (avg (* 60 (cond
|
|
|
|
|
+ (day-range (round day-range *chart-points*))
|
|
|
|
|
+ (number)
|
|
|
|
|
+ (:otherwise 1))))
|
|
|
|
|
+ (after-ts (local-time:timestamp- (local-time:now)
|
|
|
|
|
+ (* avg *chart-points*) :sec))
|
|
|
|
|
+ (rates (multiple-value-list (db-get-last-finance)))
|
|
|
|
|
+ (chart (apply #'make-chart (multiple-value-list
|
|
|
|
|
+ (db-get-series after-ts fields avg)))))
|
|
|
|
|
+ (telegram-send-photo chat-id chart
|
|
|
|
|
+ :caption
|
|
|
|
|
+ (format nil "Зеленый ~,2F, гейро ~,2F, британец ~,2F, чёрная ~,2F @ ~A"
|
|
|
|
|
+ (elt rates 1) (elt rates 2) (elt rates 3) (elt rates 4)
|
|
|
|
|
+ (format-ts (local-time:unix-to-timestamp (elt rates 0))))))
|
|
|
(error (e)
|
|
(error (e)
|
|
|
(log:error e)
|
|
(log:error e)
|
|
|
(telegram-send-message chat-id "Хуйня какая-то"))))
|
|
(telegram-send-message chat-id "Хуйня какая-то"))))
|