Best Python code snippet using localstack_python
Analyzer.py
Source:Analyzer.py
...64 def get_end_date(self):65 return self.end_date66 def get_name_from_dates(self):67 return str(self.get_start_date()) + '_' + str(self.get_end_date())68 def get_unzipped_size(self):69 size_in_bytes = util.get_directory_size(self.path)70 size_in_mb = util.convert_bytes_to_megabytes(size_in_bytes)71 return size_in_mb72 def read_dates_from_folder_name(self):73 start_date_no_format = self.folder_name.split('-')[0]74 end_date_no_format = self.folder_name.split('-')[1]75 finished_dates = []76 for date in [start_date_no_format, end_date_no_format]:77 year = date.split('_')[-1]78 month = date[:3]79 day = date.split('_')[0][-2:]80 finished_date = str(year) + '-' + str(month) + '-' + str(day)81 finished_dates.append(util.get_datetime_from_string(finished_date))82 return finished_dates83class BigTimePeriod(TimePeriod):84 def __init__(self, paths, start_end_dates):85 self.paths = paths86 self.folder_names = []87 for path in self.paths:88 self.folder_names.append(path.stem)89 self.earliest_start_date = start_end_dates[0]90 self.latest_end_date = start_end_dates[1]91 def get_name_from_dates(self):92 return str(self.get_earliest_date()) + '_' + str(self.get_latest_date())93 def get_earliest_date(self):94 return self.earliest_start_date95 def get_latest_date(self):96 return self.latest_end_date97 def get_unzipped_size(self):98 size_in_bytes = 099 for path in self.paths:100 size_in_bytes = size_in_bytes + util.get_directory_size(path)101 size_in_mb = util.convert_bytes_to_megabytes(size_in_bytes)102 return size_in_mb103class Analyzer:104 def __init__(self, settings_file, ready_zips):105 self.settings_dict = None106 self.load_settings(settings_file)107 self.time_periods = []108 self.big_time_period = None109 self.create_time_periods(ready_zips)110 self.analysis_data = {}111 def start_analysis(self):...
DataSizeInvestigator.py
Source:DataSizeInvestigator.py
...17 file_sizes = []18 file_size_in_mbs_per_day = []19 time_period_dates = []20 for time_period in self.time_periods:21 size_of_time_period = time_period.get_unzipped_size()22 time_period_time = time_period.get_name_from_dates()23 period_length_in_days = util.get_difference_between_datetimes(24 time_period.get_end_date(),25 time_period.get_start_date(),26 interval='days'27 )28 time_period_mbs_per_day = round(size_of_time_period / period_length_in_days, 3)29 time_period_dates.append(time_period_time)30 file_size_in_mbs_per_day.append(time_period_mbs_per_day)31 file_sizes.append(size_of_time_period)32 file_sizes_df_only = pd.DataFrame({'size': file_sizes}, index=time_period_dates)33 file_size_in_mbs_per_day_only = pd.DataFrame(34 {'size_per_day': file_size_in_mbs_per_day}, index=time_period_dates)35 self.investigated_period_data['periods'] = file_sizes_df_only.join(file_size_in_mbs_per_day_only)36 big_period_size = self.big_time_period.get_unzipped_size()37 big_period_length_in_days = util.get_difference_between_datetimes(38 self.big_time_period.get_latest_date(),39 self.big_time_period.get_earliest_date(),40 interval='days'41 )42 mbs_per_day_big_period = round(big_period_size / big_period_length_in_days, 3)43 mbs_per_year_big_period = round(mbs_per_day_big_period / 365, 3)44 big_period_df = pd.DataFrame({45 'size': self.big_time_period.get_unzipped_size(),46 'size_per_day': mbs_per_day_big_period,47 'size_per_year': mbs_per_year_big_period48 },49 index=[self.big_time_period.get_name_from_dates()])50 self.investigated_period_data['big_period'] = big_period_df51 return self.investigated_period_data52 def create_plots(self):53 # TODO:54 print('bim bam plot created')55 def add_to_report(self):56 # TODO...
archives.py
Source:archives.py
...10LOG = logging.getLogger(__name__)11def is_zip_file(content):12 stream = io.BytesIO(content)13 return zipfile.is_zipfile(stream)14def get_unzipped_size(path: str):15 """Returns the size of the unzipped file."""16 with zipfile.ZipFile(path, "r") as zip_ref:17 return sum(f.file_size for f in zip_ref.infolist())18def unzip(path: str, target_dir: str, overwrite: bool = True) -> Optional[Union[str, Popen]]:19 from localstack.utils.platform import is_debian20 is_in_debian = is_debian()21 if is_in_debian:22 # Running the native command can be an order of magnitude faster in Alpine on Travis-CI23 flags = "-o" if overwrite else ""24 flags += " -q"25 try:26 return run("cd %s; unzip %s %s" % (target_dir, flags, path), print_error=False)27 except Exception as e:28 error_str = truncate(str(e), max_length=200)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!