annotate base/database/datasets-functions.lisp @ 289:2519652145c3

Add function assigning a list of composition identifiers to a dataset. Ignore-this: aa2078c1427801491a54d23ffca7da70 darcs-hash:20090716170022-16a00-d95599a9631d18530c0d0d51ef095133f9bbde5a.gz
author j.forth <j.forth@gold.ac.uk>
date Thu, 16 Jul 2009 18:00:22 +0100
parents 00d35eb70ef9
children 317fe3126c6c
rev   line source
j@287 1 (cl:in-package #:amuse-database-admin)
j@287 2
j@287 3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
j@287 4 ;;; Constructors
j@287 5
j@287 6 (defun make-amuse-dataset-identifier (dataset-id)
j@287 7 (make-instance 'amuse-dataset-identifier
j@287 8 :dataset-id dataset-id))
j@287 9
j@287 10 (defun %make-amuse-dataset (dataset-identifier description
j@287 11 composition-identifiers)
j@287 12 (make-instance 'amuse-dataset
j@287 13 :%data composition-identifiers
j@287 14 :identifier dataset-identifier
j@287 15 :description description))
j@287 16
j@287 17
j@287 18 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
j@287 19 ;;; Database functions
j@287 20
j@287 21 (defun make-new-dataset (description &optional (database
j@287 22 *amuse-database*))
j@287 23 "A dataset is a set of pieces used for a particualar analytical
j@287 24 task. A dataset is not necessarily the same thing as a corpus or
j@287 25 collection (are these things different?). Corpus indicates that a set
j@287 26 of pieces have been curated in some way and in that sense `belong
j@287 27 together'. A dataset is just simply a set of pieces gathered together
j@287 28 to analyse, and the pieces can be from any corpus or backend."
j@287 29 (let (dataset-id)
j@287 30 #.(clsql:locally-enable-sql-reader-syntax)
j@287 31 (clsql:insert-records :into "amuse_datasets"
j@287 32 :attributes '([description])
j@287 33 :values (list description)
j@287 34 :database database)
j@287 35 #.(clsql:locally-disable-sql-reader-syntax)
j@287 36 (setf dataset-id (clsql-mysql::mysql-insert-id
j@287 37 (clsql-mysql::database-mysql-ptr
j@287 38 database)))
j@287 39 (make-amuse-dataset-identifier dataset-id)))
j@287 40
j@287 41 (defun assign-composition-to-dataset (composition-identifier
j@287 42 dataset-identifier
j@287 43 &optional (database
j@287 44 *amuse-database*))
j@287 45 (clsql:execute-command (format nil "
j@287 46 INSERT INTO amuse_datasets_join
j@287 47 SET dataset_id := ~S,
j@287 48 implementation_id := (SELECT get_impl_id('~A')),
j@287 49 composition_id := ~S;"
j@287 50 (dataset-id dataset-identifier)
j@287 51 (implementation-namestring
j@287 52 composition-identifier)
j@287 53 (composition-id
j@287 54 composition-identifier)))
j@287 55 :database database)
j@287 56
j@289 57 (defun assign-compositions-to-dataset (composition-identifiers
j@289 58 dataset-identifier
j@289 59 &optional (database
j@289 60 *amuse-database*))
j@289 61 "This should be done more sensibly."
j@289 62 (loop for identifier in composition-identifiers
j@289 63 do (assign-composition-to-dataset identifier
j@289 64 dataset-identifier
j@289 65 database)))
j@289 66
j@287 67 (defun get-dataset (dataset-identifier &optional (database
j@287 68 *amuse-database*))
j@287 69 (let ((dataset-header (clsql:query (format nil "
j@287 70 SELECT description
j@287 71 FROM amuse_datasets
j@287 72 WHERE dataset_id = ~S" (dataset-id dataset-identifier))
j@287 73 :database database
j@287 74 :flatp t
j@287 75 :field-names nil))
j@287 76 (dataset-rows (clsql:query (format nil "
j@287 77 SELECT implementation_name, composition_id
j@287 78 FROM amuse_datasets_join
j@287 79 LEFT JOIN amuse_implementations
j@287 80 USING (implementation_id)
j@287 81 WHERE dataset_id = ~S"
j@287 82 (dataset-id
j@287 83 dataset-identifier))
j@287 84 :flatp t
j@287 85 :field-names nil
j@287 86 :database database)))
j@287 87 (%make-amuse-dataset dataset-identifier (car dataset-header)
j@287 88 (%init-dataset-rows dataset-rows))))
j@287 89
j@287 90 (defun %init-dataset-rows (dataset-rows)
j@287 91 (loop for row in dataset-rows
j@287 92 collect (make-composition-identifier (find-package
j@287 93 (first row)) (second row))
j@287 94 into composition-identifiers
j@287 95 finally (return composition-identifiers)))