Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 from labeling import label_object, scan_dataset
00031 import hrl_lib.util as ut
00032
00033 import shutil
00034
00035 class scans_database(object):
00036 '''
00037 classdocs
00038 '''
00039
00040
00041 def __init__(self):
00042 '''
00043 Constructor
00044 '''
00045 self.datasets = []
00046 self.current_index = 0
00047
00048
00049 def load(self, path, filename):
00050 self.filename = filename
00051 self.path = path
00052
00053 dict = ut.load_pickle(self.path+'/'+self.filename)
00054
00055
00056
00057
00058 self.datasets = dict['datasets']
00059
00060 def save(self):
00061 dict = {'datasets': self.datasets,'version': 0.1}
00062
00063
00064 database_filename = self.path+'/'+self.filename
00065 backup_filename = self.path+'/'+self.filename+'_backup_'+ut.formatted_time()
00066 print 'Backing up old database to ' + backup_filename
00067 shutil.copy(database_filename, backup_filename)
00068
00069 print "Saving: "+database_filename
00070 ut.save_pickle(dict,database_filename)
00071
00072
00073 def get_path(self):
00074 return self.path
00075
00076 def get_dataset(self, index):
00077 self.current_index = index
00078 return self.datasets[index]
00079
00080 def get_dataset_by_id(self, id):
00081
00082
00083 for dataset in self.datasets:
00084 if dataset.id == id:
00085 return dataset
00086 return False
00087
00088 def set_internal_pointer_to_dataset(self, id):
00089 self.current_index = 0
00090 for dataset in self.datasets:
00091 if dataset.id == id:
00092 return True
00093 self.current_index += 1
00094 return False
00095
00096 def get_next_dataset(self):
00097 if self.current_index < len(self.datasets) - 1:
00098 self.current_index = self.current_index + 1
00099 return self.datasets[self.current_index]
00100 else:
00101 return False
00102
00103 def get_prev_dataset(self):
00104 if self.current_index > 0:
00105 self.current_index = self.current_index - 1
00106 return self.datasets[self.current_index]
00107 else:
00108 return False
00109
00110 def get_first_dataset(self):
00111 if len(self.datasets) > 0:
00112 self.current_index = 0
00113 return self.datasets[self.current_index]
00114 else:
00115 return False
00116
00117 def get_last_dataset(self):
00118 if len(self.datasets) > 0:
00119 self.current_index = len(self.datasets) - 1
00120 return self.datasets[self.current_index]
00121 else:
00122 return False
00123
00124
00125 def get_count(self):
00126 return len(self.datasets)
00127
00128 def add_dataset(self, dataset):
00129 self.datasets.append(dataset)
00130
00131 def delete_current_dataset(self):
00132 del self.datasets[self.current_index]
00133 dataset = self.get_prev_dataset()
00134 if False != dataset:
00135 return dataset
00136 else:
00137 dataset = self.get_next_dataset()
00138 return dataset
00139
00140
00141 def add_attribute_to_every_dataset(self, name):
00142 for dataset in self.datasets:
00143 dataset.dict[name]=''
00144
00145