final debugging
[rrq/hourglass.git] / control-logic.lsp
index c842c06eee67d320d6270d87548e66ec80baf1b6..2d2cd3e4efcac3ed4824390b071bda48bd59cc20 100644 (file)
@@ -9,7 +9,15 @@
   (write-line 2 (join (map string args)))
   (exit 1))
 
   (write-line 2 (join (map string args)))
   (exit 1))
 
-(constant 'NOW (date-value))
+(constant
+ 'NOW (date-value)
+ 'ACTDIR SITE:listener.activity.dir
+ 'CONTROL.DAT SITE:control.dat
+ 'EXTRA.DAT SITE:control.extra.dat
+ 'USAGE.DAT SITE:control.usage.dat
+ 'USAGE.TMP SITE:control.usage.tmp
+ 'ACTION SITE:control.action
+ )
 
 # Set current time variables in local timezone
 (map set '(YEAR MONTH DATE HOUR MINUTE SECOND DOY DOW)
 
 # Set current time variables in local timezone
 (map set '(YEAR MONTH DATE HOUR MINUTE SECOND DOY DOW)
  DAY (list YEAR MONTH DATE)
  HM (list HOUR MINUTE)
  TOTAL '()
  DAY (list YEAR MONTH DATE)
  HM (list HOUR MINUTE)
  TOTAL '()
- CONTROL.DAT "control.dat"
- EXTRA.DAT "control-extra.dat"
- USAGE.DAT "usage.dat"
- USAGE.TMP ".usage.dat" 
+ GAP SITE:control.activity.gap
+ CLIP SITE:control.activity.clip
  )
 
 # Load CONTROL.DAT
  )
 
 # Load CONTROL.DAT
-# ( (control "file") (gap minutes) ( weekday start limit stop ) ... )
+# (( weekday start limit stop ) ... )
 (setf CONTROL (read-expr (or (read-file CONTROL.DAT)
                              (die "** Missing " CONTROL.DAT " ** Exiting."))
                          ))
 (setf CONTROL (read-expr (or (read-file CONTROL.DAT)
                              (die "** Missing " CONTROL.DAT " ** Exiting."))
                          ))
+
+(write-line 2 (string (list CONTROL DOW)))
+
 (map set '(dow MODE START LIMIT END)
      (or (assoc DOW CONTROL)
          (assoc 'policy CONTROL)
          (list DOW (6 30) 120 (20 0)))
      )
 
 (map set '(dow MODE START LIMIT END)
      (or (assoc DOW CONTROL)
          (assoc 'policy CONTROL)
          (list DOW (6 30) 120 (20 0)))
      )
 
-(setf
- GAP (or (lookup 'gap CONTROL) 15)
- CLIP (or (lookup 'clip CONTROL) 1000)
- NET  (or (lookup 'net CONTROL) "10.0.0.0/8")
- )
-
 # Load the configured control mechanism
 # Load the configured control mechanism
-(if (lookup 'control CONTROL) (load $it)
+(if (file? ACTION) (load ACTION)
   (die "** Unknown control mechanism. Exiting!!"))
 (unless control
   (die "** Unknown control mechanism. Exiting!!"))
 (unless control
-    (die "** Control function (control cmd reason) not defined. Exiting!!"))
+  (die "** Control function (control cmd reason) not defined. Exiting!!"))
 
 ;; Apply control command with reason, then exit
 (define (do-control x r) (control x r) (exit 0))
 
 ;; Apply control command with reason, then exit
 (define (do-control x r) (control x r) (exit 0))
 ;;==== Utilities for activity data
 # Activity is lines of timestamps. Collect TOTAL as list of unique
 # time values (H M) within the start-end time span.
 ;;==== Utilities for activity data
 # Activity is lines of timestamps. Collect TOTAL as list of unique
 # time values (H M) within the start-end time span.
+
 (define (log-name-fmt t)
   (format "%d%02d%02d-.*\\.dat" (0 3 (date-list t))))
 
 (define (log-lines f)
 (define (log-name-fmt t)
   (format "%d%02d%02d-.*\\.dat" (0 3 (date-list t))))
 
 (define (log-lines f)
-  (find-all "([0-9]+( \\S+)?).*" (read-file (string "activity/" f)) $1 0))
+  (find-all "([0-9]+( \\S+)?).*" (read-file (format "%s/%s" ACTDIR f)) $1 0))
 
 # Collect all timestamps of the UTC date of the given time stamp
 (define (logs t)
 
 # Collect all timestamps of the UTC date of the given time stamp
 (define (logs t)
-  (flat (map log-lines (directory "activity" (log-name-fmt t)))))
+  (flat (map log-lines (directory ACTDIR (log-name-fmt t)))))
 
 # Translate timestamp into its local time (hour minute), if it's
 # within the applicable day, null otherwise.
 
 # Translate timestamp into its local time (hour minute), if it's
 # within the applicable day, null otherwise.