def download_files(channel_id): ch: ChannelModel = ChannelModel.find_by_id(channel_id) if not ch: raise EntityNotFound( "The channel with id {} doesn't exist".format(channel_id)) tar_filename = ch.make_tar_file() return response.file_to_response(tar_filename, delete_after=True)
def rsync_files(channel_id): ch: ChannelModel = ChannelModel.find_by_id(channel_id) if not ch: raise EntityNotFound( "The channel with id {} doesn't exist".format(channel_id)) bash_filename = ch.bash_rsync_files() return response.file_to_response(bash_filename, delete_after=True)
def is_valid_upload_file(self, upload_file: UploadMseedFiles): """ Check if upload file is valid to be transferred to the storage area. :param upload_file: The UploadMseedFile structure. :return: A tuple (isValid: boolean, message: str) """ ch: ChannelModel = ChannelModel.find_by_id(self.channel_id) if not ch: raise EntityNotFound("Channel id {} not found".format( self.channel_id)) start_time = DateUtils.convert_string_to_utc(upload_file.start_time) stop_time = DateUtils.convert_string_to_utc(upload_file.end_time) sd = SeismicDataModel.find_by(channel_id=self.channel_id, start_time=start_time) if sd: return False, "File {} is in conflict with file {} at the channel {}-{}"\ .format(upload_file.file_name, sd.filename, ch.station.name, ch.name) if not ch.is_within_deltatime(start_time, stop_time): return False, "File {} is not within the channel's time interval".format( upload_file.file_name) if ch.sample_rate != upload_file.sample_rate: return False, "File {} has not the same sample rate than channel {}-{} {}"\ .format(upload_file.file_name, ch.station.name, ch.name, DateUtils.convert_datetime_to_utc(ch.start_time)) return True, ""
def update_channel(channel: dict): updated_channel = ChannelModel.update(channel) if not updated_channel: raise EntityNotFound("This channel doesn't exist.") return response.bool_to_response(updated_channel.save())
def test_channel_model(self): station: StationModel = StationModel.find_by(name="04A", creation_date="2016/159") self.assertIsNotNone(station) setup: ChannelModel = ChannelModel.find_by(station_id=station.id, start_time="2016/159") self.assertIsNotNone(setup) print(setup.to_dict()) print(setup.equipments)
def get_containers(self): """ Gets the channel and station that this data belong. :return: A tuple containing channel and station. """ ch: ChannelModel = ChannelModel.find_by_id(self.channel_id) station = ch.get_station() return ch, station
def rename_files(channel_id): progress_id = 'rename_' + channel_id with ProgressEvent(progress_id) as pe: ch: ChannelModel = ChannelModel.find_by_id(channel_id) if not ch: raise EntityNotFound( "The channel with id {} doesn't exist".format(channel_id)) ch.rename_data(pe) return response.string_to_response('Ok')
def get_metadata(channel_id): channel: ChannelModel = ChannelModel.find_by_id(channel_id) if not channel: raise EntityNotFound( "The channel id {} doesn't exist".format(channel_id)) mdh = MseedMetadataHandler(channel) file_path = mdh.save_metadata() return response.file_to_response(file_path, delete_after=True)
def test_metadata(self): ch = ChannelModel.find_by_id("XdrwcAlnazawNdnF") mdh = MseedMetadataHandler(ch) print(mdh.ch) print(mdh.st) print(mdh.nw) print(mdh.datalogger) print(mdh.sensor) mdh.save_metadata()
def delete_channel(channel_id): channel: ChannelModel = ChannelModel.find_by_id(channel_id) if not channel: raise EntityNotFound( "The channel id {} doesn't exist".format(channel_id)) deleted = channel.delete() if deleted: app_logger.info("Channel {}-{}-{} has been deleted".format( channel.get_station().name, channel.name, DateUtils.convert_datetime_to_utc(channel.start_time))) else: app_logger.warning("Channel {}-{}-{} could't be deleted.".format( channel.get_station().name, channel.name, DateUtils.convert_datetime_to_utc(channel.start_time))) return response.bool_to_response(deleted)
def is_public(self): channel: ChannelModel = ChannelModel.find_by_id(self.channel_id) return channel.get_station().public_data
def create_channel(channel_dict: dict): was_created = ChannelModel.create_channel(channel_dict) return response.bool_to_response(was_created)
def search_channels(station_search: Search): search_result: SearchResult = ChannelModel.search(station_search) return response.model_to_response(search_result)
def get_channel(channel_id: str): channel = ChannelModel.find_by_id(channel_id) if channel: return response.model_to_response(channel) return response.empty_response()