Mercurial > hg > amuse
diff base/database/datasets-functions.lisp @ 287:00d35eb70ef9
amuse-database-admin add implementation and dataset functionality
Ignore-this: 787cc01acf2d6a58640fec017de16c17
darcs-hash:20090716145807-16a00-6fe5ad4a2b6252b2c1f3d109a16455bb32243965.gz
author | j.forth <j.forth@gold.ac.uk> |
---|---|
date | Thu, 16 Jul 2009 15:58:07 +0100 |
parents | |
children | 385935631532 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/base/database/datasets-functions.lisp Thu Jul 16 15:58:07 2009 +0100 @@ -0,0 +1,85 @@ +(cl:in-package #:amuse-database-admin) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; Constructors + +(defun make-amuse-dataset-identifier (dataset-id) + (make-instance 'amuse-dataset-identifier + :dataset-id dataset-id)) + +(defun %make-amuse-dataset (dataset-identifier description + composition-identifiers) + (make-instance 'amuse-dataset + :%data composition-identifiers + :identifier dataset-identifier + :description description)) + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; Database functions + +(defun make-new-dataset (description &optional (database + *amuse-database*)) + "A dataset is a set of pieces used for a particualar analytical +task. A dataset is not necessarily the same thing as a corpus or +collection (are these things different?). Corpus indicates that a set +of pieces have been curated in some way and in that sense `belong +together'. A dataset is just simply a set of pieces gathered together +to analyse, and the pieces can be from any corpus or backend." + (let (dataset-id) + #.(clsql:locally-enable-sql-reader-syntax) + (clsql:insert-records :into "amuse_datasets" + :attributes '([description]) + :values (list description) + :database database) + #.(clsql:locally-disable-sql-reader-syntax) + (setf dataset-id (clsql-mysql::mysql-insert-id + (clsql-mysql::database-mysql-ptr + database))) + (make-amuse-dataset-identifier dataset-id))) + +(defun assign-composition-to-dataset (composition-identifier + dataset-identifier + &optional (database + *amuse-database*)) + (clsql:execute-command (format nil " +INSERT INTO amuse_datasets_join +SET dataset_id := ~S, +implementation_id := (SELECT get_impl_id('~A')), +composition_id := ~S;" + (dataset-id dataset-identifier) + (implementation-namestring + composition-identifier) + (composition-id + composition-identifier))) + :database database) + +(defun get-dataset (dataset-identifier &optional (database + *amuse-database*)) + (let ((dataset-header (clsql:query (format nil " +SELECT description +FROM amuse_datasets +WHERE dataset_id = ~S" (dataset-id dataset-identifier)) + :database database + :flatp t + :field-names nil)) + (dataset-rows (clsql:query (format nil " +SELECT implementation_name, composition_id +FROM amuse_datasets_join +LEFT JOIN amuse_implementations +USING (implementation_id) +WHERE dataset_id = ~S" + (dataset-id + dataset-identifier)) + :flatp t + :field-names nil + :database database))) + (%make-amuse-dataset dataset-identifier (car dataset-header) + (%init-dataset-rows dataset-rows)))) + +(defun %init-dataset-rows (dataset-rows) + (loop for row in dataset-rows + collect (make-composition-identifier (find-package + (first row)) (second row)) + into composition-identifiers + finally (return composition-identifiers)))