Best Python code snippet using Airtest
resample_data.py
Source: resample_data.py
1""""2- This file is used for resampling data monthly.3- Original data will record in each 10 seconds or 1 minute4- MySQL query group by day5- Resampling data will resample the query data to be monthly6- This file will operate monthly at the end of month, eg. 31 January at 11:59PM7- This will insert to table: month_data8"""9import connectToDatabase as connect10import pandas as pd11from datetime import datetime12import logging13TABLE_NAME_DATA_MONTH = "month_data"14MONTH = datetime.today().month - 115YEAR = datetime.today().year16""""17- Replace empty data(string) with NaN18- convert data type to numeric19- Fill missing values by applying interpolate function:20 y2 is missing, y2 = (y3+y1)/221"""22"""" COMMENT23This loop through all MeterId:241 get one meterID and use it to get all data within particular month252 use resampling function to fill NaN values and resample to be in month263 insert data in month format to month_data table that will be used in forecasting27"""28def get_meter_data(meter_id_in, meter_data_in, mydb_connection):29 meter_data_in['ReadAt'] = pd.to_datetime(meter_data_in['ReadAt'])30 meter_data_in.rename(columns={'ReadAt': 'usage_date'}, inplace=True)31 meter_data_in.set_index('usage_date', inplace=True)32 meter_data_in['KWH'] = pd.to_numeric(meter_data_in['KWH'])33 meter_data_in.interpolate(method='linear', inplace=True)34 meter_data_diff = meter_data_in.diff()35 data_in_month = meter_data_diff.resample('M').sum()36 data_in_month['MeterId'] = int(meter_id_in)37 connect.insert_to_database(data_in_month, mydb_connection, TABLE_NAME_DATA_MONTH)38if __name__ == "__main__":39 mydb_sqlalchemy = connect.database_connection_with_sqlalchemy()40 sql_query_get_meter_id = "SELECT MeterId FROM Meter"41 MeterID = connect.read_from_database(sql_query_get_meter_id, mydb_sqlalchemy)42 meter_id_to_array = MeterID.values.reshape(-1, ).tolist()43 for meter_id in meter_id_to_array:44 try:45 sql_query_get_meter_data = "SELECT MAX(KWH) AS KWH, DATE_FORMAT(ReadAt, \"%Y-%m-%d 00:00:00\") AS ReadAt " \46 "FROM MeterData WHERE MeterId={0} AND YEAR(ReadAt)={1} AND MONTH(ReadAt)={2} " \47 "GROUP BY ReadAt, YEAR(ReadAt), MONTH(ReadAt), DAY(ReadAt)".format(meter_id,48 YEAR, MONTH)49 meter_data = connect.read_from_database(sql_query_get_meter_data, mydb_sqlalchemy)50 get_meter_data(meter_id, meter_data, mydb_sqlalchemy)51 except Exception as err:52 logging.basicConfig(filename="Error_at_resample_data_log.log", filemode='a',53 format='%(asctime)s - %(levelname)s - %(message)s')...
r.py
Source: r.py
1import sys2@profile3def main():4 inp = map(int, sys.stdin.read().split())5 n = inp[0]6 readAt = 1 + (n * n)7 tests = inp[readAt]8 readAt += 19 for test in xrange(tests):10 q = inp[readAt:readAt + 4]11 readAt += 412 #x1 = q[0]13 #y1 = q[1]14 #x2 = q[2]15 #y2 = q[3]16 d = {}17 count = 018 startIndex = (n * (q[0] - 1)) + (q[1] - 1)19 rowLength = (q[3] - q[1]) + 120 rowCount = (q[2] - q[0]) + 121 offset = n - rowLength22 i = startIndex + 123 24 for row in xrange(rowCount):25 br = i26 er = rowLength + i27 for x in xrange(br, er):28 if not inp[x] in d:29 count += 130 d[inp[x]] = 131 if count == 10:32 break33 if count == 10:34 break35 36 i += offset + rowLength37 print count...
f.py
Source: f.py
1import sys2@profile3def main():4 inp = map(int, sys.stdin.read().split())5 tests = inp[0]6 readAt = 17 for test in xrange(tests):8 nk = inp[readAt:readAt + 2]9 readAt += 210 spots = {}11 for nn in xrange(nk[0]):12 sfp = inp[readAt:readAt + 3]13 readAt += 314 s = sfp[0]15 f = sfp[1]16 p = sfp[2]17 if not p in spots:18 spots[p] = []19 spots[p].append((s, f))20 total = 021 for spot in spots:22 ss = sorted(spots[spot], key=lambda x: x[1])23 finish = 024 for s in ss:25 if finish <= s[0]:26 finish = s[1]27 total += 128 print total...
Check out the latest blogs from LambdaTest on this topic:
Unit testing is typically software testing within the developer domain. As the QA role expands in DevOps, QAOps, DesignOps, or within an Agile team, QA testers often find themselves creating unit tests. QA testers may create unit tests within the code using a specified unit testing tool, or independently using a variety of methods.
People love to watch, read and interact with quality content — especially video content. Whether it is sports, news, TV shows, or videos captured on smartphones, people crave digital content. The emergence of OTT platforms has already shaped the way people consume content. Viewers can now enjoy their favorite shows whenever they want rather than at pre-set times. Thus, the OTT platform’s concept of viewing anything, anytime, anywhere has hit the right chord.
Agile project management is a great alternative to traditional methods, to address the customer’s needs and the delivery of business value from the beginning of the project. This blog describes the main benefits of Agile for both the customer and the business.
The purpose of developing test cases is to ensure the application functions as expected for the customer. Test cases provide basic application documentation for every function, feature, and integrated connection. Test case development often detects defects in the design or missing requirements early in the development process. Additionally, well-written test cases provide internal documentation for all application processing. Test case development is an important part of determining software quality and keeping defects away from customers.
I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.
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!!