Browse Source

track leading car no, make more fabulous

master
eta 3 months ago
parent
commit
6b63434a96
  1. 2
      deploy.txt
  2. 48
      trackernet.lisp

2
deploy.txt

@ -1,4 +1,4 @@
(ql:quickload '(drakma cl-conspack cxml cl-statsd cl-redis qbase64 archive))
(ql:quickload '(drakma cl-conspack cxml cl-statsd cl-redis qbase64 archive cl-ansi-text))
(load "trackernet.lisp")
(sb-ext:save-lisp-and-die "./intertube-scraper" :toplevel #'trackernet::main :executable t)

48
trackernet.lisp

@ -406,7 +406,7 @@
(conspack:encode-to-file pred pathname))))
(defun redis-train (universal-ts line-code code-station train)
(with-slots (train-id set-no trip-no lcid seconds-to track-code location-desc) train
(with-slots (train-id set-no trip-no lcid seconds-to track-code location-desc leading-car-no) train
(when (and (or lcid train-id) seconds-to track-code)
(let ((tid (or (if (and lcid (string= lcid "0"))
nil
@ -433,16 +433,46 @@
;; log the new train
(unless (red:exists (format nil "~A-active-~A"
line-code tid))
(format t "~&scraper(~A): new ~A: ~A~%"
(format t "~&scraper(~A): ~Anew ~A~A: ~A~%"
code-station
(cl-ansi-text:make-color-string :green :style :background)
tid
cl-ansi-text:+reset-color-string+
train))
;; mark this train as active
(red:setex (format nil "~A-active-~A"
line-code tid)
*train-active-expiry-secs*
"yep")
(unless (string= set-no "000")
(unless (or (not leading-car-no) (string= leading-car-no "0")
(uiop:string-prefix-p "set" tid))
;; check whether the train's leading car no was previously
;; used by a train with a different id
(let ((lcn-train-id
(red:get
(format nil "~A-lcn-~A"
line-code leading-car-no))))
(when (and lcn-train-id
(not (string= lcn-train-id
tid)))
;; if so, it might be the same train
(format
*error-output*
"scraper(~A): ~Aleading car no ~A changed~A: ~A -> ~A~%"
code-station
(cl-ansi-text:make-color-string :yellow :style :background)
leading-car-no
cl-ansi-text:+reset-color-string+
lcn-train-id
tid)
(statsd:inc "intertube.leading-car-no-change")))
;; reserve the leading car no
(red:setex (format nil "~A-lcn-~A"
line-code leading-car-no)
*train-set-code-expiry-secs*
tid))
(unless (or (string= set-no "000")
(uiop:string-prefix-p "set" tid))
;; check whether the train's set number was previously
;; used by a train with a different id
(let ((set-code-train-id
@ -455,10 +485,12 @@
;; if so, it might be the same train
(format
*error-output*
"scraper(~A): WARNING: set code ~A (~A) changed: ~A -> ~A~%"
"scraper(~A): ~Aset code ~A (~A) changed~A: ~A -> ~A~%"
code-station
(cl-ansi-text:make-color-string :magenta :style :background)
set-no
trip-no
cl-ansi-text:+reset-color-string+
set-code-train-id
tid)
(statsd:inc "intertube.set-code-change")))
@ -578,7 +610,13 @@
for train in trains-data
do (let ((last-data
(third (car (last (car (last train)))))))
(format t "~&archiver: archiving ~A: ~A~%" (second train) last-data))
(format
t
"~&archiver: ~Aarchiving ~A~A: ~A~%"
(cl-ansi-text:make-color-string :red :style :background)
(second train)
cl-ansi-text:+reset-color-string+
last-data))
do (conspack-encode-to-archive tar
(format nil "~A-~A.trn"
(first train)

Loading…
Cancel
Save