From ec88c79e0feac7d3438c9402984677ddf6a87fde Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Mon, 3 Aug 2020 18:26:07 +0200 Subject: [PATCH] [frontend] support date restrictions in dataset, expose data_host to user --- fishbook/frontend/frontend_classes.py | 38 ++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/fishbook/frontend/frontend_classes.py b/fishbook/frontend/frontend_classes.py index 3e3fc0b..f1ad200 100644 --- a/fishbook/frontend/frontend_classes.py +++ b/fishbook/frontend/frontend_classes.py @@ -5,6 +5,7 @@ import os import numpy as np from IPython import embed from fishbook.backend.util import progress +import datetime as dt class Cell: """The Cell class represents a recorded cell. It is characterized by *id*, the cell *type*, the *firing_rate*, and the recording *location*. @@ -242,6 +243,16 @@ class Dataset: """ return self.__tuple["data_source"] + @property + def data_host(self): + """Returns the fully qualified name of the host from which the data was imported. That is, where it + should be available. + + Returns: + str: the fully qualified domain. + """ + return self.__tuple["data_host"] + @property def setup(self): """The recording setup. @@ -272,6 +283,16 @@ class Dataset: subject_list = (Subjects * (SubjectDatasetMap & self.__tuple)) return [Subject(tuple=s) for s in subject_list] + @property + def repro_runs(self): + """The repros that have been run in this dataset. + + Returns: + list of fishbook.RePro: list of repro runs + """ + repros = (Repros * Cells * (CellDatasetMap & self.__tuple)) + return [RePro(tuple=r) for r in repros] + @property def samplerate(self): """Get the samplerate of the data. @@ -291,13 +312,16 @@ class Dataset: return len(Datasets()) @staticmethod - def find(min_duration=None, experimenter=None, quality=None, test=False): - """Find dataset entries in the database. You may restrict the search by providing the following arguments. + def find(min_duration=None, experimenter=None, quality=None, min_date=None, max_date=None, test=False): + """Find dataset entries in the database. You may restrict the search by providing the following arguments. All restrictions are connected + with a logical AND. Args: min_duration (float, optional): minimum duration of the recording session, if not given, any length datasets will be returned. Defaults to None. experimenter (str, optional): the name of the one who did the recording. The name does not need to be the full name. Defaults to None. quality (str, optional): the quality assigned to the dataset during recording (e.g. good, fair, poor). Defaults to None. + min_date (datetime, optional): the minimum recording date. Dates may be given as datetime objects or string of the format "2010.01.01" or "2010-01-01". Defaults to None. + max_date (datetime, optional): the maximum recording date. Defaults to None. test (bool, optional): defines whether this is a test run and thus whether or not the search results should be fetched, which can take a while. Defaults to False. Returns: list: list of Dataset object matching the search criteria, empty if test==True @@ -310,7 +334,11 @@ class Dataset: dataset_list = dataset_list & "experimenter like '%{0:s}%'".format(experimenter) if quality: dataset_list = dataset_list & "quality like '{0:s}'".format(quality) - + if min_date and isinstance(min_date, (dt.date, str)): + dataset_list = dataset_list & "recording_date >= '%s'" % min_date + if max_date and isinstance(min_date, (dt.date, str)): + dataset_list = dataset_list & "recording_date < '%s'" % max_date + results = [] total = len(dataset_list) if not test: @@ -353,6 +381,7 @@ class Dataset: str = "dataset id: %s\n" % self.id str += "recorded: %s \t by: %s\n" % (self.recording_date, self.experimenter) str += "duration: %s min \t quality: %s\n" % (self.recording_duration, self.quality) + str += "location: %s\t host:%s\n" % (self.data_source, self.data_host) str += "comment: %s" % self.comment return str @@ -653,7 +682,8 @@ class Subject: def __str__(self): str = "Subject: %s\n" % self.id - str += "" + str += "Species: %s\n" % self.species + return str if __name__ == "__main__":