forked from jgrewe/fishbook
		
	rearraning things
This commit is contained in:
		
							parent
							
								
									1874985f56
								
							
						
					
					
						commit
						14bed0cc6a
					
				| @ -1,4 +1,4 @@ | |||||||
| from .fishbook import Cell, Subject, Stimulus, Dataset, RePro | from fishbook.frontend.frontend_classes import Cell, Subject, Stimulus, Dataset, RePro | ||||||
| import fishbook.reproclasses as repros  | #import fishbook.reproclasses as repros  | ||||||
| import fishbook.database as database | #import fishbook.database as database | ||||||
| __all__ = ['fishbook', 'database'] | __all__ = ['', ''] | ||||||
|  | |||||||
| @ -1,3 +1,2 @@ | |||||||
| from .database import * | from .database import Cells, Datasets, Stimuli, Repros, Subjects, SubjectDatasetMap, CellDatasetMap | ||||||
| 
 |  | ||||||
| __all__ = ['database'] | __all__ = ['database'] | ||||||
							
								
								
									
										1
									
								
								fishbook/frontend/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								fishbook/frontend/__init__.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1 @@ | |||||||
|  | # __all__ = ["fronten_classes", "reproclasses"] | ||||||
| @ -1,21 +1,11 @@ | |||||||
| from fishbook.database.database import Cells, Datasets, CellDatasetMap, Subjects, SubjectProperties, SubjectDatasetMap, Stimuli, Repros | from fishbook.backend.database import Cells, Datasets, CellDatasetMap, Subjects, SubjectProperties, SubjectDatasetMap, Stimuli, Repros | ||||||
|  | from .util import safe_get_val, results_check | ||||||
| import nixio as nix | import nixio as nix | ||||||
| import os | import os | ||||||
| import numpy as np | import numpy as np | ||||||
| from IPython import embed | from IPython import embed | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def _safe_get_val(dictionary:dict, key, default=None): |  | ||||||
|     return dictionary[key] if key in dictionary.keys() else default |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| def _results_check(results, id, text="ID"): |  | ||||||
|     if len(results) == 0: |  | ||||||
|         raise ValueError("%s %s does not exist!" % (text, id)) |  | ||||||
|     elif len(results) > 1: |  | ||||||
|         raise ValueError("%s %s is not unique!" % (text, id)) |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| class Cell: | class Cell: | ||||||
|     def __init__(self, cell_id=None, tuple=None): |     def __init__(self, cell_id=None, tuple=None): | ||||||
|         if tuple: |         if tuple: | ||||||
| @ -23,7 +13,7 @@ class Cell: | |||||||
|         elif cell_id: |         elif cell_id: | ||||||
|             pattern = "cell_id like '{0:s}'".format(cell_id) |             pattern = "cell_id like '{0:s}'".format(cell_id) | ||||||
|             cells = (Cells & pattern) |             cells = (Cells & pattern) | ||||||
|             _results_check(cells, cell_id, "Cell ID") |             results_check(cells, cell_id, "Cell ID") | ||||||
|             self.__tuple = cells.fetch(as_dict=True)[0] |             self.__tuple = cells.fetch(as_dict=True)[0] | ||||||
|         else: |         else: | ||||||
|             print("Empty Cell, not linked to any database entry!") |             print("Empty Cell, not linked to any database entry!") | ||||||
| @ -105,7 +95,7 @@ class Dataset: | |||||||
|         elif dataset_id: |         elif dataset_id: | ||||||
|             pattern = "dataset_id like '{0:s}'".format(dataset_id) |             pattern = "dataset_id like '{0:s}'".format(dataset_id) | ||||||
|             dsets = (Datasets & pattern) |             dsets = (Datasets & pattern) | ||||||
|             _results_check(dsets, dataset_id, "Dataset ID") |             results_check(dsets, dataset_id, "Dataset ID") | ||||||
|             self.__tuple = dsets.fetch(limit=1, as_dict=True)[0] |             self.__tuple = dsets.fetch(limit=1, as_dict=True)[0] | ||||||
|         else: |         else: | ||||||
|             print("Empty dataset, not linked to any database entry!") |             print("Empty dataset, not linked to any database entry!") | ||||||
| @ -220,7 +210,7 @@ class RePro: | |||||||
|             self.__tuple = tuple |             self.__tuple = tuple | ||||||
|         elif repro_id: |         elif repro_id: | ||||||
|             repros = (RePro & "repro_id like '{0:s}'".format(repro_id)) |             repros = (RePro & "repro_id like '{0:s}'".format(repro_id)) | ||||||
|             _results_check(repros, repro_id, "RePro ID") |             results_check(repros, repro_id, "RePro ID") | ||||||
|             self.__tuple = repros.fetch(limit=1, as_dict=True)[0] |             self.__tuple = repros.fetch(limit=1, as_dict=True)[0] | ||||||
|         else: |         else: | ||||||
|             self.__tuple = {} |             self.__tuple = {} | ||||||
| @ -228,15 +218,15 @@ class RePro: | |||||||
| 
 | 
 | ||||||
|     @property |     @property | ||||||
|     def id(self): |     def id(self): | ||||||
|         return _safe_get_val(self.__tuple, "repro_id", "") |         return safe_get_val(self.__tuple, "repro_id", "") | ||||||
| 
 | 
 | ||||||
|     @property |     @property | ||||||
|     def run(self): |     def run(self): | ||||||
|         return _safe_get_val(self.__tuple, "run", -1) |         return safe_get_val(self.__tuple, "run", -1) | ||||||
| 
 | 
 | ||||||
|     @property |     @property | ||||||
|     def cell_id(self): |     def cell_id(self): | ||||||
|         return _safe_get_val(self.__tuple, "cell_id", "") |         return safe_get_val(self.__tuple, "cell_id", "") | ||||||
| 
 | 
 | ||||||
|     @property |     @property | ||||||
|     def cell(self): |     def cell(self): | ||||||
| @ -252,19 +242,19 @@ class RePro: | |||||||
| 
 | 
 | ||||||
|     @property |     @property | ||||||
|     def name(self): |     def name(self): | ||||||
|         return _safe_get_val(self.__tuple, "repro_name", "") |         return safe_get_val(self.__tuple, "repro_name", "") | ||||||
| 
 | 
 | ||||||
|     @property |     @property | ||||||
|     def settings(self): |     def settings(self): | ||||||
|         return _safe_get_val(self.__tuple, "settings", "") |         return safe_get_val(self.__tuple, "settings", "") | ||||||
| 
 | 
 | ||||||
|     @property |     @property | ||||||
|     def start(self): |     def start(self): | ||||||
|         return _safe_get_val(self.__tuple, "start", 0.0) |         return safe_get_val(self.__tuple, "start", 0.0) | ||||||
| 
 | 
 | ||||||
|     @property |     @property | ||||||
|     def duration(self): |     def duration(self): | ||||||
|         return _safe_get_val(self.__tuple, "duration", 0.0) |         return safe_get_val(self.__tuple, "duration", 0.0) | ||||||
| 
 | 
 | ||||||
|     @property |     @property | ||||||
|     def stimuli(self): |     def stimuli(self): | ||||||
| @ -316,16 +306,16 @@ class Stimulus: | |||||||
|             self.__tuple = tuple |             self.__tuple = tuple | ||||||
|         elif stimulus_id: |         elif stimulus_id: | ||||||
|             stimuli = Stimuli & "stimulus_id = '%s'" %stimulus_id |             stimuli = Stimuli & "stimulus_id = '%s'" %stimulus_id | ||||||
|             _results_check(stimuli, stimulus_id, "Stimulus ID") |             results_check(stimuli, stimulus_id, "Stimulus ID") | ||||||
|             self.__tuple = stimuli.fetch(limit=1, as_dict=True)[0] |             self.__tuple = stimuli.fetch(limit=1, as_dict=True)[0] | ||||||
|         else: |         else: | ||||||
|             print("Empty RePro, not linked to any database entry!") |             print("Empty RePro, not linked to any database entry!") | ||||||
| 
 | 
 | ||||||
|     def __str__(self): |     def __str__(self): | ||||||
|         str = "Stimulus %s: " % _safe_get_val(self.__tuple, "stimulus_id", "") |         str = "Stimulus %s: " % safe_get_val(self.__tuple, "stimulus_id", "") | ||||||
|         str += "\nStart time/index: %0.4f/%i, duration: %.3f" % (_safe_get_val(self.__tuple, "start_time", 0.0), |         str += "\nStart time/index: %0.4f/%i, duration: %.3f" % (safe_get_val(self.__tuple, "start_time", 0.0), | ||||||
|                                                                  _safe_get_val(self.__tuple, "start_index", -1), |                                                                  safe_get_val(self.__tuple, "start_index", -1), | ||||||
|                                                                  _safe_get_val(self.__tuple, "duration", 0.0)) |                                                                  safe_get_val(self.__tuple, "duration", 0.0)) | ||||||
|         return str |         return str | ||||||
| 
 | 
 | ||||||
|     @property |     @property | ||||||
| @ -370,7 +360,7 @@ class Stimulus: | |||||||
| 
 | 
 | ||||||
|     @property |     @property | ||||||
|     def settings(self): |     def settings(self): | ||||||
|         return _safe_get_val(self.__tuple, "settings", "") |         return safe_get_val(self.__tuple, "settings", "") | ||||||
| 
 | 
 | ||||||
|     @property |     @property | ||||||
|     def _tuple(self): |     def _tuple(self): | ||||||
| @ -405,7 +395,7 @@ class Subject: | |||||||
|             self.__tuple = tuple |             self.__tuple = tuple | ||||||
|         elif subject_id: |         elif subject_id: | ||||||
|             subjects = Subjects & "subject_id like '{0:s}'".format(subject_id) |             subjects = Subjects & "subject_id like '{0:s}'".format(subject_id) | ||||||
|             _results_check(subjects, subject_id, "Subject ID") |             results_check(subjects, subject_id, "Subject ID") | ||||||
|             self.__tuple = subjects.fetch()[0] |             self.__tuple = subjects.fetch()[0] | ||||||
|         else: |         else: | ||||||
|             self.__tuple = {} |             self.__tuple = {} | ||||||
							
								
								
									
										9
									
								
								fishbook/frontend/util.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								fishbook/frontend/util.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,9 @@ | |||||||
|  | def safe_get_val(dictionary:dict, key, default=None): | ||||||
|  |     return dictionary[key] if key in dictionary.keys() else default | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | def results_check(results, id, text="ID"): | ||||||
|  |     if len(results) == 0: | ||||||
|  |         raise ValueError("%s %s does not exist!" % (text, id)) | ||||||
|  |     elif len(results) > 1: | ||||||
|  |         raise ValueError("%s %s is not unique!" % (text, id)) | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user