From 3f83ab92106f961f260ebfb3230e89d4aa6a1137 Mon Sep 17 00:00:00 2001 From: Grant Horner Date: Sun, 4 Jan 2026 01:07:31 -0500 Subject: [PATCH] clean up drops data --- drops.lisp | 13 ++++++++++++- utils.lisp | 6 ++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/drops.lisp b/drops.lisp index 61b99ee..036d907 100644 --- a/drops.lisp +++ b/drops.lisp @@ -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") +(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)) (let* ((data (drakma:http-request *chronostory-drops-sheet-url*)) (csv (cl-csv:read-csv data)) @@ -12,7 +21,8 @@ (keys (mapcar #'string-to-hash-table-key (subseq header 0 num-fields-to-keep))) (drops (map 'vector (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)))) (setf (cache ds) drops) (write-string-into-file @@ -23,4 +33,5 @@ (comment (defvar drops (make-drop-data-source)) + (refresh drops) (reload drops)) diff --git a/utils.lisp b/utils.lisp index 1b37d45..a08022b 100644 --- a/utils.lisp +++ b/utils.lisp @@ -20,6 +20,12 @@ (defun string-to-hash-table-key (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 () ((cache :initform nil :accessor cache) (file-path :initarg :file-path :accessor file-path)))