[frontend] add __repr__ and to dict methods

This commit is contained in:
Jan Grewe 2020-08-12 18:24:58 +02:00
parent 48acf9edb3
commit e37d4d5add

View File

@ -6,6 +6,7 @@ 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 import datetime as dt
import yaml
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*.
@ -382,6 +383,16 @@ class Dataset:
def _tuple(self): def _tuple(self):
return self.__tuple.copy() return self.__tuple.copy()
@property
def yaml(self):
settings = yaml.dump({"dataset id": self.id, "recording date": self.recording_date,
"duration": self.recording_duration, "comment": self.comment,
"experimenter": self.experimenter, "quality": self.quality,
"data_source": self.data_source, "host": self.data_host,
"setup": self.setup, "nixed": self.has_nix})
return settings
def __str__(self): def __str__(self):
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)
@ -390,6 +401,8 @@ class Dataset:
str += "comment: %s" % self.comment str += "comment: %s" % self.comment
return str return str
def __repr__(self):
return self.__str__()
class RePro: class RePro:
"""The RePro class represents an entry in the repro table. This is a run of a certain relacs "Research Protocol". """The RePro class represents an entry in the repro table. This is a run of a certain relacs "Research Protocol".
@ -518,6 +531,17 @@ class RePro:
str += "start time: %s\t duration: %s\n" % (self.start, self.duration) str += "start time: %s\t duration: %s\n" % (self.start, self.duration)
return str return str
def __repr__(self):
return self.__str__()
@property
def to_dict(self):
r_settings = yaml.safe_load(self.settings.replace("\t", " "))
settings = {"repro id": self.id, "run": self.run, "cell": self.cell_id,
"name": self.name, "start": self.start, "duration": self.duration,
"settings":r_settings}
return settings
class Stimulus: class Stimulus:
"""The stimulus class represents a Stimulus that was presented. A Stimulus has several properties """The stimulus class represents a Stimulus that was presented. A Stimulus has several properties
@ -622,6 +646,17 @@ class Stimulus:
return results, total return results, total
def __repr__(self):
return self.__str__()
@property
def to_dict(self):
s_settings = yaml.safe_load(self.settings.replace("\t", " "))
settings = {"id": self.id, "run": self.run, "stimulus name" : self.name,
"stimulus index": self.index, "duration": self.duration, "start time": self.start_time,
"name": self.name, "settings": s_settings}
return settings
class Subject: class Subject:
"""Representation of the recorded subject's properties. """Representation of the recorded subject's properties.