Best Python code snippet using robotframework-appiumlibrary_python
vtkSymbols.py
Source:vtkSymbols.py
...44 transform = vtk.vtkTransform()45 transform.Translate(startPoint)46 transform.Concatenate(matrix)47 #transform.Scale(length, length, length)48 transform.Scale(self.project.get_element_size(), self.project.get_element_size(), self.project.get_element_size())49 transformPD = vtk.vtkTransformPolyDataFilter()50 transformPD.SetTransform(transform)51 transformPD.SetInputConnection(arrowSource.GetOutputPort())52 mapper = vtk.vtkPolyDataMapper()53 actor = vtk.vtkActor()54 mapper.SetInputConnection(arrowSource.GetOutputPort())55 actor.SetUserMatrix(transform.GetMatrix())56 actor.SetMapper(mapper)57 return actor58 def getElementAxe(self, element):59 center, direction = element.get_local_coordinate_system_info()60 arrows = []61 x = self.arrow(center, center+direction[0])62 x.GetProperty().SetColor(1,0,0)63 y = self.arrow(center, center+direction[1])64 y.GetProperty().SetColor(0,1,0)65 z = self.arrow(center, center+direction[2])66 z.GetProperty().SetColor(0,0,1)67 arrows.append(x)68 arrows.append(y)69 arrows.append(z)70 return arrows71 def getSpring(self, node, u_def=[]):72 a = self.getReal(node.get_lumped_stiffness())73 base_length = self.project.preprocessor.structure_principal_diagonal/1074 element_length = self.project.get_element_size()75 if base_length/10 < element_length*1.5:76 shift = base_length/1077 else:78 shift = element_length*1.579 v = [1,2,3]80 for i in range(0,3):81 try:82 if a[i] is None or a[i] == 0:83 v[i] = 084 elif a[i] < 0:85 v[i] = -1*v[i]86 except Exception as log_error:87 if isinstance(a[i], np.ndarray):88 pass89 else:90 print(str(log_error))91 if v.count(0) == 3:92 return []93 arrows = []94 for i in range(3):95 if v[i] == 0:96 continue97 b = ActorSpring(node, self.project.get_element_size(), base_length, xyz=v[i], u_def=u_def)98 b.setShiftValue(shift)99 b.setNormalizedColor([1,0,1])100 b.setNormalizedColor([242/255,121/255,0])101 b.build()102 arrows.append(b.getActor())103 return arrows104 def getDamper(self, node, u_def=[]):105 a = self.getReal(node.get_lumped_dampings())106 base_length = self.project.preprocessor.structure_principal_diagonal/10107 element_length = self.project.get_element_size()108 if base_length/20 < element_length*1.5:109 shift = base_length/20110 else:111 shift = element_length/2112 v = [1,2,3]113 for i in range(0,3):114 try:115 if a[i] is None or a[i] == 0:116 v[i] = 0117 elif a[i] < 0:118 v[i] = -1*v[i]119 except Exception as log_error:120 if isinstance(a[i], np.ndarray):121 pass122 else:123 print(str(log_error))124 if v.count(0) == 3:125 return []126 arrows = []127 for i in range(3):128 if v[i] == 0:129 continue130 a = ActorArrow(node, self.project.get_element_size(), base_length, xyz=v[i], u_def=u_def)131 a.setNormalizedColor([242/255,121/255,0])132 a.setNormalizedColor([1,0,1])133 a.setShiftValue(shift)134 a.removeTipLength()135 a.build()136 arrows.append(a.getActor())137 return arrows138 def getArrowBC(self, node, u_def=[]):139 a = self.getReal(node.getStructuralBondaryCondition())140 base_length = self.project.preprocessor.structure_principal_diagonal/10141 element_length = self.project.get_element_size()142 if base_length/20 < element_length/2:143 shift = base_length/20144 else:145 shift = element_length/2146 v = [1,2,3]147 for i in range(0,3):148 try:149 if a[i] is None:150 v[i] = 0151 elif a[i] < 0:152 v[i] = -1*v[i]153 except Exception as log_error:154 if isinstance(a[i], np.ndarray):155 pass156 else:157 print(str(log_error))158 159 if v.count(0) == 3:160 return []161 arrows = []162 for i in range(3):163 if v[i] == 0:164 continue165 a = ActorArrow(node, self.project.get_element_size(), base_length, xyz=v[i], u_def=u_def)166 a.removeShaftRadius()167 a.setNormalizedColor([0,1,0])168 a.setShiftValue(shift)169 a.build()170 arrows.append(a.getActor())171 return arrows172 def getArrowForce(self, node):173 a = self.getReal(node.get_prescribed_loads())174 base_length = self.project.preprocessor.structure_principal_diagonal/10175 element_length = self.project.get_element_size()176 if base_length/20 < element_length/2:177 shift = base_length/20178 else:179 shift = element_length/2180 v = [1,2,3]181 for i in range(0,3):182 try:183 if a[i] is None or a[i] == 0:184 v[i] = 0185 elif a[i] < 0:186 v[i] = -1*v[i]187 except Exception as log_error:188 if isinstance(a[i], np.ndarray):189 pass190 else:191 print(str(log_error))192 if v.count(0) == 3:193 return []194 arrows = []195 for i in range(3):196 if v[i] == 0:197 continue198 a = ActorArrow(node, self.project.get_element_size(), base_length, xyz=v[i])199 a.setNormalizedColor([1,0,0])200 a.setShiftValue(shift)201 a.build()202 arrows.append(a.getActor())203 return arrows204 def getArrowRotation(self, node):205 a = self.getReal(node.getStructuralBondaryCondition())206 base_length = self.project.preprocessor.structure_principal_diagonal/10207 element_length = self.project.get_element_size()208 if base_length/20 < element_length/2:209 shift1 = base_length/20210 shift2 = 2.7*shift1211 else:212 shift1 = element_length/2213 shift2 = 6.5*shift1214 v = [1,2,3]215 for i in range(3,6):216 try:217 if a[i] is None or a[i] == 0:218 v[i-3] = 0219 elif a[i] < 0:220 v[i-3] = -1*v[i-3]221 except Exception as log_error:222 if isinstance(a[i], np.ndarray):223 pass224 else:225 print(str(log_error))226 if v.count(0) == 3:227 return []228 arrows = []229 for i in range(3):230 if v[i] == 0:231 continue232 233 a = ActorArrow(node, self.project.get_element_size(), base_length, xyz=v[i])234 a.removeShaftRadius()235 a.setNormalizedColor([0, 1, 1])236 a.setShiftValue(shift1)237 a.build()238 arrows.append(a.getActor())239 b = ActorArrow(node, self.project.get_element_size(), base_length, xyz=v[i])240 b.removeShaftRadius()241 b.setNormalizedColor([0,1,1])242 b.setShiftValue(shift2)243 b.build()244 arrows.append(b.getActor())245 return arrows246 def getArrowMomento(self, node):247 a = self.getReal(node.get_prescribed_loads())248 base_length = self.project.preprocessor.structure_principal_diagonal/10249 element_length = self.project.get_element_size()250 if base_length/20 < element_length/2:251 shift1 = base_length/20252 shift2 = 2.7*shift1253 else:254 shift1 = element_length/2255 shift2 = 6.5*shift1256 v = [1,2,3]257 for i in range(3,6):258 try:259 if a[i] is None or a[i] == 0:260 v[i-3] = 0261 elif a[i] < 0:262 v[i-3] = -1*v[i-3]263 except Exception as log_error:264 if isinstance(a[i], np.ndarray):265 pass266 else:267 print(str(log_error))268 if v.count(0) == 3:269 return []270 arrows = []271 for i in range(3):272 if v[i] == 0:273 continue274 a = ActorArrow(node, self.project.get_element_size(), base_length, xyz=v[i])275 a.setNormalizedColor([0,0,1])276 a.setShiftValue(shift1)277 a.build()278 arrows.append(a.getActor())279 b = ActorArrow(node, self.project.get_element_size(), base_length, xyz=v[i])280 b.setNormalizedColor([0,0,1])281 b.setShiftValue(shift2)282 b.removeShaftRadius()283 b.build()284 arrows.append(b.getActor())285 return arrows286 def getReal(self, vector):287 new_vector = vector.copy()288 for i in range(len(vector)):289 if type(vector[i]) == complex:290 new_vector[i] = vector[i].real...
audio_tfrecord_analysis.py
Source:audio_tfrecord_analysis.py
...54 k2 = item % self._base55 if k2 not in self._values[k1]:56 return None57 return self._values[k1][k2]58def get_element_size(element):59 if isinstance(element[0], bytes):60 return len(element[0].decode("utf-8").strip().split())61 return len(element)62def freq_percent(counter):63 cnt = 0.64 current_idx = 065 margin_values = []66 for val in range(counter.min_value, counter.max_value + 1):67 this_cnt = counter[val]68 if this_cnt:69 cnt += this_cnt70 percent = cnt / counter.total71 while (current_idx < len(_DISPLAY_PERCENTS)72 and percent > _DISPLAY_PERCENTS[current_idx]):73 margin_values.append(val)74 current_idx += 175 if current_idx == len(_DISPLAY_PERCENTS):76 break77 return margin_values78def main(dataset, feature_extractor=None):79 audio_counter = BigCounter()80 transcript_counter = BigCounter()81 translation_counter = BigCounter()82 has_translation = False83 total_seconds = 0.84 for idx, sample in enumerate(dataset.build().as_numpy_iterator()):85 if idx == 0:86 if "translation" in sample:87 has_translation = True88 audio_length = get_element_size(sample["audio"])89 audio_length //= feature_extractor.feature_dim90 total_seconds += feature_extractor.seconds(91 numpy.reshape(sample["audio"], [-1, feature_extractor.feature_dim]))92 audio_counter.count(audio_length)93 transcript_counter.count(get_element_size(sample["transcript"]))94 if has_translation:95 translation_counter.count(get_element_size(sample["translation"]))96 logging.info("Total %d samples, %.2f hours", audio_counter.total, total_seconds / 3600.)97 logging.info(f"Max audio size: {audio_counter.max_value}, min audio size: {audio_counter.min_value}")98 logging.info("Audio feature size distribution: ")99 for percent, margin in zip(_DISPLAY_PERCENTS, freq_percent(audio_counter)):100 logging.info(f" {percent} samples <= {margin}")101 logging.info("")102 logging.info("Transcript distribution: ")103 for percent, margin in zip(_DISPLAY_PERCENTS, freq_percent(transcript_counter)):104 logging.info(f" {percent} samples <= {margin}")105 if has_translation:106 logging.info("")107 logging.info("Translation distribution: ")108 for percent, margin in zip(_DISPLAY_PERCENTS, freq_percent(translation_counter)):109 logging.info(f" {percent} samples <= {margin}")...
container.py
Source:container.py
...17 Drawable.FILL_PARENT,18 Drawable.FILL_PARENT))19 self.create_children(parameters)20 21 def get_element_size(self) :22 if self._children :23 self.layout_policy.update_bounds(self.inner_bounds)24 return self.layout_policy.get_element_size() 25 return super().get_element_size()26 27 def create_children(self, parameters) :28 for element in parameters.get("elements", []) :29 self.__create_elements(element) 30 31 def __create_elements(self, element) :32 parser = ParameterParser(element)33 class_name = parser.realize_parameter("class")34 if not class_name :35 raise ParameterError("Elements must specify a class") 36 37 if self.__skip_element(parser) :38 return39 40 klass = globals()[class_name]41 primary_element = None42 43 for _ in range(self.__number_of_elements_to_create(parser)) :44 new_element = klass(element)45 if primary_element :46 new_element.primary_element = primary_element47 else :48 primary_element = new_element49 50 self._children.append(new_element) 51 52 def __skip_element(self, parser) :53 return not parser.realize_parameter("probability", True)54 55 def __number_of_elements_to_create(self, parser) :56 rows = 1 + parser.realize_parameter("repeat", 0)57 return self.layout_policy.columns * rows58 59 def update_page_parameters(self, page) :60 for child in self._children :61 child.update_page_parameters(page) 62 63 super().update_page_parameters(page)64 65 def calculate_dimensions(self, draw, size) : 66 inner_size = self._calculate_content_from_size(size)67 self.layout_policy.update_bounds(inner_size)68 max_child_size = self.layout_policy.get_max_child_size()69 for child in self._children :70 child.calculate_dimensions(draw, max_child_size) 71 72 super().calculate_dimensions(draw, size)73 74 def layout(self, bounds) :75 super().layout(bounds)76 self.layout_policy.update_bounds(self.inner_bounds)77 self.layout_policy.layout()78 size = self.layout_policy.get_element_size()79 outer_size = self.calculate_size_from_inner_size(size)80 self._bounds = Bounds(bounds.x, bounds.y, bounds.width, outer_size.height)81 82 def render(self, draw) :83 super().render(draw)84 for child in self._children :85 child.render(draw) 86 87 def set_numerator(self, numerator) :88 for child in self._children :89 child.set_numerator(numerator)90 91 def __get_layout_policy(self, parent_bounds) :92 policy_params = self.parameters.get("layout")...
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!!