diff options
Diffstat (limited to 'webstats/server.lisp')
-rw-r--r-- | webstats/server.lisp | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/webstats/server.lisp b/webstats/server.lisp index 44dbe89..6c74b3e 100644 --- a/webstats/server.lisp +++ b/webstats/server.lisp @@ -1,4 +1,4 @@ -(ql:quickload '(hunchentoot spinneret cl-yesql cl-yesql/sqlite parenscript)) +(ql:quickload '(hunchentoot spinneret cl-yesql cl-yesql/sqlite parenscript cl-json)) (defpackage :webstats (:use :common-lisp :hunchentoot :spinneret)) @@ -96,3 +96,33 @@ (:input :type "text" :name "title") (:input :type "submit" :value "submit" :name "submit")))) )) + +(hunchentoot:define-easy-handler (metric :uri "/metric.json") (q) + (setf (hunchentoot:content-type*) "application/json") + (sqlite:with-open-database (db "test.db") + (let ((series (activity-stats db))) + (cl-json:encode-json-to-string + (apply #'mapcar #'list series))))) + +(hunchentoot:define-easy-handler (graphs :uri "/graphs") () + (with-html-string + (:doctype) + (:html + (:head (:title "hu yu ipi") + (:meta :charset "utf-8") + (:link :rel "stylesheet" :href "/webstats/static/uPlot.min.css") + (:script :async t :src "/webstats/static/uPlot.iife.min.js" :type "text/javascript") + (:script :async t :src "/stats/stats.js" :type "text/javascript") + (:script :async t :src "http://127.0.0.1:8095/skewer")) + (:body + (:h1 "great graph stats") + (:div :id "graph") + (:script + (:raw + (ps:ps + (add-event-listener + "load" + (lambda () + (ps:chain (fetch "/stats/metric.json") + (then #'response-to-json) + (then #'plot))))))))))) |