How to use _parse_structure method in localstack

Best Python code snippet using localstack_python

app.py

Source:app.py Github

copy

Full Screen

...75 # we don't have anomalies in the conf76 anomalies = [lambda x: x for i in range(structure.W.shape[0])]77 logging.debug(anomalies)78 return structure, anomalies, m079def _parse_structure(conf):80 structures = []81 m0 = []82 anomalies = []83 for structure in conf:84 _structure, _anomalies, _m0 = _parse_component(structure)85 m0.extend(_m0)86 anomalies.extend(_anomalies)87 structures.append(_structure)88 m0 = np.array(m0)89 C0 = np.eye(len(m0))90 return reduce((lambda x, y: x + y), structures), m0, C0, anomalies91def _parse_composite(conf):92 models = []93 prior_mean = []94 anomaly_vector = []95 for element in conf:96 if 'replicate' in element:97 structure, m0, C0, anomalies = _parse_structure(98 element['structure'])99 prior_mean.extend([m0] * element['replicate'])100 anomaly_vector.extend(anomalies * element['replicate'])101 model = _parse_observations(element['observations'], structure)102 models.extend([model] * element['replicate'])103 else:104 structure, m0, C0, anomalies = _parse_structure(105 element['structure'])106 prior_mean.extend(m0)107 anomaly_vector.extend(anomalies)108 model = _parse_observations(element['observations'], structure)109 models.append(model)110 print(models)111 model = CompositeTransformer(*models)112 m0 = np.array(prior_mean)113 C0 = np.eye(len(m0))114 return model, m0, C0, anomaly_vector115def _parse_observations(obs, structure):116 if obs['type'] == 'continuous':117 model = NormalDLM(structure=structure, V=obs['noise'])118 elif obs['type'] == 'discrete':119 model = PoissonDLM(structure=structure)120 elif obs['type'] == 'categorical':121 if 'values' in obs:122 values = obs['values'].split(',')123 model = BinomialTransformer(structure=structure, source=values)124 elif 'categories' in obs:125 model = BinomialDLM(structure=structure,126 categories=obs['categories'])127 else:128 raise ValueError("Categorical models must have either 'values' "129 "or 'categories'")130 else:131 raise ValueError("Model type {} is not valid".format(obs['type']))132 return model133def parse_configuration(conf):134 """135 Parse a YAML configuration string into an state-space model136 :param conf:137 :return: A state-space model138 """139 if 'compose' in conf:140 model, m0, C0, anomalies = _parse_composite(conf['compose'])141 else:142 structure, m0, C0, anomalies = _parse_structure(conf['structure'])143 model = _parse_observations(conf['observations'], structure)144 state = mvn(m0, C0).rvs()145 period = float(conf['period'])146 name = conf['name']147 return model, state, period, name, anomalies148def build_message(name, value):149 return json.dumps({150 'name': name,151 'value': value152 }).encode()153def main(args):154 logging.basicConfig(level=args.logging)155 logging.info('brokers={}'.format(args.brokers))156 logging.info('topic={}'.format(args.topic))...

Full Screen

Full Screen

parse_course.py

Source:parse_course.py Github

copy

Full Screen

...65 content['parent'] = parent_id66 for attr in root.attrib:67 content[attr] = root.attrib.get(attr)68 return content69 def _parse_structure(self, label, instance_id, usage_id, parent_id=None):70 file_name = "{}/{}/{}.xml".format(self.directory, label, instance_id)71 root = ElementTree.parse(file_name).getroot()72 content = self._populate_attributes(root, parent_id)73 if instance_id:74 content['id'] = instance_id75 content['usage_id'] = usage_id76 for child in root:77 try:78 child_parser = getattr(EdXMLParser, '_parse_' + child.tag)79 except AttributeError:80 child_parser = getattr(EdXMLParser, '_parse_leaf')81 content['children'] = content.get('children', [])82 child = child_parser(self, child, instance_id, child.tag)83 content['children'].append(child)84 content['score'] = content['score'] + child['score']85 return content86 def _calculate_usage_id(self, instance_id, label):87 # This method returns a usage ID for a split-mongo installation. For88 # the mongo DB in the Devstack or Full Stack installations, use:89 # return "i4x:;_;_{};_{};_{}".format(self.usage_prefix.replace('/', ';_'), label, instance_id)90 return "block-v1:{}+{}+{}+type@{}+block@{}".format(91 self.org,92 self.course,93 self.url_name,94 label,95 instance_id96 )97 def _parse_course_xml(self):98 file_name = "{}/course.xml".format(self.directory)99 root = ElementTree.parse(file_name).getroot()100 self.url_name = root.attrib.get('url_name')101 self.course = root.attrib.get('course')102 self.org = root.attrib.get('org')103 def _parse_course(self):104 self._parse_course_xml()105 usage_id = self._calculate_usage_id(self.url_name, 'course')106 self.parsed_course = self._parse_structure('course', self.url_name, usage_id)107 def _parse_chapter(self, element, parent_id, tag):108 instance_id = self._get_instance_id(element)109 usage_id = self._calculate_usage_id(element.attrib.get('url_name'), tag)110 return self._parse_structure(tag, instance_id=instance_id, usage_id=usage_id, parent_id=parent_id)111 def _parse_sequential(self, element, parent_id, tag):112 instance_id = self._get_instance_id(element)113 usage_id = self._calculate_usage_id(element.attrib.get('url_name'), tag)114 return self._parse_structure(tag, instance_id=instance_id, usage_id=usage_id, parent_id=parent_id)115 def _parse_vertical(self, element, parent_id, tag):116 instance_id = self._get_instance_id(element)117 usage_id = self._calculate_usage_id(element.attrib.get('url_name'), tag)118 return self._parse_structure(tag, instance_id=instance_id, usage_id=usage_id, parent_id=parent_id)119 def _parse_problem(self, element, parent_id, tag):120 if element.attrib.get('display_name'):121 content = self._populate_attributes(element, parent_id)122 content['score'] = 1123 else:124 instance_id = self._get_instance_id(element)125 # instance_id = element.attrib.get('url_name')126 file_name = "{}/problem/{}.xml".format(self.directory, instance_id)127 root = ElementTree.parse(file_name).getroot()128 content = self._populate_attributes(root, parent_id)129 content['id'] = instance_id130 content['usage_id'] = self._calculate_usage_id(content['id'], tag)131 score = 0132 score += len(root.findall('.//coderesponse'))...

Full Screen

Full Screen

pdb_parse.py

Source:pdb_parse.py Github

copy

Full Screen

...19 for line in f:20 content.append(line.decode("utf-8"))21 temp_fp = StringIO("".join(content))22 return temp_fp23def _parse_structure(24 parser: Union[PDBParser, MMCIFParser], name: str, file_path: str25) -> Structure:26 """Parse a .pdb or .cif file into a structure object.27 The file can be gzipped."""28 if pd.isnull(file_path):29 return None30 if file_path.endswith(".gz"):31 structure = parser.get_structure(name, gunzip_to_ram(file_path))32 else: # not gzipped33 structure = parser.get_structure(name, file_path)34 return structure35parse_pdb_structure = _parse_structure # for backward compatiblity36def parse_structure(37 pdb_parser: PDBParser, cif_parser: MMCIFParser, name: str, file_path: str38) -> Structure:39 """Parse a .pdb file or .cif file into a structure object.40 The file can be gzipped."""41 if file_path.rstrip(".gz").endswith("pdb"):42 return _parse_structure(pdb_parser, name, file_path)43 else:44 return _parse_structure(cif_parser, name, file_path)45def three_to_one_standard(res: Residue) -> str:46 """Encode non-standard AA to X."""47 if not is_aa(res, standard=True):48 return "X"49 return three_to_one(res)50def is_aa_by_target_atoms(res: Residue) -> bool:51 """Tell if a Residue object is AA"""52 target_atoms = ["N", "CA", "C", "O"]53 for atom in target_atoms:54 try:55 res[atom]56 except KeyError:57 return False58 return True...

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