tracking: minor improvements; make building of track data configurable
This commit is contained in:
parent
69c3013332
commit
d363a3dde3
3 changed files with 13 additions and 8 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
(defpackage :scopes/shape
|
(defpackage :scopes/shape
|
||||||
(:use :common-lisp)
|
(:use :common-lisp)
|
||||||
|
(:local-nicknames (:util :scopes/util))
|
||||||
(:export #:record #:head-fields #:head #:data
|
(:export #:record #:head-fields #:head #:data
|
||||||
#:head-plist))
|
#:head-plist))
|
||||||
|
|
||||||
|
@ -14,9 +15,8 @@
|
||||||
(data :accessor data :initarg :data :initform nil)))
|
(data :accessor data :initarg :data :initform nil)))
|
||||||
|
|
||||||
(defun head-plist (track)
|
(defun head-plist (track)
|
||||||
(let (pl h (hv (head track)))
|
(let (pl (hv (head track)))
|
||||||
(dolist (hf (head-fields track))
|
(dolist (hf (head-fields track))
|
||||||
(setf h (pop hv))
|
(setf pl (cons hf (cons (util:keyword-to-string (pop hv)) pl))))
|
||||||
(setf (getf pl hf)
|
(log:info "pl: ~s" pl)
|
||||||
(if h (string-downcase h) "")))
|
|
||||||
pl))
|
pl))
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
|
|
||||||
(in-package :scopes/storage/tracking)
|
(in-package :scopes/storage/tracking)
|
||||||
|
|
||||||
|
(defvar *build-track-data* #'alx:hash-table-plist)
|
||||||
|
|
||||||
(defclass track (shape:record)
|
(defclass track (shape:record)
|
||||||
((trackid :accessor trackid :initform nil)
|
((trackid :accessor trackid :initform nil)
|
||||||
(time-stamp :accessor time-stamp :initform nil)
|
(time-stamp :accessor time-stamp :initform nil)
|
||||||
|
@ -45,8 +47,8 @@
|
||||||
(defun plist (track)
|
(defun plist (track)
|
||||||
(let ((vl (shape:head-plist track)))
|
(let ((vl (shape:head-plist track)))
|
||||||
(with-slots ((trid trackid) (ts time-stamp) (data shape:data)) track
|
(with-slots ((trid trackid) (ts time-stamp) (data shape:data)) track
|
||||||
(if trid (setf (getf vl :trackid) trid))
|
(when trid (setf (getf vl :trackid) trid))
|
||||||
(if ts (setf (getf vl :timestamp) (timestamp-to-sql track ts)))
|
(when ts (setf (getf vl :timestamp) (timestamp-to-sql track ts)))
|
||||||
(when data
|
(when data
|
||||||
(unless (hash-table-p data)
|
(unless (hash-table-p data)
|
||||||
(setf data (alx:plist-hash-table data)))
|
(setf data (alx:plist-hash-table data)))
|
||||||
|
@ -84,7 +86,7 @@
|
||||||
(setf (trackid tr) (getf row :trackid))
|
(setf (trackid tr) (getf row :trackid))
|
||||||
(setf (time-stamp tr) (getf row :timestamp))
|
(setf (time-stamp tr) (getf row :timestamp))
|
||||||
(setf (shape:data tr)
|
(setf (shape:data tr)
|
||||||
(alx:hash-table-plist
|
(funcall *build-track-data*
|
||||||
(jzon:parse (getf row :data) :key-fn #'util:to-keyword)))
|
(jzon:parse (getf row :data) :key-fn #'util:to-keyword)))
|
||||||
tr))
|
tr))
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
(defpackage :scopes/util
|
(defpackage :scopes/util
|
||||||
(:use :common-lisp)
|
(:use :common-lisp)
|
||||||
(:export #:flatten-str #:to-keyword #:to-string
|
(:export #:flatten-str #:to-keyword #:keyword-to-string #:to-string
|
||||||
#:loop-plist
|
#:loop-plist
|
||||||
#:absolute-dir #:check-dir #:ensure-dir #:home-path #:path-from-string
|
#:absolute-dir #:check-dir #:ensure-dir #:home-path #:path-from-string
|
||||||
#:relative-path #:runtime-path #:system-path))
|
#:relative-path #:runtime-path #:system-path))
|
||||||
|
@ -16,6 +16,9 @@
|
||||||
(mapcar (lambda (x) (str:trim x))
|
(mapcar (lambda (x) (str:trim x))
|
||||||
(str:lines s))))
|
(str:lines s))))
|
||||||
|
|
||||||
|
(defun keyword-to-string (k)
|
||||||
|
(if k (string-downcase k) ""))
|
||||||
|
|
||||||
(defun to-string (k &key (sep " ") lower-case)
|
(defun to-string (k &key (sep " ") lower-case)
|
||||||
(let ((pattern (if lower-case "~(~a~)" "~a")))
|
(let ((pattern (if lower-case "~(~a~)" "~a")))
|
||||||
(if (atom k)
|
(if (atom k)
|
||||||
|
|
Loading…
Add table
Reference in a new issue