Skip to content
Snippets Groups Projects
Commit 9aaa9e83 authored by Alex Diebold's avatar Alex Diebold
Browse files

added comparative functions to Instrument/Site/Experiment/FileType/File....

added comparative functions to Instrument/Site/Experiment/FileType/File. currently only support equal and not_equal. made progress in getting _sync() to work correctly with optional /experiment/ directory
parent 884b5411
Branches
No related tags found
No related merge requests found
......@@ -80,7 +80,25 @@ class Instrument(Base):
for i_f in self.instrument_filetypes:
output += '{}~'.format(i_f.filetype.name)
output += ' - {}'.format(self.description)
return output
return output + '\n'
def __eq__(self, other):
return ((self.name == other.name) and (self.site.name == other.site.name))
def __ne__(self, other):
return ((self.name != other.name) or (self.site.name != other.site.name))
def __lt__(self, other):
return False
def __le__(self, other):
return False
def __gt__(self, other):
return False
def __ge__(self, other):
return False
class Instrument_FileType(Base):
......@@ -99,7 +117,7 @@ class Instrument_FileType(Base):
self.filetype = filetype
def __repr__(self):
return 'Instrument -- {} | FileType -- {}'.format(self.instrument.name, self.filetype.name)
return 'Instrument -- {} | FileType -- {}\n'.format(self.instrument.name, self.filetype.name)
class Site_Experiment(Base):
......@@ -118,7 +136,7 @@ class Site_Experiment(Base):
self.experiment = experiment
def __repr__(self):
return 'Site -- {} | Experiment -- {}'.format(self.site.name, self.experiment.name)
return 'Site -- {} | Experiment -- {}\n'.format(self.site.name, self.experiment.name)
class Site(Base):
......@@ -142,14 +160,32 @@ class Site(Base):
for s_e in self.site_experiments:
output += '{}~'.format(s_e.experiment.name)
output += ' - {}'.format(self.description)
return output
return output + '\n'
def __eq__(self, other):
return self.name == other.name
def __ne__(self, other):
return self.name != other.name
def __lt__(self, other):
return False
def __le__(self, other):
return False
def __gt__(self, other):
return False
def __ge__(self, other):
return False
class Experiment(Base):
__tablename__ = 'Experiments'
experiment_id = Column(Integer, primary_key=True)
name = Column(String(255))
name = Column(String(255), unique=True)
start_time = Column(DateTime)
end_time = Column(DateTime)
site = relationship('Site', secondary='Site_Experiments', viewonly=True)
......@@ -170,8 +206,25 @@ class Experiment(Base):
for s_e in self.site_experiments:
output += '{}~'.format(s_e.site.name)
output += ' - {}'.format(self.description)
return output
return output + '\n'
def __eq__(self, other):
return self.name == other.name
def __ne__(self, other):
return self.name != other.name
def __lt__(self, other):
return False
def __le__(self, other):
return False
def __gt__(self, other):
return False
def __ge__(self, other):
return False
class FileType(Base):
......@@ -207,7 +260,25 @@ class FileType(Base):
for i_f in self.instrument_filetypes:
output += '{}~'.format(i_f.instrument.name)
output += ' - {}'.format(self.description)
return output
return output + '\n'
def __eq__(self, other):
return ((self.name == other.name) and (self.glob_pattern == other.glob_pattern) and (self.format_pattern == other.format_pattern))
def __ne__(self, other):
return ((self.name != other.name) or (self.glob_pattern != other.glob_pattern) or (self.format_pattern != other.format_pattern))
def __lt__(self, other):
return False
def __le__(self, other):
return False
def __gt__(self, other):
return False
def __ge__(self, other):
return False
class File(Base):
......@@ -238,7 +309,25 @@ class File(Base):
self.end_time = end_time
def __repr__(self):
return '{} - {} - {} - {} - {} - {}'.format(self.instrument.name, self.experiment.name, self.filetype.name, self.relative_path, self.start_time, self.end_time)
return '{} - {} - {} - {} - {} - {}\n'.format(self.instrument.name, self.experiment.name, self.filetype.name, self.relative_path, self.start_time, self.end_time)
def __eq__(self, other):
return self.relative_path == other.relative_path
def __ne__(self, other):
return self.relative_path != other.relative_path
def __lt__(self, other):
return False
def __le__(self, other):
return False
def __gt__(self, other):
return False
def __ge__(self, other):
return False
'''given a string, parse out the date and return a datetime
......@@ -561,6 +650,8 @@ def _sync(args):
print('\nFILE sync output')
print(OUTPUT.FILE.value)
'''
for step in os.walk('data'):
path = step[0]
dirname = os.path.dirname(path).split('/')[len(os.path.dirname(path).split('/'))-1]
......@@ -580,6 +671,27 @@ def _sync(args):
print(curr_file)
session.add(curr_file)
break
'''
for step in os.walk('data'):
if step[2]:
path = step[0]
site_name = path.split('/')[1]
inst_name = os.path.basename(path)
if len(path.split('/')) == 4:
exp_name = path.split('/')[2]
else:
exp_name = 'n/a'
files = step[2]
site = session.query(Site).filter(Site.name == site_name).all()
inst = session.query(Instrument).filter(Instrument.anem == inst_name)
inst = inst.filter(Instrument.site.has(name = site_name)).all()
exp = session.query(Experiment).filter(Experiment.name == exp_name).all()
if site and inst and exp:
site = site[0]
inst = inst[0]
exp = exp[0]
session.commit()
'''
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment