From e37d4d5add9281ff33197fb7782d2e9403aa862f Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Wed, 12 Aug 2020 18:24:58 +0200 Subject: [PATCH] [frontend] add __repr__ and to dict methods --- fishbook/frontend/frontend_classes.py | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/fishbook/frontend/frontend_classes.py b/fishbook/frontend/frontend_classes.py index 4502fdf..49c7dcb 100644 --- a/fishbook/frontend/frontend_classes.py +++ b/fishbook/frontend/frontend_classes.py @@ -6,6 +6,7 @@ import numpy as np from IPython import embed from fishbook.backend.util import progress import datetime as dt +import yaml class Cell: """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): 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): str = "dataset id: %s\n" % self.id str += "recorded: %s \t by: %s\n" % (self.recording_date, self.experimenter) @@ -390,6 +401,8 @@ class Dataset: str += "comment: %s" % self.comment return str + def __repr__(self): + return self.__str__() class RePro: """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) 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: """The stimulus class represents a Stimulus that was presented. A Stimulus has several properties @@ -622,6 +646,17 @@ class Stimulus: 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: """Representation of the recorded subject's properties.