Artifact
253156d2fd06eedd7e6d869099268743e3c92026:
0000: 3b 3b 20 20 43 6f 70 79 72 69 67 68 74 20 32 30 ;; Copyright 20
0010: 30 36 2d 32 30 31 37 2c 20 4d 61 74 74 68 65 77 06-2017, Matthew
0020: 20 57 65 6c 6c 61 6e 64 2e 0a 3b 3b 20 0a 3b 3b Welland..;; .;;
0030: 20 54 68 69 73 20 66 69 6c 65 20 69 73 20 70 61 This file is pa
0040: 72 74 20 6f 66 20 4d 65 67 61 74 65 73 74 2e 0a rt of Megatest..
0050: 3b 3b 20 0a 3b 3b 20 20 20 20 20 4d 65 67 61 74 ;; .;; Megat
0060: 65 73 74 20 69 73 20 66 72 65 65 20 73 6f 66 74 est is free soft
0070: 77 61 72 65 3a 20 79 6f 75 20 63 61 6e 20 72 65 ware: you can re
0080: 64 69 73 74 72 69 62 75 74 65 20 69 74 20 61 6e distribute it an
0090: 64 2f 6f 72 20 6d 6f 64 69 66 79 0a 3b 3b 20 20 d/or modify.;;
00a0: 20 20 20 69 74 20 75 6e 64 65 72 20 74 68 65 20 it under the
00b0: 74 65 72 6d 73 20 6f 66 20 74 68 65 20 47 4e 55 terms of the GNU
00c0: 20 47 65 6e 65 72 61 6c 20 50 75 62 6c 69 63 20 General Public
00d0: 4c 69 63 65 6e 73 65 20 61 73 20 70 75 62 6c 69 License as publi
00e0: 73 68 65 64 20 62 79 0a 3b 3b 20 20 20 20 20 74 shed by.;; t
00f0: 68 65 20 46 72 65 65 20 53 6f 66 74 77 61 72 65 he Free Software
0100: 20 46 6f 75 6e 64 61 74 69 6f 6e 2c 20 65 69 74 Foundation, eit
0110: 68 65 72 20 76 65 72 73 69 6f 6e 20 33 20 6f 66 her version 3 of
0120: 20 74 68 65 20 4c 69 63 65 6e 73 65 2c 20 6f 72 the License, or
0130: 0a 3b 3b 20 20 20 20 20 28 61 74 20 79 6f 75 72 .;; (at your
0140: 20 6f 70 74 69 6f 6e 29 20 61 6e 79 20 6c 61 74 option) any lat
0150: 65 72 20 76 65 72 73 69 6f 6e 2e 0a 3b 3b 20 0a er version..;; .
0160: 3b 3b 20 20 20 20 20 4d 65 67 61 74 65 73 74 20 ;; Megatest
0170: 69 73 20 64 69 73 74 72 69 62 75 74 65 64 20 69 is distributed i
0180: 6e 20 74 68 65 20 68 6f 70 65 20 74 68 61 74 20 n the hope that
0190: 69 74 20 77 69 6c 6c 20 62 65 20 75 73 65 66 75 it will be usefu
01a0: 6c 2c 0a 3b 3b 20 20 20 20 20 62 75 74 20 57 49 l,.;; but WI
01b0: 54 48 4f 55 54 20 41 4e 59 20 57 41 52 52 41 4e THOUT ANY WARRAN
01c0: 54 59 3b 20 77 69 74 68 6f 75 74 20 65 76 65 6e TY; without even
01d0: 20 74 68 65 20 69 6d 70 6c 69 65 64 20 77 61 72 the implied war
01e0: 72 61 6e 74 79 20 6f 66 0a 3b 3b 20 20 20 20 20 ranty of.;;
01f0: 4d 45 52 43 48 41 4e 54 41 42 49 4c 49 54 59 20 MERCHANTABILITY
0200: 6f 72 20 46 49 54 4e 45 53 53 20 46 4f 52 20 41 or FITNESS FOR A
0210: 20 50 41 52 54 49 43 55 4c 41 52 20 50 55 52 50 PARTICULAR PURP
0220: 4f 53 45 2e 20 20 53 65 65 20 74 68 65 0a 3b 3b OSE. See the.;;
0230: 20 20 20 20 20 47 4e 55 20 47 65 6e 65 72 61 6c GNU General
0240: 20 50 75 62 6c 69 63 20 4c 69 63 65 6e 73 65 20 Public License
0250: 66 6f 72 20 6d 6f 72 65 20 64 65 74 61 69 6c 73 for more details
0260: 2e 0a 3b 3b 20 0a 3b 3b 20 20 20 20 20 59 6f 75 ..;; .;; You
0270: 20 73 68 6f 75 6c 64 20 68 61 76 65 20 72 65 63 should have rec
0280: 65 69 76 65 64 20 61 20 63 6f 70 79 20 6f 66 20 eived a copy of
0290: 74 68 65 20 47 4e 55 20 47 65 6e 65 72 61 6c 20 the GNU General
02a0: 50 75 62 6c 69 63 20 4c 69 63 65 6e 73 65 0a 3b Public License.;
02b0: 3b 20 20 20 20 20 61 6c 6f 6e 67 20 77 69 74 68 ; along with
02c0: 20 4d 65 67 61 74 65 73 74 2e 20 20 49 66 20 6e Megatest. If n
02d0: 6f 74 2c 20 73 65 65 20 3c 68 74 74 70 3a 2f 2f ot, see <http://
02e0: 77 77 77 2e 67 6e 75 2e 6f 72 67 2f 6c 69 63 65 www.gnu.org/lice
02f0: 6e 73 65 73 2f 3e 2e 0a 3b 3b 0a 28 75 73 65 20 nses/>..;;.(use
0300: 66 6f 6f 66 2d 6c 6f 6f 70 20 73 71 6c 2d 64 65 foof-loop sql-de
0310: 2d 6c 69 74 65 20 70 6f 73 69 78 29 0a 0a 28 64 -lite posix)..(d
0320: 65 66 69 6e 65 20 62 65 67 69 6e 6e 69 6e 67 2d efine beginning-
0330: 32 30 31 36 20 31 34 35 31 36 33 36 34 33 35 2e 2016 1451636435.
0340: 30 29 0a 28 64 65 66 69 6e 65 20 6e 6f 77 20 28 0).(define now (
0350: 63 75 72 72 65 6e 74 2d 73 65 63 6f 6e 64 73 29 current-seconds)
0360: 29 0a 28 64 65 66 69 6e 65 20 6f 6e 65 2d 79 65 ).(define one-ye
0370: 61 72 2d 61 67 6f 20 28 2d 20 6e 6f 77 20 28 2a ar-ago (- now (*
0380: 20 33 36 35 20 32 34 20 36 30 20 36 30 29 29 29 365 24 60 60)))
0390: 0a 0a 28 64 65 66 69 6e 65 20 64 62 20 28 6f 70 ..(define db (op
03a0: 65 6e 2d 64 61 74 61 62 61 73 65 20 22 65 78 61 en-database "exa
03b0: 6d 70 6c 65 2e 64 62 22 29 29 0a 0a 28 65 78 65 mple.db"))..(exe
03c0: 63 20 28 73 71 6c 20 64 62 20 22 43 52 45 41 54 c (sql db "CREAT
03d0: 45 20 54 41 42 4c 45 20 49 46 20 4e 4f 54 20 45 E TABLE IF NOT E
03e0: 58 49 53 54 53 20 61 6c 6c 64 61 74 20 28 65 76 XISTS alldat (ev
03f0: 65 6e 74 5f 74 69 6d 65 2c 76 61 72 2c 76 61 6c ent_time,var,val
0400: 29 22 29 29 0a 20 0a 3b 3b 20 73 69 6e 28 74 69 )")). .;; sin(ti
0410: 6d 65 29 0a 28 77 69 74 68 2d 74 72 61 6e 73 61 me).(with-transa
0420: 63 74 69 6f 6e 0a 20 64 62 0a 20 28 6c 61 6d 62 ction. db. (lamb
0430: 64 61 20 28 29 0a 20 20 20 28 6c 6f 6f 70 20 28 da (). (loop (
0440: 28 66 6f 72 20 6d 20 28 75 70 2d 66 72 6f 6d 20 (for m (up-from
0450: 28 2f 20 6f 6e 65 2d 79 65 61 72 2d 61 67 6f 20 (/ one-year-ago
0460: 36 30 29 20 28 74 6f 20 28 2f 20 6e 6f 77 20 36 60) (to (/ now 6
0470: 30 29 29 29 29 29 20 3b 3b 20 64 61 79 73 20 6f 0))))) ;; days o
0480: 66 20 74 68 65 20 79 65 61 72 0a 09 20 28 6c 65 f the year.. (le
0490: 74 20 28 28 74 68 65 74 69 6d 65 20 28 2a 20 6d t ((thetime (* m
04a0: 20 36 30 29 29 0a 09 20 20 20 20 20 20 20 28 74 60)).. (t
04b0: 68 65 68 6f 75 72 20 28 72 6f 75 6e 64 20 28 2f hehour (round (/
04c0: 20 6d 20 36 30 29 29 29 29 0a 09 20 20 20 28 6c m 60)))).. (l
04d0: 65 74 20 6c 6f 6f 70 20 28 28 6c 61 73 74 73 65 et loop ((lastse
04e0: 63 20 2d 31 29 0a 09 09 20 20 20 20 20 20 28 73 c -1)... (s
04f0: 65 63 20 20 20 20 20 28 72 61 6e 64 6f 6d 20 36 ec (random 6
0500: 30 29 29 0a 09 09 20 20 20 20 20 20 28 63 6f 75 0))... (cou
0510: 6e 74 20 20 20 30 29 29 0a 09 20 20 20 20 20 28 nt 0)).. (
0520: 69 66 20 28 3e 20 73 65 63 20 6c 61 73 74 73 65 if (> sec lastse
0530: 63 29 0a 09 09 20 28 65 78 65 63 20 28 73 71 6c c)... (exec (sql
0540: 20 64 62 20 22 49 4e 53 45 52 54 20 49 4e 54 4f db "INSERT INTO
0550: 20 61 6c 6c 64 61 74 20 28 65 76 65 6e 74 5f 74 alldat (event_t
0560: 69 6d 65 2c 76 61 72 2c 76 61 6c 29 20 56 41 4c ime,var,val) VAL
0570: 55 45 53 20 28 3f 2c 3f 2c 3f 29 22 29 0a 09 09 UES (?,?,?)")...
0580: 20 20 20 20 20 20 20 28 2b 20 74 68 65 74 69 6d (+ thetim
0590: 65 20 73 65 63 29 20 3b 3b 20 28 2a 20 73 65 63 e sec) ;; (* sec
05a0: 20 36 30 29 29 0a 09 09 20 20 20 20 20 20 20 22 60))... "
05b0: 73 74 75 66 66 22 20 0a 09 09 20 20 20 20 20 20 stuff" ...
05c0: 20 28 69 66 20 28 65 76 65 6e 3f 20 74 68 65 68 (if (even? theh
05d0: 6f 75 72 29 0a 09 09 09 20 20 20 28 72 61 6e 64 our).... (rand
05e0: 6f 6d 20 31 30 30 30 29 0a 09 09 09 20 20 20 28 om 1000).... (
05f0: 72 61 6e 64 6f 6d 20 36 29 29 29 29 0a 09 20 20 random 6))))..
0600: 20 20 20 28 69 66 20 28 3c 20 63 6f 75 6e 74 20 (if (< count
0610: 32 30 29 0a 09 09 20 28 6c 6f 6f 70 20 28 6d 61 20)... (loop (ma
0620: 78 20 73 65 63 20 6c 61 73 74 73 65 63 29 28 72 x sec lastsec)(r
0630: 61 6e 64 6f 6d 20 36 30 29 28 2b 20 63 6f 75 6e andom 60)(+ coun
0640: 74 20 31 29 29 29 29 29 29 29 29 0a 0a 28 63 6c t 1))))))))..(cl
0650: 6f 73 65 2d 64 61 74 61 62 61 73 65 20 64 62 29 ose-database db)
0660: 0a 0a 0a 3b 3b 20 28 77 69 74 68 2d 74 72 61 6e ...;; (with-tran
0670: 73 61 63 74 69 6f 6e 0a 3b 3b 20 20 64 62 0a 3b saction.;; db.;
0680: 3b 20 20 28 6c 61 6d 62 64 61 20 28 29 0a 3b 3b ; (lambda ().;;
0690: 20 20 20 20 28 6c 6f 6f 70 20 28 28 66 6f 72 20 (loop ((for
06a0: 64 20 28 75 70 2d 66 72 6f 6d 20 30 20 28 74 6f d (up-from 0 (to
06b0: 20 33 36 35 29 29 29 29 20 3b 3b 20 64 61 79 73 365)))) ;; days
06c0: 20 6f 66 20 74 68 65 20 79 65 61 72 0a 3b 3b 20 of the year.;;
06d0: 09 20 28 70 72 69 6e 74 20 22 44 61 79 3a 20 22 . (print "Day: "
06e0: 20 64 29 0a 3b 3b 20 09 20 28 6c 6f 6f 70 20 28 d).;; . (loop (
06f0: 28 66 6f 72 20 68 20 28 75 70 2d 66 72 6f 6d 20 (for h (up-from
0700: 31 20 28 74 6f 20 32 34 29 29 29 29 0a 3b 3b 20 1 (to 24)))).;;
0710: 09 20 20 20 20 20 28 6c 6f 6f 70 20 28 28 66 6f . (loop ((fo
0720: 72 20 6d 20 28 75 70 2d 66 72 6f 6d 20 31 20 28 r m (up-from 1 (
0730: 74 6f 20 36 30 29 29 29 29 0a 3b 3b 20 09 09 20 to 60)))).;; ..
0740: 20 20 28 6c 65 74 20 28 28 74 68 65 74 69 6d 65 (let ((thetime
0750: 20 28 2b 20 62 65 67 69 6e 6e 69 6e 67 2d 32 30 (+ beginning-20
0760: 31 36 20 28 2a 20 33 36 35 20 32 34 20 36 30 20 16 (* 365 24 60
0770: 36 30 29 28 2a 20 68 20 36 30 20 36 30 29 28 2a 60)(* h 60 60)(*
0780: 20 6d 20 36 30 29 29 29 29 0a 3b 3b 20 09 09 20 m 60)))).;; ..
0790: 20 20 20 20 28 6c 65 74 20 6c 6f 6f 70 20 28 28 (let loop ((
07a0: 6c 61 73 74 73 65 63 20 2d 31 29 0a 3b 3b 20 09 lastsec -1).;; .
07b0: 09 09 09 28 73 65 63 20 20 20 20 20 28 72 61 6e ...(sec (ran
07c0: 64 6f 6d 20 36 30 29 29 0a 3b 3b 20 09 09 09 09 dom 60)).;; ....
07d0: 28 63 6f 75 6e 74 20 20 20 30 29 29 0a 3b 3b 20 (count 0)).;;
07e0: 09 09 20 20 20 20 20 20 20 28 69 66 20 28 3e 20 .. (if (>
07f0: 73 65 63 20 6c 61 73 74 73 65 63 29 0a 3b 3b 20 sec lastsec).;;
0800: 09 09 09 20 20 20 28 65 78 65 63 20 28 73 71 6c ... (exec (sql
0810: 20 64 62 20 22 49 4e 53 45 52 54 20 49 4e 54 4f db "INSERT INTO
0820: 20 61 6c 6c 64 61 74 20 28 65 76 65 6e 74 5f 74 alldat (event_t
0830: 69 6d 65 2c 76 61 72 2c 76 61 6c 29 20 56 41 4c ime,var,val) VAL
0840: 55 45 53 20 28 3f 2c 3f 2c 3f 29 22 29 0a 3b 3b UES (?,?,?)").;;
0850: 20 09 09 09 09 20 28 2b 20 74 68 65 74 69 6d 65 .... (+ thetime
0860: 20 73 65 63 29 20 3b 3b 20 28 2a 20 73 65 63 20 sec) ;; (* sec
0870: 36 30 29 29 0a 3b 3b 20 09 09 09 09 20 22 73 74 60)).;; .... "st
0880: 75 66 66 22 20 0a 3b 3b 20 09 09 09 09 20 28 69 uff" .;; .... (i
0890: 66 20 28 65 76 65 6e 3f 20 68 29 0a 3b 3b 20 09 f (even? h).;; .
08a0: 09 09 09 20 20 20 20 20 28 72 61 6e 64 6f 6d 20 ... (random
08b0: 31 30 30 29 0a 3b 3b 20 09 09 09 09 20 20 20 20 100).;; ....
08c0: 20 28 72 61 6e 64 6f 6d 20 36 29 29 29 29 0a 3b (random 6)))).;
08d0: 3b 20 09 09 20 20 20 20 20 20 20 28 69 66 20 28 ; .. (if (
08e0: 3c 20 63 6f 75 6e 74 20 32 30 29 0a 3b 3b 20 09 < count 20).;; .
08f0: 09 09 20 20 20 28 6c 6f 6f 70 20 28 6d 61 78 20 .. (loop (max
0900: 73 65 63 20 6c 61 73 74 73 65 63 29 28 72 61 6e sec lastsec)(ran
0910: 64 6f 6d 20 36 30 29 28 2b 20 63 6f 75 6e 74 20 dom 60)(+ count
0920: 31 29 29 29 29 29 29 29 29 29 29 0a 3b 3b 20 0a 1)))))))))).;; .
0930: 3b 3b 20 28 63 6c 6f 73 65 2d 64 61 74 61 62 61 ;; (close-databa
0940: 73 65 20 64 62 29 0a se db).