clean up drops data

This commit is contained in:
2026-01-04 01:07:31 -05:00
parent 712361da86
commit 3f83ab9210
2 changed files with 18 additions and 1 deletions

View File

@@ -4,6 +4,15 @@
(defparameter *chronostory-drops-sheet-url* "https://docs.google.com/spreadsheets/d/e/2PACX-1vRpKuZGJQIFFxSi6kzYx4ALI0MQborpLEkh3J1qIGSd0Bw7U4NYg5CK-3ESzyK580z4D8NO59SUeC3k/pub?gid=1888753114&single=true&output=csv") (defparameter *chronostory-drops-sheet-url* "https://docs.google.com/spreadsheets/d/e/2PACX-1vRpKuZGJQIFFxSi6kzYx4ALI0MQborpLEkh3J1qIGSd0Bw7U4NYg5CK-3ESzyK580z4D8NO59SUeC3k/pub?gid=1888753114&single=true&output=csv")
(defun cleanup-data (hm)
(dolist (key '("DropperID" "ItemID" "Chance" "MinQTY" "MaxQTY"))
(update-hash hm key (lambda (x) (string-replace-all "," x "")))
(update-hash hm key #'parse-integer))
(update-hash hm "AvgQty" #'parse-float)
(dolist (key '("isBoss" "Enable" "InGame"))
(update-hash hm key #'string->bool))
hm)
(defmethod refresh ((ds drop-data-source)) (defmethod refresh ((ds drop-data-source))
(let* ((data (drakma:http-request *chronostory-drops-sheet-url*)) (let* ((data (drakma:http-request *chronostory-drops-sheet-url*))
(csv (cl-csv:read-csv data)) (csv (cl-csv:read-csv data))
@@ -12,7 +21,8 @@
(keys (mapcar #'string-to-hash-table-key (subseq header 0 num-fields-to-keep))) (keys (mapcar #'string-to-hash-table-key (subseq header 0 num-fields-to-keep)))
(drops (map 'vector (drops (map 'vector
(lambda (row) (lambda (row)
(pairhash keys (subseq row 0 num-fields-to-keep))) (cleanup-data
(pairhash keys (subseq row 0 num-fields-to-keep) (dict))))
(cdr csv)))) (cdr csv))))
(setf (cache ds) drops) (setf (cache ds) drops)
(write-string-into-file (write-string-into-file
@@ -23,4 +33,5 @@
(comment (comment
(defvar drops (make-drop-data-source)) (defvar drops (make-drop-data-source))
(refresh drops)
(reload drops)) (reload drops))

View File

@@ -20,6 +20,12 @@
(defun string-to-hash-table-key (s) (defun string-to-hash-table-key (s)
(string-replace " " s "")) (string-replace " " s ""))
(defun update-hash (hm key f)
(setf (@ hm key) (funcall f (@ hm key))))
(defun string->bool (s)
(if (string-equal (string-downcase s) "true") t nil))
(defclass data-source () (defclass data-source ()
((cache :initform nil :accessor cache) ((cache :initform nil :accessor cache)
(file-path :initarg :file-path :accessor file-path))) (file-path :initarg :file-path :accessor file-path)))