j@286
|
1 (cl:in-package #:amuse-meredith)
|
j@286
|
2
|
j@286
|
3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
j@286
|
4 ;; Importing
|
j@286
|
5
|
j@286
|
6 (defun make-path (base-path file-prefix file-id file-suffix)
|
j@286
|
7 (pathname (concatenate 'string
|
j@286
|
8 base-path
|
j@286
|
9 file-prefix
|
j@286
|
10 (princ-to-string file-id)
|
j@286
|
11 file-suffix)))
|
j@286
|
12
|
j@286
|
13 (defun file->list-of-lists (path)
|
j@286
|
14 (with-open-file (stream path)
|
j@286
|
15 (loop
|
j@286
|
16 for row-strings = (split-sequence:split-sequence
|
j@286
|
17 #\space (read-line stream nil)
|
j@286
|
18 :remove-empty-subseqs t)
|
j@286
|
19 while row-strings
|
j@286
|
20 collect (loop
|
j@286
|
21 for value in row-strings
|
j@286
|
22 collect (read-from-string value)
|
j@286
|
23 into row-objects
|
j@286
|
24 finally (return row-objects))
|
j@286
|
25 into results
|
j@286
|
26 finally (return (cdr results)))))
|
j@286
|
27
|
j@286
|
28 (defvar *import-file* (pathname "/tmp/raph-c.txt"))
|
j@286
|
29
|
j@286
|
30 (defun write-to-db-file (composition-id datapoints)
|
j@286
|
31 (with-open-file (stream *import-file*
|
j@286
|
32 :direction :output
|
j@286
|
33 :if-exists :supersede
|
j@286
|
34 :external-format :latin1)
|
j@286
|
35 (sequence:dosequence (datapoint datapoints)
|
j@286
|
36 (format stream
|
j@286
|
37 "~S \\N ~{~S ~}~%"
|
j@286
|
38 composition-id datapoint)))
|
j@286
|
39 t)
|
j@286
|
40
|
j@286
|
41 (defun import-meredith-composition (event-lists &key description
|
j@286
|
42 database)
|
j@286
|
43 "Import a composition into the database. A composition is a list of
|
j@286
|
44 lists (dataset in the SIA sense), where each internal list (datapoint)
|
j@286
|
45 represents an event. All datapoints are the same cardinality. The
|
j@286
|
46 description is a string of up to 255 characters."
|
j@286
|
47 #.(clsql:locally-enable-sql-reader-syntax)
|
j@286
|
48 (clsql:with-transaction
|
j@286
|
49 (:database database)
|
j@286
|
50 (let (composition-id)
|
j@286
|
51 (clsql:insert-records :into "meredith_compositions"
|
j@286
|
52 :attributes '([description])
|
j@286
|
53 :values (list description)
|
j@286
|
54 :database database)
|
j@286
|
55 #.(clsql:locally-disable-sql-reader-syntax)
|
j@286
|
56 (setf composition-id (clsql-mysql::mysql-insert-id
|
j@286
|
57 (clsql-mysql::database-mysql-ptr
|
j@286
|
58 database)))
|
j@286
|
59 (write-to-db-file composition-id event-lists)
|
j@286
|
60 (clsql:execute-command
|
j@286
|
61 (concatenate 'string
|
j@286
|
62 "LOAD DATA LOCAL INFILE '"
|
j@286
|
63 (namestring *import-file*)
|
j@286
|
64 "' INTO TABLE "
|
j@286
|
65 "meredith_events")
|
j@286
|
66 :database database)
|
j@286
|
67 (delete-file *import-file*)
|
j@286
|
68 (format t "composition added to db, id: ~A~%" composition-id)
|
j@286
|
69 (make-meredith-composition-identifier composition-id))))
|
j@286
|
70
|
j@286
|
71 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
j@286
|
72 ;;; Import functions for specific datasets.
|
j@286
|
73
|
j@286
|
74 (defun import-bach-inv+sin (&optional (database *amuse-database*))
|
j@286
|
75 "Imports all of Dave's encodings of Bach's Inventions and Sinfonias,
|
j@286
|
76 and assigns them all so a unique dataset."
|
j@286
|
77 (clsql:with-transaction
|
j@286
|
78 (:database database)
|
j@286
|
79 (let ((dataset-identifier (make-new-dataset
|
j@286
|
80 "Bach Inventions and Sinfonias"
|
j@286
|
81 database)))
|
j@286
|
82 (import-bach-inventions database dataset-identifier)
|
j@286
|
83 (import-bach-sinfonias database dataset-identifier))))
|
j@286
|
84
|
j@286
|
85 (defun import-bach-inventions (database &optional dataset-identifier)
|
j@286
|
86 "Imports all of Dave's encodings of Bach's Inventions."
|
j@286
|
87 (let ((base-path "/home/jamie/Music/meredith-data/20060301raph-c/")
|
j@286
|
88 (file-prefix "bachrasmussinventio0")
|
j@286
|
89 (file-suffix "01.raph-c"))
|
j@286
|
90 (loop for file-id from 772 to 786
|
j@286
|
91 for composition-order from 1
|
j@286
|
92 for composition-identifier =
|
j@286
|
93 (import-meredith-composition
|
j@286
|
94 (file->list-of-lists
|
j@286
|
95 (make-path base-path file-prefix file-id file-suffix))
|
j@286
|
96 :description (concatenate 'string
|
j@286
|
97 "Bach Invention No."
|
j@286
|
98 (princ-to-string composition-order)
|
j@286
|
99 " BWV "
|
j@286
|
100 (princ-to-string file-id))
|
j@286
|
101 :database database)
|
j@286
|
102 do (when dataset-identifier
|
j@286
|
103 (assign-composition-to-dataset
|
j@286
|
104 composition-identifier dataset-identifier database)))))
|
j@286
|
105
|
j@286
|
106 (defun import-bach-sinfonias (database &optional dataset-identifier)
|
j@286
|
107 "Imports all of Dave's encodings of Bach's Sinfonias."
|
j@286
|
108 (let ((base-path "/home/jamie/Music/meredith-data/20060301raph-c/")
|
j@286
|
109 (file-prefix "bachrasmusssinfonie0")
|
j@286
|
110 (file-suffix "01.raph-c"))
|
j@286
|
111 (loop for file-id from 787 to 801
|
j@286
|
112 for composition-order from 1
|
j@286
|
113 for composition-identifier =
|
j@286
|
114 (import-meredith-composition
|
j@286
|
115 (file->list-of-lists
|
j@286
|
116 (make-path base-path file-prefix file-id file-suffix))
|
j@286
|
117 :description (concatenate 'string
|
j@286
|
118 "Bach Sinfonia No."
|
j@286
|
119 (princ-to-string composition-order)
|
j@286
|
120 " BWV "
|
j@286
|
121 (princ-to-string file-id))
|
j@286
|
122 :database database)
|
j@286
|
123 do (when dataset-identifier
|
j@286
|
124 (assign-composition-to-dataset
|
j@286
|
125 composition-identifier dataset-identifier database)))))
|