def delete_by_id(self, id): d = sql.Delete(self) index_id = self.get_index_id() cond = c.Condition(field=self.columns()[index_id].target, compare_operator=c.Equality()) cc = c.Conditions() cc.append(cond=cond, val=id) d.add_options(conditions=cc) execute(d.query(), (id, ), fetchall=False) commit()
def link1(table, nodeDesc1, nodeDesc2, edgeDesc): # Get attributes indexes node1Idx = table.getIndex(nodeDesc1.idAttr) node2Idx = table.getIndex(nodeDesc2.idAttr) relationAttr1 = [attr for attr, _ in edgeDesc.relation] relationAttr2 = [attr for _, attr in edgeDesc.relation] node1RelIdx = table.getIndex(relationAttr1) node2RelIdx = table.getIndex(relationAttr2) node1DataIdx = table.getIndex(nodeDesc1.dataAttr) node2DataIdx = table.getIndex(nodeDesc2.dataAttr) # Create new graph and add nodes g = graph.Graph(edgeDesc.type, False) g.addNodes(table, node1Idx) g.addNodes(table, node2Idx) # Tranform table assert not (node1Idx in node1RelIdx or node2Idx in node2RelIdx) projlist1 = [node1Idx] + node1RelIdx + node1DataIdx projlist2 = [node2Idx] + node2RelIdx + node2DataIdx for cond in nodeDesc1.filter + nodeDesc2.filter: cond.configureForTable(table) t1, idxmap1 = table.select(nodeDesc1.filter, projlist1) t2, idxmap2 = table.select(nodeDesc2.filter, projlist2) t3, idxmap3 = t1.join( t2, zip(util.mapIdx(node1RelIdx, idxmap1), util.mapIdx(node2RelIdx, idxmap2))) if edgeDesc.threshold: t4, idxmap4 = t3.group([ util.mapIdx(node1Idx, idxmap1, idxmap3), util.mapIdx(node2Idx, idxmap2, idxmap3) ], True) t5, idxmap5 = t4.select( condition.Condition(WEIGHT_ATTR_NAME, ">=", edgeDesc.threshold)) idxmap = util.mergeIdxmap(idxmap4, idxmap5) else: t5, idxmap = t3.group([ util.mapIdx(node1Idx, idxmap1, idxmap3), util.mapIdx(node2Idx, idxmap2, idxmap3) ], False) # Add edges g.addEdges(t5, util.mapIdx(node1Idx, idxmap1, idxmap3, idxmap), util.mapIdx(node2Idx, idxmap2, idxmap3, idxmap)) pdb.set_trace() return g # Node description: # id (attribute name) # filter (condition on some attributes) # attributes (attributes in the table, other than ID)
def get_row_by_id(self, id): index_id = self.get_index_id() cond = c.Condition(field=self.columns()[index_id].real_name, compare_operator=c.Equality()) cc = c.Conditions() cc.append(cond=cond, val=id) current_values = self.select(conditions=cc) if not current_values: raise Exception("Строка c id " + str(id) + " в таблице " + self.caption + " уже не существует") current_values = list(current_values[0]) return current_values
def restart_test(appname): return MicroTest( steps=[ operation.Operation('stop', None, {'name': appname}), operation.Operation('start', None, {'name': appname}), operation.Operation('wait', None, {'time': 1000}), operation.Operation('waitact', None, {'name': appname}), operation.Operation('waitready'), operation.Operation('waitready'), ], conds=[condition.Condition('notequal', {'screen': 'init'})], name="restart app", feature_name="meta", meta=True, prio=-30, state_change=config.restart_state_change)
def init_test(appname): test = MicroTest( steps=[ operation.Operation('clear', None, {'name': appname}), #operation.Operation('kbdoff'), operation.Operation('start', None, {'name': appname}), operation.Operation('wait', None, {'time': 1000}), operation.Operation('waitact', None, {'name': appname}), operation.Operation('waitready'), operation.Operation('waitready'), ], conds=[condition.Condition('equal', {'screen': 'init'})], name="start app", feature_name="meta", meta=True) for prop in config.init_state: test.add_change(prop, config.init_state[prop]) return test
def update_by_id(self, id, values, updated_fields_number=()): sel = sql.Update(self) updated_fields = [ col.real_name for col in self.convert_to_columns(updated_fields_number) ] if not updated_fields_number: updated_fields = self.real_columns_name(skipped_field='id') sel.extend_field(fields=updated_fields) index_id = self.get_index_id() cond = c.Condition(field=self.columns()[index_id].real_name, compare_operator=c.Equality()) cc = c.Conditions() cc.append(cond=cond, val=id) sel.add_options(conditions=cc) execute(sel.query(), tuple(values + [id]), fetchall=False) commit()
def get_conflict_by_id(self, id): conf_table = ConflictTable() type_conf = TypeConflict() sel = sql.Select(conf_table) sel.add_options(left_joins=[ conf_table._columns['id_type'].reference, ]) target_columns = [ conf_table._columns['id_row_from'].real_name, conf_table._columns['id_type'].target ] sorted_columns = [ type_conf._columns['order_number'].target, ] sel.add_options(sorted_fields=sorted_columns, fields=target_columns) cond = c.Condition(field=conf_table._columns['id_row_to'].real_name, compare_operator=c.Equality()) cc = c.Conditions() cc.append(cond=cond, val=id) sel.add_options(conditions=cc) return execute(sel.query(), (id, ))
def explore_mode(self): if not config.do_exploration: return False trying_state_id = 0 progress = False while True: trying_state_id += 1 trying_state = self.slib.get_essential_screen(trying_state_id) if trying_state is None: break if not self.slib.check_state_perf(trying_state_id, self.tlib): continue if not self.slib.should_explore(trying_state_id): continue logger.info("exploring %s", trying_state) trying_route = self.slib.get_route_by_state(trying_state) if trying_route is None: continue logger.info("picked %s", trying_route) curr_state = state.State({'screen': 'init'}) self.replay_route(trying_route, curr_state) gui_state = self.observer.grab_state(self.dev) if gui_state is None: logger.error("fail to grab current state") continue curr_state.merge(gui_state) if trying_state.get('screen', '') == 'WRONG': # the new state is likely classified wrong curr_state.set('screen', 'WRONG') if not curr_state.is_unknown(): logger.warning( "route replayed, but the resulting screen does not match") ops = operation.collect_ops(curr_state) try_op = self.pick_explore_op(curr_state, ops) if try_op is None: self.slib.mark_state_finished(trying_state_id) continue op_test = microtest.MicroTest( steps=[try_op], name="generated %s" % try_op, conds=[ condition.Condition('screen', trying_state.get('screen')), condition.Condition('items', trying_state.get('items')) ]) ret = op_test.attempt(self.dev, self.observer, curr_state, self.tlib) if not ret: logger.warning("collected op failed??") continue self.record_new_state(curr_state, trying_route, op_test) self.statemgr.cleanup(curr_state) progress = True return progress
def parse_feature_file(filename): tests = [] curr_test = None feature_name = '' tags = set() last_verb = None for line in open(filename).read().split('\n'): line = line.strip() if line == '' or line.startswith('#'): continue if feature_re.match(line): feature_name = feature_re.match(line).group(1) logger.debug("Feature: %s", feature_name) elif scenario_re.match(line): (scenario_name, args) = scenario_re.match(line).groups() if curr_test is not None: tests.append(curr_test) tags.add(feature_name) curr_test = microtest.MicroTest(filename=filename, name=scenario_name, tags=tags, args=args, feature_name=feature_name) # no custom test can run on init curr_test.add_cond( condition.Condition("notequal", {"screen": "init"})) last_verb = None tags = set() logger.debug("Scenario: %s", scenario_name) elif stmt_re.match(line): (verb, stmt) = stmt_re.match(line).groups() if verb == 'And': if last_verb is None: raise Exception("Fresh And stmt") verb = last_verb else: last_verb = verb if verb == 'Given': cond = try_parse_condition(stmt) if cond is None: raise Exception("Unknown condition %s" % line) curr_test.add_cond(cond) elif verb == 'When' or verb == 'Then': cond = try_parse_condition(stmt) if cond is not None: curr_test.add_expect(cond) elif change_re.match(stmt): (name, value) = change_re.match(stmt).groups() curr_test.add_change(name, value) else: op = operation.parse_line(stmt) if op is not None: curr_test.add_step(op) else: raise Exception("unknown line: %s" % line) else: raise Exception("unknown verb: %s" % verb) elif tag_re.match(line): tag = tag_re.match(line).group(1) tags.add(tag) else: raise Exception("unknown line: %s" % line) if curr_test is not None: tests.append(curr_test) return tests
def parse_condition(name, value): if name.startswith('!'): return condition.Condition("notequal", {name[1:]: value}) else: return condition.Condition('equal', {name: value})
def create_primary_strategy(self): # primary strategy s3 = strategy.Strategy(self.db, self.tele, name='primary', color='teal', order=1) # BUY c1 = condition.Condition(function='percentage_to_last', operator='>', value=0.01) c2 = condition.Condition(function='trend_of_last_seconds', param=70, operator='<', value=-0.24) s3.add_should_buy([c1, c2], text='percentage to last is positive') c1 = condition.Condition(function='percentage_to_last', operator='>', value=0) c2 = condition.Condition(function='trend_of_last_seconds', param=70, operator='<', value=0.4) s3.add_should_buy([c1, c2], text='percentage to last is positive') # c = condition.Condition(function='percentage_to_last', operator='<', value=-0.03) # s3.add_should_buy([c], text='high loss in cur tick') # SELL c1 = condition.Condition(function='percentage_to_last', operator='<', value=-0.01) c2 = condition.Condition(function='trade.percentage', operator='>=', value=0) s3.add_should_sell([c1, c2], text='high loss in cur tick and has profit') c1 = condition.Condition(function='percentage_to_last', operator='<', value=0) c2 = condition.Condition(function='trade.percentage', operator='<', value=-0.4) s3.add_should_sell( [c1, c2], text='percentage to last is negative and profit is lower than -0.4%' ) # c = condition.Condition(function='trend_of_last_seconds', param=30, operator='<', value=0.005) # s3.add_should_sell([c], text='no significant change in last 30 seconds') c = condition.Condition(function='trade.percentage', operator='>=', value=1) s3.add_should_sell([c], text='enough profit (>0.1%)') # c = condition.Condition(function='trend_of_last_seconds', param=10, operator='<', value=0) # s3.add_should_sell([c], text='no positive trend in last 10 seconds') c1 = condition.Condition(function='trade.percentage', operator='>=', value=0) c2 = condition.Condition(function='trade.last_percentage', operator='<', value=0) s3.add_should_sell([c1, c2], text='has profit, after no profit') self.strategies.append(s3)
def add_expect_eq(self, key, val): """ debug interface! """ expect = condition.Condition("equal", {key: val}) self.expects.append(expect) self.calc_prio()
continue matched_rows.append(row) if len(matched_rows) == 0: print("No data") continue matched_df = pd.DataFrame(matched_rows) for analysis in grp[1]: if analysis.GetInputType() != "HNR": continue output_dir = output_base_dir / analysis.GetName() output_dir.mkdir(parents=True, exist_ok=True) analysis.RunAnalysis(matched_df, group_name, output_dir) CONDITIONS_A = [ (condition.Condition(['S_a_a_a1', 'S_a_b_a1']), [ analyzer.FormantQuantilesF1F2SaSb(), analyzer.FormantQuantilesF1SbMb(), analyzer.FormantQuantilesF2SbMb(), analyzer.FormantRegressionSa(), analyzer.FormantRegressionSb(), analyzer.FormantRegressionMb(), analyzer.FormantInflectionMb(), ]), (condition.Condition(['S_a_a_a1', 'S_a_b_a2']), [ analyzer.FormantQuantilesF1F2SaSb(), analyzer.FormantQuantilesF1SbMb(), analyzer.FormantQuantilesF2SbMb(), analyzer.FormantRegressionSa(),