How to use build_intervals method in yandex-tank

Best Python code snippet using yandex-tank

database_cleanup.py

Source:database_cleanup.py Github

copy

Full Screen

...19 now_2.strftime('%Y-%m-%d %H:%M:%S'),20 admin=True)21 if len(items) == 0:22 return23 intervals = build_intervals(items, now_2, 10)24 remove = []25 for i in intervals:26 if len(i) > 0:27 remove += i[1:]28 delete_items(remove)29def cleanup_lt_24(device_id, report_type):30 print("\t\t1 day cleanup")31 now_4 = get_now() - datetime.timedelta(hours=4)32 now_24 = get_now() - datetime.timedelta(hours=24)33 print "Working between %s and %s" % (now_24, now_4)34 items = database.database.get_reports_between(35 device_id,36 report_type,37 now_24.strftime('%Y-%m-%d %H:%M:%S'),38 now_4.strftime('%Y-%m-%d %H:%M:%S'),39 admin=True)40 if len(items) == 0:41 return42 intervals = build_intervals(items, now_4, 30)43 remove = []44 for i in intervals:45 if len(i) > 0:46 remove += i[1:]47 delete_items(remove)48def cleanup_lt_168(device_id, report_type):49 print("\t\t1 week cleanup")50 now_24 = get_now() - datetime.timedelta(hours=24)51 now_168 = get_now() - datetime.timedelta(hours=168)52 print "Working between %s and %s" % (now_168, now_24)53 items = database.database.get_reports_between(54 device_id,55 report_type,56 now_168.strftime('%Y-%m-%d %H:%M:%S'),57 now_24.strftime('%Y-%m-%d %H:%M:%S'),58 admin=True)59 if len(items) == 0:60 return61 intervals = build_intervals(items, now_24, 60)62 remove = []63 for i in intervals:64 if len(i) > 0:65 remove += i[1:]66 delete_items(remove)67#TODO: Add larger than a week: Once every 360m/6h68def cleanup_loop():69 for d in database.database.get_all_device_ids():70 di = d['id']71 for r in database.database.get_all_report_type_ids():72 ri = r['id']73 cleanup_lt_2(di, ri)74 cleanup_lt_24(di, ri)75 cleanup_lt_168(di, ri)76def delete_items(items):77 if len(items) > 0:78 database.database.delete_reports([x['id'] for x in items])79def build_intervals(items, start, interval):80 results = []81 td = datetime.timedelta(minutes=interval)82 current_limit = start - td83 number_items = len(items)84 handled = 085 itemsr = items[::-1]86 while number_items > handled:87 group = []88 for i in itemsr[handled:]:89 if i['time'] <= current_limit:90 break91 else:92 group.append(i)93 handled += 1...

Full Screen

Full Screen

period.py

Source:period.py Github

copy

Full Screen

...20 splits.append(first_day)21 end = datetime.datetime(self.end_year, self.end_month, self.end_day, 0, 0, 0)22 if end > splits[-1]:23 splits.append(end)24 return self.build_intervals(splits)25 26 def split_by_month(self):27 splits = []28 start = self.start_datetime29 while start < self.end_datetime: 30 splits.append(start) 31 start = start + relativedelta.relativedelta(months=+1)32 if self.end_datetime > splits[-1]:33 splits.append(self.end_datetime)34 35 return self.build_intervals(splits)36 37 def split_by_week(self):38 return self.split_by_day_ammount(7)39 def split_by_day_ammount(self, ammount):40 diff = self.end_datetime - self.start_datetime41 splits = []42 for i in range((diff.days//ammount) + 1):43 splits.append(self.start_datetime + datetime.timedelta(days=i*ammount))44 45 end = datetime.datetime(self.end_year, self.end_month, self.end_day, 0, 0, 0)46 if end > splits[-1]:47 splits.append(end)48 return self.build_intervals(splits)49 50 def split_by_day(self):51 return self.split_by_day_ammount(1)52 53 def build_intervals(self, splits):54 splitted_intervals = []55 for i in range(len(splits)-1):56 splitted_intervals.append((splits[i], splits[i+1] - datetime.timedelta(seconds=1)))...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run yandex-tank automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful