def set_case_like_db(self, obs): c = self.db[CASE_COLLECTION].find_one(obs['case'].get_query()) if c is not None: obs['case'] = Case.from_db(self.db, c['_id']) obs['saved'] = True return True else: return False
def set_case_like_local(self, obs): casename = str(obs['case']) + ".json" if casename in [cn.name for cn in self.casepath.iterdir()]: path = str(self.casepath.joinpath(casename)) obs['case'] = Case.from_JSON(path) obs['saved'] = True return True else: return False
def init_obs(self, observation): self.obsKeys.append(str(observation)) # d = { 'obs': observation, 'wavpath': observation.export_to_wav(self.wavpath), 'case': Case.new_from_obs(observation, self.author), 'modified': False, 'saved': False } if self.local: self.set_case_like_local(d) else: self.set_case_like_db(d) sR, t, p = observation.get_signal() d['t0'] = t.min() d['sn'] = [t, p] self.observations[str(observation)] = d