def decide(self, time, bits): lookup_time = time - self.DELAY ##only return a trade when time_period has passed and sufficient candles are skipped if lookup_time % self.candles_to_skip == 0 and lookup_time > self.candles_to_skip: ##mv_past = MovingAverage(self.predicter_candles, (time-self.candles_to_skip)) ##mv_present = MovingAverage(self.predicter_candles, time) ##avg_past = mv_past.simple() ##avg_present = mv_present.simple() avg_past = self.point_avgs[lookup_time - self.candles_to_skip].value avg_present = self.point_avgs[lookup_time].value if avg_past < avg_present: ##trending up return Operation(Operation.BUY_OP, self.AMOUNT) elif avg_past > avg_present: ##trending down return Operation(Operation.SELL_OP, self.AMOUNT) elif avg_past == avg_present: ##stable trend return Operation(Operation.NONE_OP, 0) ##do nothing rest of the time else: return Operation(Operation.NONE_OP, 0)
def decide(self, candle_num, bits): ##make sure there exists adequate history for prediction, return NONE OP if candle_num > self.neural_model.num_past: ##computing what will be the input into the model inp = [] for i in range(self.neural_model.num_past): if self.neural_model.mode == self.neural_model.CLOSE: inp.append( self.candles[candle_num - (self.neural_model.num_past - i)].close) elif self.neural_model.mode == self.neural_model.VOLUME: inp.append( self.candles[candle_num - (self.neural_model.num_past - i)].volume) ##get model prediction results = self.neural_model.model.predict([inp]) result = results[0] if result == 1: return Operation(Operation.BUY_OP, self.AMOUNT) elif result == -1: return Operation(Operation.SELL_OP, self.AMOUNT) elif result == 0: return Operation(Operation.NONE_OP, 0) else: return Operation(Operation.NONE_OP, 0)
def decide(self, time, bits): cur_timestamp = self.cur_traded_candles[time].date trend_timestamp = cur_timestamp - self.DELAY * self.DAY cur_date = timestamp_to_date(cur_timestamp) if cur_date != self.last_date: self.last_date = cur_date try: past_avg = PointTable.lookup_date(self.avg_table_name, trend_timestamp).value print(("Number of views: ", past_avg)) except: return Operation(Operation.NONE_OP, 0) ## ask for user input response = raw_input("Please enter trade: ") if response == self.BUY_CMD: return Operation(Operation.BUY_OP, self.BUY_AMOUNT) elif response == self.SELL_CMD: return Operation(Operation.SELL_OP, bits) else: return Operation(Operation.NONE_OP, 0) else: return Operation(Operation.NONE_OP, 0)
def decide(self, time, bits): if time % 6 == 2: return Operation(Operation.BUY_OP, self.AMOUNT) elif time % 6 == 5: return Operation(Operation.SELL_OP, self.AMOUNT) else: ##do nothing rest of the time return Operation(Operation.NONE_OP, 0)
def main(): addition = Operation(lambda a, b: a + b, '+') subtraction = Operation(lambda a, b: a - b, '-') multiplication = Operation(lambda a, b: a * b, '*') division = Operation(lambda a, b: a / b, '/') numbers = [25, 75, 4, 100] operations = [addition, subtraction, multiplication] expected_result = 425 beast = ArithmeticBeast(numbers, operations) beast.print_phrases_for_result(expected_result)
def membership_history(conn, cur): option = input( "Membership history phase > \nEnter 1.HISTORY / 2.ANNOTATION option number: " ) if int(option) is 1: op = Operation() op.history(cur) elif int(option) is 2: op = Operation() op.annotate(conn, cur) op.list_members(cur) print("Member annotation inserted") return 1
def decide(self, time, bits): print("************************************************************************************************") print(("Time: ", timestamp_to_date(self.candles[time].date))) print(("Price: ", self.candles[time].close)) print((self.attribute_name, ": ", getattr(self.candles[time], self.attribute_name))) ## ask for user input response = raw_input("Please enter trade: ") print("************************************************************************************************") if response == self.BUY_CMD: return Operation(Operation.BUY_OP, self.BUY_AMOUNT) elif response == self.SELL_CMD: return Operation(Operation.SELL_OP, bits) else: return Operation(Operation.NONE_OP, 0)
def decide(self, candle_num, bits): if candle_num <= self.OSCIL_PERIOD: return Operation(Operation.NONE_OP, 0) else: ##if crossed 0 from below up, buy signal if self.oscil_pts[candle_num - self.OSCIL_PERIOD - 1].value < 0 and self.oscil_pts[ candle_num - self.OSCIL_PERIOD].value > 0: return Operation(Operation.BUY_OP, self.amount) elif self.oscil_pts[candle_num - self.OSCIL_PERIOD - 1].value > 0 and self.oscil_pts[ candle_num - self.OSCIL_PERIOD].value < 0: return Operation(Operation.SELL_OP, self.amount) else: return Operation(Operation.NONE_OP, 0)
def decide(self, candle_num, bits): if self.bits > 0: rand_int_buy = randint(1, 100) if candle_num % int(self.exp_buy_run_len + 1) == self.rand_int_sell: self.runs.append(0) return Operation(Operation.SELL_OP, bits) elif rand_int_buy <= (self.PBUY) * 100: self.runs[-1] += 1 return Operation(Operation.BUY_OP, self.buy_amt) else: self.runs[-1] += 1 return Operation(Operation.NONE_OP, 0) else: return Operation(Operation.NONE_OP, 0)
def main(): if v.login(): o = Operation() while True: choice = input("请选择需要办理的业务:") if choice == "1": # 开户 o.register() elif choice == "2": # 查询 o.query() elif choice == "3": # 还款 o.repay_money() elif choice == "4": # 贷款 o.get_money() elif choice == "5": # 转账 o.trans_money() elif choice == "6": # 改密 o.change_pwd() elif choice == "7": # 锁卡 o.lock() elif choice == "8": # 解卡 o.unlock() elif choice == "9": # 补卡 o.new_card() elif choice == "0": # 退出 o.save() break
def _check_changed_cb(self, obj, part): if obj.state: self._part_add(part, self._edit_grp.animation.name) op = Operation("part (%s) addition into animation (%s)" % \ (part, self._edit_grp.animation.name)) op.redo_callback_add(self._part_add, part, self._edit_grp.animation.name) op.undo_callback_add(self._part_remove, part, self._edit_grp.animation.name) self._operation_stack_cb(op) else: # FIXME: Take the confirmation out of this function self._notification = ErrorNotify( self, elementary.ELM_NOTIFY_ORIENT_CENTER) self._notification.title = "Part Removal" lb = elementary.Label(self._notification) lb.text_set("Are you sure you want to remove<br>" "this part from the animation?") lb.show() self._notification.pack_end(lb) self._notification.action_add("Remove", self._confirm_remove_cb, data=part) self._notification.action_add("Cancel", self._cancel_remove_cb, data=obj) self._notification.show()
def _states_added_cb(self, popup, data): new_state = self.newstate_entry.entry tmp = new_state.split(None, 1) if len(tmp) == 1: new_state = (tmp[0], 0.0) else: new_state = (tmp[0], float(tmp[1])) part_name = self._edit_grp.part.name part = self._edit_grp.part_get(part_name) curr_state = self._edit_grp.part.state.name if part.state_exist(*new_state): # FIXME: notify the user of it somehow return self._part_state_copy_from(part_name, curr_state, new_state) op = Operation("state addition") op.redo_callback_add(self._part_state_copy_from, part_name, curr_state, new_state) op.undo_callback_add(self._remove_state_internal, new_state) self._operation_stack_cb(op) self.close()
def make_word_context(word_name: Op_name, op_def: Operation_def, in_seq: Sequence["Type"] = [], out_seq: Sequence["Type"] = []) -> None: sig = TypeSignature(in_seq=[StackObject(stype=x) for x in in_seq], out_seq=[StackObject(stype=x) for x in out_seq]) Type.add_op(Operation(word_name, op_def, sig=sig), sig.stack_in)
def main(): op = Operation() driver = op.driver # op.login('//a[@class="btn-login"]', # '//li[text()="账密登录"]', # 'J-input-user', # 'password_rsainput', # 'J-checkcode-img', # 'J-input-checkcode', # 'J-login-btn', # '*****@*****.**', # 'htf99!123' # ) #input() driver.get('https://wshop.alipay.com/api/dashboard/queryAumData') html_str = driver.page_source # print(html_str) # driver.back() # driver.get('https://wshop.alipay.com/api/dashboard/queryProductData') # html_str = driver.page_source # print('###') # print(html_str) # print() op.rank_str_to_csv(html_str) time.sleep(2) driver.back() time.sleep(3)
def test_any_stack_effect(self) -> None: op = Operation("nop", op_nop, sig=TypeSignature([StackObject(stype=TAny)], [StackObject(stype=TInt)])) check_out = Stack([StackObject(stype=TInt)]) sig, match = op.check_stack_effect() assert sig == check_out assert match == True sig, match = op.check_stack_effect(Stack([StackObject(stype=TBool)])) assert sig == check_out assert match == True sig, match = op.check_stack_effect(Stack([StackObject(stype=TAny)])) assert sig == check_out assert match == True sig, match = op.check_stack_effect( Stack([StackObject(stype=TBool), StackObject(stype=TInt)])) assert sig == Stack( [StackObject(stype=TBool), StackObject(stype=TInt)]) assert match == True
def parse_operation(args): protocol_info = args[0] operation = Operation() # Timestamp operation.ts = (protocol_info[0] - datetime.datetime(1970, 1, 1)).total_seconds() # Connection operation.orig_ip = str(protocol_info[1][0][0]) operation.resp_ip = str(protocol_info[1][0][2]) # Control Protocol (service) operation.service = str(protocol_info[2]) # uid operation.uid = str(protocol_info[3]) # Function code operation.fc = protocol_info[4].value # Function name operation.fn = str(protocol_info[5]) # Is from teh originator side operation.is_orig = protocol_info[6] #print(operation) return operation
def _remove_cb(self, obj, emission, source): def anim_restore(anim_save): name = anim_save.name if self._edit_grp.animation_add(name): anim_save.apply_to(self._edit_grp) def sigs_restore(anim_name, sigs_save): curr_sig = self._edit_grp.signal.name self._edit_grp.signal.name = None pname = "@%[email protected]" % anim_name for sig in sigs_save: prog = self._edit_grp.program_get(sig) prog.afters_clear() prog.after_add(pname) self._edit_grp.signal.name = curr_sig def relative_signals_anim_clear(anim_name): sigs = [] curr_sig = self._edit_grp.signal.name self._edit_grp.signal.name = None pname = "@%[email protected]" % anim_name for sig in self._edit_grp.signals: prog = self._edit_grp.program_get(sig) afters = prog.afters if afters and pname != afters[0]: continue prog.afters_clear() sigs.append(sig) self._edit_grp.signal.name = curr_sig return sigs for s in self.selected: anim_name = s[0] pname = "@%s@stop" % anim_name stop_prog = self._edit_grp.edje.program_get(pname) anim_data = objects_data.Animation(stop_prog) r = self._edit_grp.animation_del(anim_name) if not r: del anim_data continue sigs_save = relative_signals_anim_clear(anim_name) op = Operation("animation deletion: %s" % anim_name) op.redo_callback_add(relative_signals_anim_clear, anim_name) op.redo_callback_add(self._edit_grp.animation_del, anim_name) op.undo_callback_add(anim_restore, anim_data) op.undo_callback_add(sigs_restore, anim_name, sigs_save) self._operation_stack_cb(op)
def setup_campaign(conn, cur): print("Setup campaign phase >") op = Operation() op.insert(conn, cur) op.list_operations(cur) print("Campaign setup inserted") return 1
def lock(target, trans, obj): """ Returns an Operation object representing the lock operation 'target' on 'obj' by 'trans' """ if target != 'SHARED_L' and target != 'XCLUSIVE_L' and target != 'UNLOCKED': raise ValueError('Invalid lock/unlock operation') return Operation(target, trans, obj)
def scrambler(state, count): scramble = Operation() actions = ['L', 'Li', 'R', 'Ri', 'U', 'Ui', 'D', 'Di', 'F', 'Fi', 'B', 'Bi', 'M', 'Mi', 'E', 'Ei', 'S', 'Si'] moves = " ".join((random.choice(actions) for i in range(count))) print(moves) result = scramble.sequence(moves, state) return result
def _state_entry_changed_cb(self, st_widget, *args, **kwargs): def state_rename(part_name, old_name, new_name): # select 1st if self.e.part.name != part_name: self.e.part.name = part_name self.e.part.state.name = old_name[0] part = self.e.part_get(part_name) if (part.state_exist(*new_name)) or old_name == ["default", 0.0]: return False # rename later return self.e.part.state.rename(*new_name) part = self.e.part.name old_name = self.e.part.state.name new_name = st_widget.value.split(None, 1) if len(new_name) == 1: new_name[1] = 0.0 else: new_name[1] = float(new_name[1]) if state_rename(part, old_name, new_name): op = Operation("state renaming") op.redo_callback_add(state_rename, part, old_name, new_name) op.undo_callback_add(state_rename, part, new_name, old_name) self._operation_stack_cb(op) else: # TODO: notify the user of renaming failure st_widget.value = "%s %.2f" % old_name
def _add(self): def add_internal(name, edje_type, ext_name=""): if not self._edit_grp.part_add(name, edje_type, ext_name, init=self._partsetup.apply_to): self.notify("Error adding new part.") return False return True self._part_name = self._part_name_entry.entry if self._type == edje.EDJE_PART_TYPE_EXTERNAL: ext_name = self._ext_list.type else: ext_name = "" if self._type == edje.EDJE_PART_TYPE_IMAGE: ImageSelectionWizard(self._parent, self._image_set, self._new_img_cb, self._img_list_get_cb, self._img_id_get_cb, self._workfile_name_get_cb).show() else: if add_internal(self._part_name, self._type, ext_name): op = Operation("part addition") op.redo_callback_add( add_internal, self._part_name, self._type, ext_name) op.undo_callback_add(self._edit_grp.part_del, self._part_name) self._operation_stack_cb(op) self.close()
def test_get_column_id_invalid_column(mock_dataset, mock_column_name_to_id, column_name_to_id_return_value) -> None: mock_column_name_to_id.return_value = column_name_to_id_return_value try: get_column_id(Operation(mock_dataset), 'column1') assert False except SystemExit: pass
def delete_campaigns(conn, cur): print("Delete campaign phase >") op = Operation() op.list_operations(cur) next_session() op.delete(conn, cur) op.list_operations(cur) print("Campaign operation deleted")
def run_operation(): #print('-1') op = Operation() # print('0') driver = op.driver #print('1') op.quit_frame() op.click('//a[text()="平台招商"]') time.sleep(2) download_tag_1 = '//div[@class="ant-spin-container"]/div/div/button' download_tag_2 = '//div[@class="ant-row ant-form-item"]//div[@class="ant-form-item-control"]//button' op.roll_down_window(download_tag_1) op.delete_file() #print("delete finish") selector_xpaths = [] for i in range(1, 4): selector_xpath = '//div[@class="ant-modal-root"]/../following-sibling::div[2]//ul[@class="ant-select-dropdown-menu ant-select-dropdown-menu-root ant-select-dropdown-menu-vertical"]//li[{}]'.format( i) # selector_xpath = "//div[@style=\"width: 200px; left: 224px; top: 227px;\"]//ul[@class=\"ant-select-dropdown-menu ant-select-dropdown-menu-root ant-select-dropdown-menu-vertical\"]//li[{}]".format( # i) #selector_xpath = "//ul[@class=\"ant-select-dropdown-menu ant-select-dropdown-menu-vertical ant-select-dropdown-menu-root\"]//li[{}]".format(i) selector_xpaths.append(selector_xpath) date_xpath = "//ul[@role=\"listbox\"]//li[2]" file_class = ['申购一(拉新)', '申购二(满减)', '定投'] for index, selector_xpath in enumerate(selector_xpaths): op.click(download_tag_1) # 点击下载类型 if index == 0: pass else: # time.sleep(1) op.click( '//label[@title="请选择下载类型"]/../following-sibling::div[1]//div[@class="ant-select-selection__rendered"]' ) # op.click( # '//div[@class="ant-modal-content"]//div[@class="ant-form-item-control has-success"]//div[@class="ant-select-selection__rendered"]') # time.sleep(1) # driver.find_elements_by_xpath('//ul[@class="ant-select-dropdown-menu ant-select-dropdown-menu-root ant-select-dropdown-menu-vertical"]')[0].find_elements_by_xpath('//li')[1].click() # op.click(selector_xpath) # time.sleep(1) op.click( '//label[@title="选择明细报表"]/../following-sibling::div[1]//div[@class="ant-select-selection__rendered"]' ) # op.click( # '//div[@class="ant-modal-content"]//div[@class="ant-form-item-control"]//div[@class="ant-select-selection__rendered"]') #op.click(selector_xpaths[1]) # time.sleep(1) op.click(date_xpath) # time.sleep(1) op.click(download_tag_2) time.sleep(2) op.file_rename(file_class[index]) driver.back()
def train(): op = Operation() op.user = request.form['login'] op.pressedtime = float(request.form['pressedtime']) op.flytime = float(request.form['onflytime']) op.keytimes = request.form['keytimes'] op.save() return render_template("train.html", myOp=op)
def _down_cb(self, obj, emission, source): r = self._restack_below(self._edit_grp.part.name) if not r: return op = Operation("part re-stacking (below)") op.redo_callback_add(self._restack_below, self._edit_grp.part.name) op.undo_callback_add(self._restack_above, self._edit_grp.part.name) self._operation_stack_cb(op)
def parse_schedule(sched): """ Parses the input schedule as a string. Returns the list of 'Operation' objects """ if sched == '': print('Using test schedule') return parse_schedule(TEST_SCHEDULES[-1]) schedule = [] i = 0 last_ops = dict() #save last operation for each transaction try: while i < len(sched): t, tx, o = None, None, None # get operation type 't' if sched[i] == 'r': t = 'READ' elif sched[i] == 'w': t = 'WRITE' else: return _sched_malformed_err( 'operation types must be \'r\' or \'w\'') i += 1 # get operation transaction 'tx' tx_end = sched[i:].find('(') tx = sched[i:i + tx_end] if tx == '': return _sched_malformed_err() i = i + tx_end + 1 # get operation object 'o' o_end = sched[i:].find(')') o = sched[i:i + o_end] if o == '': return _sched_malformed_err() i = i + o_end + 1 operation = Operation(t, tx, o) #operation object last_ops[ tx] = operation #save operation as last for transaction tx schedule.append(operation) #append operation to schedule # Set final operations for each transaction for op in last_ops.values(): op.tx_continues = False return schedule except ValueError: return _sched_malformed_err()
def generate_one(self, ts): operation = Operation(ts, self.orig_ip, self.resp_ip, self.service, self.uid, self.fc, self.fn, self.is_orig) return operation
def test_jump(): algorithm = Algorithm() op = Operation() im = op.screen_cap() start_x, start_y, end_x, end_y = algorithm.find_point(im) start_point = (start_x, start_y) end_point = (end_x, end_y) distance = algorithm.euclidean_distance(start_point, end_point) press_time = algorithm.distance_to_time(distance) op.jump(start_point, end_point, press_time)