Best Python code snippet using elementium_python
testJsEsAlucantemp.py
Source:testJsEsAlucantemp.py
...61 data = json.load(open(objectRecieved['fileReceived'], encoding='ISO-8859-1', mode='r'))62 dictionary = {x: None for x in objectRecieved['db']['siteConfig']['js']['jsCols']}63 if os.path.basename(objectRecieved['fileReceived']).startswith('INVERTER'):64 try:65 dictionary.__delitem__('0')66 dictionary.__delitem__('1')67 dictionary.__delitem__('2')68 dictionary.__delitem__('4')69 dictionary.__delitem__('EnergyReal_WAC_Sum_Consumed')70 dictionary.__delitem__('PowerReal_P_Sum')71 except:72 print("key not exist")73 for key, value in dictionary.items():74 if key in data['Body']:75 dictionary[key] = 076 for k, v in data['Body'][key]['Values'].items():77 dictionary[key] += dictionaryBuilder(key, v)78 dictionary['type'] = "inverter"79 elif os.path.basename(objectRecieved['fileReceived']).startswith('METER'):80 try:81 dictionary.__delitem__('DAY_ENERGY')82 dictionary.__delitem__('TOTAL_ENERGY')83 dictionary.__delitem__('PAC')84 dictionary.__delitem__('YEAR_ENERGY')85 dictionary.__delitem__('0')86 dictionary.__delitem__('1')87 dictionary.__delitem__('2')88 dictionary.__delitem__('4')89 except:90 print("key not exist")91 for key, value in dictionary.items():92 if key in data['Body']['0']:93 dictionary[key] = 094 v = data['Body']['0'][key]95 dictionary[key] += dictionaryBuilder(key, v)96 dictionary['type'] = "sensor"97 elif os.path.basename(objectRecieved['fileReceived']).startswith('SENSOR'):98 try:99 dictionary.__delitem__('DAY_ENERGY')100 dictionary.__delitem__('TOTAL_ENERGY')101 dictionary.__delitem__('PAC')102 dictionary.__delitem__('YEAR_ENERGY')103 dictionary.__delitem__('EnergyReal_WAC_Sum_Consumed')104 dictionary.__delitem__('PowerReal_P_Sum')105 except:106 print("key not exist")107 for key, value in dictionary.items():108 if key in data['Body']['1']:109 dictionary[key] = 0110 for k, v in data['Body']['1'][key].items():111 if 'Value' in k:112 dictionary[key] += dictionaryBuilder(key, v)113 dictionary['type'] = "meter"114 elif os.path.basename(objectRecieved['fileReceived']).startswith('ERROR'):115 try:116 dictionary.__delitem__('DAY_ENERGY')117 dictionary.__delitem__('TOTAL_ENERGY')118 dictionary.__delitem__('PAC')119 dictionary.__delitem__('YEAR_ENERGY')120 dictionary.__delitem__('EnergyReal_WAC_Sum_Consumed')121 dictionary.__delitem__('PowerReal_P_Sum')122 dictionary.__delitem__('0')123 dictionary.__delitem__('1')124 dictionary.__delitem__('2')125 dictionary.__delitem__('4')126 except:127 print("key not exist")128 dictionary = data129 dictionary['type'] = "error"130 elif os.path.basename(objectRecieved['fileReceived']).startswith('LOG'):131 try:132 dictionary.__delitem__('DAY_ENERGY')133 dictionary.__delitem__('TOTAL_ENERGY')134 dictionary.__delitem__('PAC')135 dictionary.__delitem__('YEAR_ENERGY')136 dictionary.__delitem__('EnergyReal_WAC_Sum_Consumed')137 dictionary.__delitem__('PowerReal_P_Sum')138 dictionary.__delitem__('0')139 dictionary.__delitem__('1')140 dictionary.__delitem__('2')141 dictionary.__delitem__('4')142 except:143 print("key not exist")144 dictionary = data145 dictionary['type'] = "log"146 dictionary['Timestamp'] = data['Head']['Timestamp']147 print(dictionary)148 buffDict = dictionary.copy()149 del dictionary['type']150 buffDict['@timestamp'] = buffDict['Timestamp']151 del buffDict['Timestamp']152 type = buffDict['type']153 del buffDict['type']154 typeofdata = None155 if type == "inverter":156 typeofdata = "data"157 elif type == "error":158 typeofdata = "error"159 elif type == "sensor":160 typeofdata = "sensor"161 elif type == "meter":162 typeofdata = "meter"163 elif type == "log":164 typeofdata = "log"165 index["index"]["_id"] = str(buffDict['@timestamp'])166 buffer += str(json.dumps(index) + "\n")167 buffer += str(json.dumps({"@timestamp": buffDict["@timestamp"], typeofdata: buffDict}) + "\n")168 isCreated = requests.get(url='https://search-reon-yf6s4jcgv6tapjin4xblwtgk6y.us-east-2.es.amazonaws.com/alucan/_doc/' + str(buffDict['@timestamp']).replace("+", "%2B"))169 print("is created " + str(isCreated.status_code))170 if isCreated.status_code == 200:171 update = requests.post(url='https://search-reon-yf6s4jcgv6tapjin4xblwtgk6y.us-east-2.es.amazonaws.com/alucan/_doc/' + str(buffDict['@timestamp']).replace("+", "%2B") + "/_update",172 headers={"content-type": "application/json"},173 json={"doc": {typeofdata: buffDict}})174 print(update.content)175 else:176 a = requests.put(url='https://search-reon-yf6s4jcgv6tapjin4xblwtgk6y.us-east-2.es.amazonaws.com/alucan/_doc/_bulk',177 headers={"content-type": "application/json"},178 data=buffer)179 print(a.status_code)180 CheckOldData()181 timeStamp = dictionary['Timestamp'].replace('T', ' ')182 timeStamp = timeStamp.replace('+05:00', '')183 unixTimeStamp = int(time.mktime(datetime.datetime.strptime(timeStamp, "%Y-%m-%d %H:%M:%S").timetuple()))184 unixTimeStamp = unixTimeStamp * 1000185 dictionary.__delitem__('Timestamp')186 print("match "+str(typeofdata in ['inverter', 'sensor']))187 if typeofdata in ['data', 'sensor', 'meter']:188 try:189 for k, v in dictionary.items():190 if v is not None:191 predixConnection.timeSeries.queue(objectRecieved['db']['siteConfig']['js'][k]['tag'],192 value=str(v),193 timestamp=unixTimeStamp,194 quality=3)195 print(Fore.YELLOW + objectRecieved['db']['siteConfig']['js'][k]['tag'] + Fore.RESET)196 print(Fore.GREEN + predixConnection.timeSeries.send() + Fore.RESET)197 except Exception:198 print("No internet")199 with open("DefaultDataStore/Default_Store.csv", "a") as file:...
linked_list_test.py
Source:linked_list_test.py
...72 self.list.append("Prof. Plum")73 self.list.append("Mrs. Peacock")74 self.list.append("Mr. Boddy")75 # Delete the list head76 self.list.__delitem__(0)77 self.assertTrue(self.list.head.data == "Mrs. Peacock")78 # Delete the list tail79 self.list.__delitem__(1)80 self.assertTrue(self.list.head.next_node is None)81 new_length = len(self.list)82 self.assertTrue(new_length == 1)83 @unittest.skip('Extra Challenge: __delitem__ method.')84 def test_delete_value_not_in_list(self):85 self.list.append("Prof. Plum")86 self.list.append("Mrs. Peacock")87 self.list.append("Mr. Boddy")88 with self.assertRaises(IndexError):89 self.list.__delitem__(3)90 @unittest.skip('Extra Challenge: __delitem__ method.')91 def test_delete_empty_list(self):92 with self.assertRaises(IndexError):93 self.list.__delitem__(1)94 @unittest.skip('Extra Challenge: __delitem__ method.')95 def test_delete_next_reassignment(self):96 self.list.append("Prof. Plum")97 self.list.append("Mrs. White")98 self.list.append("Mrs. Peacock")99 self.list.append("Mr. Boddy")100 self.list.__delitem__(1)101 self.list.__delitem__(1)102 self.assertTrue(self.list.head.next_node.data == "Prof. Plum")103if __name__ == '__main__':...
gaoyuan.py
Source:gaoyuan.py
...41 continue42 sum[j,i] += \43 self.cube[k,j,i]*self.header["CDELT3"]/1000.44 header_new = self.header45 header_new.__delitem__("NAXIS4")46 header_new.__delitem__("CTYPE4")47 header_new.__delitem__("CRPIX4")48 header_new.__delitem__("CDELT4")49 header_new.__delitem__("CRVAL4")50 header_new["NAXIS"] = 251 header_new.__delitem__("NAXIS3")52 header_new.__delitem__("CTYPE3")53 header_new.__delitem__("CRPIX3")54 header_new.__delitem__("CDELT3")55 header_new.__delitem__("CRVAL3")56 header_new.__delitem__("RESTFREQ")57 header_new.__delitem__("SPECSYS")58 header_new.__delitem__("DATAMAX")59 header_new.__delitem__("DATAMIN")60 header_new.add_history("squashed by GY")61 return sum, header_new62# def channel_maps():63#=================Class Cube======================64#=================Function mytrim=================65def mytrim(d, vmin, vmax):66 dd = (d+vmin)/(vmin+vmax)67 return np.clip(dd, 0, 1)...
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!!