def delete(self): id = request.args.get('id') user = queryById(User, id) delete(user) return {'state': 'ok', 'msg': '删除{}成功!'.format(user.name)}
def clean_data(data, offset): """Drop initial and terminal floods information. 1. the set of packets considered is the set of packet broadcast by any node, reduced by an offset to remove marginal floods 2. Any flood corresponding to a sequence number different from the set given by 1, is discarded 2. Remove references to discarded packet also from the broadcast packets sets. """ pkt_bcast = [ set(pkt_node) for pkt_node in dao.select(data, BROADCAST_ENTRY) ] pkt_bcast_some = reduce(lambda x, y: x.union(y), pkt_bcast) pkt_considered = list(pkt_bcast_some)[0 + offset:-offset] pkt_received = [set(pkt_node) for pkt_node in dao.select(data, SEQNO_ATTR)] pkt_received_some = reduce(lambda x, y: x.union(y), pkt_received) to_remove = set(pkt_bcast_some).union(pkt_received_some).difference( set(pkt_considered)) dao.delete(data, SEQNO_ATTR, to_remove) # remove packets not considered from node broadcasts paths = dao.get_paths_for_field(data, BROADCAST_ENTRY) path = paths[0] bcast_structures = dao.get_pointer_to(data, path) for bcast_structure in bcast_structures: new_pkt_bcast = set(bcast_structure[BROADCAST_ENTRY])\ .difference(to_remove) bcast_structure[BROADCAST_ENTRY] = list(new_pkt_bcast) # remove first and last epoch estimates paths = dao.get_paths_for_field(data, RTIMER_EPOCH_ATTR) path = paths[0] bcast_structures = dao.get_pointer_to(data, path) for bcast_structure in bcast_structures: new_epoch_rtimer = bcast_structure[RTIMER_EPOCH_ATTR][0 + offset:-offset] bcast_structure[RTIMER_EPOCH_ATTR] = new_epoch_rtimer # test that the pkt broadcast match those received, and vice versa pkt_bcast = [ set(pkt_node) for pkt_node in dao.select(data, BROADCAST_ENTRY) ] pkt_bcast_some = reduce(lambda x, y: x.union(y), pkt_bcast) pkt_received = [set(pkt_node) for pkt_node in dao.select(data, SEQNO_ATTR)] pkt_received_some = reduce(lambda x, y: x.union(y), pkt_received) tx_rx_diff = pkt_bcast_some.symmetric_difference(pkt_received_some) if len(tx_rx_diff) != 0: logger.debug("Packets received and sent differ!") logger.debug("Differing packets: {}".format(tx_rx_diff)) raise DAException("Packets received and sent differ!") return True
def process(api_from, api_to, total_tasks, cur_task): while True: douban=DoubanAPI(api_from, api_to) uids=dao.getUids(50, total_tasks, cur_task) if len(uids)==0: break for i,uid in enumerate(uids): print time.ctime(), 'processing', i, uid recs=douban.getRecs(uid) dao.saveRecs(uid, recs) conts=douban.getContacts(uid) dao.saveContacts(uid, conts) print 'recs:', len(recs), 'conts', len(conts) dao.delete(uids)
def fetchPankou(bisaiId): dao.delete("delete from pankou where bisaiId=%s", (bisaiId, )) print(bisaiId) url = 'http://vip.win0168.com/AsianOdds_n.aspx?id=' + str(bisaiId) html = request.sendRequest(url, "vip.win0168.com") document = pq(html) # print(document) print(str(bisaiId) + "开始") pankouLine = document("table").eq(1).find("tr") bocaiGs = None for i in range(len(pankouLine)): if i <= 1 or i > (len(pankouLine) - 3): continue hang = pq(pankouLine[i]).find("td") if pq(hang[0]).text() != '': bocaiGs = pq(hang[0]).text() pankouName = None if pq(hang[1]).text() == '': pankouName = "盘口1" else: pankouName = pq(hang[1]).text() first_zhudui = pq(hang[2]).html() first_pankou = pq(hang[3]).html() first_cidui = pq(hang[4]).html() finally_zhudui = pq(hang[5]).html() finally_pankou = pq(hang[6]).html() finally_cidui = pq(hang[7]).html() count = dao.selectOne( "select count(id) from bocaiGs where bocaiGsName=%s", (bocaiGs, )) if count[0] <= 0: dao.insert("insert into bocaiGs(bocaiGsName)" " VALUES (%s) ", (bocaiGs, )) first_pankou_alias = None if first_pankou != None: first_pankou_alias = dao.selectOne( "select alias from pankouLabel where pankou=%s limit 1", (first_pankou, )) first_pankou_alias = first_pankou_alias[0] finally_pankou_alias = None if finally_pankou != None: finally_pankou_alias = dao.selectOne( "select alias from pankouLabel where pankou=%s limit 1", (finally_pankou, )) finally_pankou_alias = finally_pankou_alias[0] data = (bocaiGs, pankouName, first_zhudui, first_pankou, first_cidui, finally_zhudui, finally_pankou, finally_cidui, bisaiId, first_pankou_alias, finally_pankou_alias) dao.insert( "insert into pankou(bocaiGs,pankouName,first_zhudui,first_pankou,first_cidui,finally_zhudui,finally_pankou,finally_cidui,bisaiId,first_pankou_alias,finally_pankou_alias)" " VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) ", data) print(str(bisaiId) + "结束")
def main(): timeout = 0 Jogador1 = 0 Jogador2 = 0 Jogador3 = 0 Jogador4 = 0 turnos = [] for i in range(0, 10): resultado, rodadas = jogar() print("Teste Numero: " + str(i)) if resultado == "Os participantes desistiram de jogar": timeout += 1 turnos.append(rodadas) if resultado == Jogador1: Jogador1 += 1 turnos.append(rodadas) if resultado == Jogador2: Jogador2 += 1 turnos.append(rodadas) if resultado == Jogador3: Jogador3 += 1 turnos.append(rodadas) if resultado == Jogador4: Jogador4 += 1 turnos.append(rodadas) dao.delete() print('O total de Partidas termindas em time out foram: ' + str(timeout)) print('A porcentagem de vitoria de cada um é: /n') print("Impulsivo: " + str(Jogador1)) print("exigente: " + str(Jogador2)) print("cauteloso: " + str(Jogador3)) print("aleatório: " + str(Jogador4)) print("O comportamento que mais vence é: " + str(maior(Jogador1, Jogador2, Jogador3, Jogador4))) print("Amedia de turnos foram de:" + str((sum(turnos) / len(turnos))))
def deletarUsuario(self, index): del self.__usuarios[index] delete('usuarios', index)
test_user_db) == True) assert (len(dao.select("SELECT * FROM test", test_user_db, False)) == 0) print("Checking insert test user db...") assert (dao.insert("INSERT INTO test(id, name) VALUES(?,?)", [123, "taro"], test_user_db) == True) assert (len(dao.select("SELECT * FROM test", test_user_db, False)) == 1) print("Checking update test user db...") assert (dao.update("UPDATE test SET name=? WHERE id=?", ["goro", 123], test_user_db) == True) assert (len(dao.select("SELECT * FROM test", test_user_db, False)) == 1) assert (dao.select("SELECT * FROM test", test_user_db, False)[0][1] == "goro") print("Checking delete a column test test db...") assert (dao.delete("DELETE FROM test WHERE id=?", [123], test_user_db) == True) assert (len(dao.select("SELECT * FROM test", test_user_db, False)) == 0) print("Checking insert user provisionally into test user db...") assert (dao.insertProvisionalUser2Db("name_test_1", "*****@*****.**", "123abc456def", "oneTimePassforUserEmailComfirm", test_user_db) == True) assert (dao.insertProvisionalUser2Db("name_test_2", "*****@*****.**", "123abc456def", "oneTimePassforUserEmailComfirm2", test_user_db) == True) assert (len(dao.select("SELECT * FROM provisionalUser", test_user_db, False)) == 2) assert (dao.select("SELECT * FROM provisionalUser", test_user_db, False)[0][0] == 1)
def checkin_guest_remove(checkin_id: int): checkin_guest = get(CheckInGuest, request.form['checkin_guest_id']) delete(checkin_guest) flash(f'Yes, {checkin_guest.guest.name} removido com sucesso.', 'success') return redirect(url_for('checkins.checkin_details', checkin_id=checkin_id))