Text processing/Max licenses in use: Difference between revisions

cleanup, and show use of CL-PPCRE for extracting IN/OUT and the time
m (Common Lisp Max License entry)
(cleanup, and show use of CL-PPCRE for extracting IN/OUT and the time)
Line 123:
 
=={{header|Common Lisp}}==
 
{{trans|Python}} {{libheader|CL-PPCRE}}
 
<lang lisp>(defun max-licenses (&optional (logfile "mlijobs.txt"))
(with-open-file (log logfile :direction :input)
(do ((current-logs 0) (max-logs 0) (max-log-times '())
(max-logs 0)
(max-log-times '())
(line #1=(read-line log nil nil) #1#))
((null line)
(format t "~&Maximum simultaneous license use is ~w at the ~
at the following timestime~p: ~{~% ~a~}."
max-logs (length max-log-times) (nreverse max-log-times)))
(cl-ppcre:register-groups-bind (op time)
(cond
((search ("License OUT(\\b.*\\b)[ ]{1,2}@ (\\b.*\\b)" line)
(cond ((string= "OUT" op) (incf current-logs))
((string= "IN" op) (decf current-logs))
(cond
(t (cerror "Ignore it." "Malformed entry ~s." line))))))</lang>
((> current-logs max-logs)
(cond (setf(> maxcurrent-logs currentmax-logs)
(setf max-loglogs current-times (list (subseq line 14 33))))logs
((= current-logs max-logslog-times (list time)))
(push (subseq line 14 33)((= maxcurrent-loglogs max-times)))logs)
(push time max-log-times '()))))))</lang>
((search "License IN" line)
(decf current-logs))
(t (cerror "Ignore it." "Malformed entry ~s." line))))))</lang>
 
<pre>> (max-licenses)
Anonymous user