How to use readat method in Airtest

Best Python code snippet using Airtest

resample_data.py

Source:resample_data.py Github

copy

Full Screen

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')...

Full Screen

Full Screen

r.py

Source:r.py Github

copy

Full Screen

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...

Full Screen

Full Screen

f.py

Source:f.py Github

copy

Full Screen

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...

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 Airtest 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