How to use _parse_plan method in tappy

Best Python code snippet using tappy_python

boo.py

Source:boo.py Github

copy

Full Screen

...16 ]17 self.relevant_operators = None18 def boo_from_plan(self, plan):19 self.relevant_operators = []20 self._parse_plan(plan)21 return self.relevant_operators22 def _parse_plan(self, plan):23 node_type = plan["Node Type"]24 if node_type in self.INTERESTING_OPERATORS:25 node_representation = self._parse_node(plan)26 self.relevant_operators.append(node_representation)27 if "Plans" not in plan:28 return29 for sub_plan in plan["Plans"]:30 self._parse_plan(sub_plan)31 def _stringify_attribute_columns(self, node, attribute):32 attribute_representation = f"{attribute.replace(' ', '')}_"33 if attribute not in node:34 return attribute_representation35 value = node[attribute]36 for replacee, replacement in self.replacings:37 value = value.replace(replacee, replacement)38 value = re.sub('".*?"', "", value)39 value = re.sub("'.*?'", "", value)40 value = value.translate(self.remove_digits)41 return value42 def _stringify_list_attribute(self, node, attribute):43 attribute_representation = f"{attribute.replace(' ', '')}_"44 if attribute not in node:...

Full Screen

Full Screen

parse.py

Source:parse.py Github

copy

Full Screen

...44 result: ScoreDict = {} # type: ignore45 soup = BeautifulSoup(html, "lxml")46 b = soup.select_one("#contentArea > div.UIElement > ul > li > #welcome")47 result["cet"] = _parse_cet(b)48 result["plan"] = _parse_plan(b) # 计划课程49 result["physical"] = _parse_physic_or_common(b, "physical")50 result["common"] = _parse_physic_or_common(b, "common") # 通选课51 return result52def _parse_cet(block):53 # ["准考证号", "考试场次", "语言级别", "总分", "听力", "阅读", "写作", "综合"]54 table = pd.read_html(str(block.select("#CET table")))[0]55 clear_lino1(table)56 rm_nan(table)57 return table58def _parse_physic_or_common(block, cata: str) -> pd.DataFrame:59 # ["学期", "课程", "课程号", "学分", "正考", "补考", "绩点"]60 table = pd.read_html(str(block.select(f"#{cata.capitalize()} table")))[0]61 clear_lino1(table)62 rm_nan(table)63 # 最后一行是学分绩点计算64 table.drop(len(table) - 1, inplace=True)65 return table66def _parse_plan(block) -> pd.DataFrame:67 _tables = pd.read_html(str(block.select("#Plan table")))68 df_lst = [] # type: List[pd.DataFrame]69 for table in _tables:70 table.dropna(thresh=len(table.columns) - 2, inplace=True) # 去除 NaN 行71 table.reset_index(drop=True, inplace=True)72 # line 0: 哪个学期73 term = extract_term(table)74 if not term:75 continue76 start_index = 077 for idx, series in table.iterrows():78 text = series[0]79 # 找到 `平均学分绩点` 这一行进行切分,分为上下两部分80 if text.startswith("平均学分绩点"):...

Full Screen

Full Screen

plan_manager.py

Source:plan_manager.py Github

copy

Full Screen

...10 with open(filename) as input_file:11 for line in input_file:12 pass13 return line14def _parse_plan(plan_filename):15 """Parse a plan file and return a pair (cost, problem_type)16 summarizing the salient information. Return (None, None) for17 incomplete plans."""18 last_line = _read_last_line(plan_filename) or ""19 match = _PLAN_INFO_REGEX.match(last_line)20 if match:21 return int(match.group(1)), match.group(2)22 else:23 return None, None24class PlanManager(object):25 def __init__(self, plan_prefix):26 self._plan_prefix = plan_prefix27 self._plan_costs = []28 self._problem_type = None29 def get_plan_prefix(self):30 return self._plan_prefix31 def get_plan_counter(self):32 return len(self._plan_costs)33 def get_best_plan_cost(self):34 """Return best plan cost found so far. Return string35 "infinity" if no plans found yet."""36 if self._plan_costs:37 return self._plan_costs[-1]38 else:39 return "infinity"40 def get_problem_type(self):41 if self._problem_type is None:42 raise ValueError("no plans found yet: cost type not set")43 return self._problem_type44 def process_new_plans(self):45 """Update information about plans after a planner run.46 Read newly generated plans and store the relevant information.47 If the last plan file is incomplete, delete it.48 """49 had_incomplete_plan = False50 for counter in itertools.count(self.get_plan_counter() + 1):51 plan_filename = self._get_plan_file(counter)52 def bogus_plan(msg):53 raise RuntimeError("%s: %s" % (plan_filename, msg))54 if not os.path.exists(plan_filename):55 break56 if had_incomplete_plan:57 bogus_plan("plan found after incomplete plan")58 cost, problem_type = _parse_plan(plan_filename)59 if cost is None:60 had_incomplete_plan = True61 print("%s is incomplete. Deleted the file." % plan_filename)62 os.remove(plan_filename)63 else:64 print("plan manager: found new plan with cost %d" % cost)65 if self._problem_type is None:66 # This is the first plan we found.67 self._problem_type = problem_type68 else:69 # Check if info from this plan matches previous info.70 if self._problem_type != problem_type:71 bogus_plan("problem type has changed")72 if cost >= self._plan_costs[-1]:...

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