[frontend] support date restrictions in dataset, expose data_host to

user
This commit is contained in:
Jan Grewe 2020-08-03 18:26:07 +02:00
parent b376edb342
commit ec88c79e0f

View File

@ -5,6 +5,7 @@ import os
import numpy as np import numpy as np
from IPython import embed from IPython import embed
from fishbook.backend.util import progress from fishbook.backend.util import progress
import datetime as dt
class Cell: class Cell:
"""The Cell class represents a recorded cell. It is characterized by *id*, the cell *type*, the *firing_rate*, and the recording *location*. """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"] 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 @property
def setup(self): def setup(self):
"""The recording setup. """The recording setup.
@ -272,6 +283,16 @@ class Dataset:
subject_list = (Subjects * (SubjectDatasetMap & self.__tuple)) subject_list = (Subjects * (SubjectDatasetMap & self.__tuple))
return [Subject(tuple=s) for s in subject_list] 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 @property
def samplerate(self): def samplerate(self):
"""Get the samplerate of the data. """Get the samplerate of the data.
@ -291,13 +312,16 @@ class Dataset:
return len(Datasets()) return len(Datasets())
@staticmethod @staticmethod
def find(min_duration=None, experimenter=None, quality=None, test=False): 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. """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: Args:
min_duration (float, optional): minimum duration of the recording session, if not given, any length datasets will be returned. Defaults to None. 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. 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. 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. 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: Returns:
list: list of Dataset object matching the search criteria, empty if test==True 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) dataset_list = dataset_list & "experimenter like '%{0:s}%'".format(experimenter)
if quality: if quality:
dataset_list = dataset_list & "quality like '{0:s}'".format(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 = [] results = []
total = len(dataset_list) total = len(dataset_list)
if not test: if not test:
@ -353,6 +381,7 @@ class Dataset:
str = "dataset id: %s\n" % self.id str = "dataset id: %s\n" % self.id
str += "recorded: %s \t by: %s\n" % (self.recording_date, self.experimenter) 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 += "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 str += "comment: %s" % self.comment
return str return str
@ -653,7 +682,8 @@ class Subject:
def __str__(self): def __str__(self):
str = "Subject: %s\n" % self.id str = "Subject: %s\n" % self.id
str += "" str += "Species: %s\n" % self.species
return str
if __name__ == "__main__": if __name__ == "__main__":