def candvector(): epsilon = 0.001 vector = [] for v in range(0, 11): v = v / 10.0 if (equals(v, 0.0)): v = v + epsilon if (equals(v, 1.0)): v = v - epsilon vector = vector + [v] return vector
async def update_role(self, ctx): msg = await ctx.send( Constants.MSG_ROLE_MENU.format(ctx.message.author, Constants.EMOJI_EL_SIP_C, Constants.EMOJI_BAM_MAD_C, Constants.EMOJI_EL_YAY_C, Constants.EMOJI_MIIA_GASP_C)) await add_msg_reactions(msg, Constants.ROLES_UPDATE_COMD) def check(reaction, user): return equals(user, ctx.message.author) await asyncio.sleep(1) try: reaction, user = await self.bot.wait_for(Constants.REACTION_ADD, timeout=Constants.THIRTY, check=check) if equals(user, ctx.message.author): el_sip_emoji = self.bot.get_emoji(Constants.EMOJI_EL_SIP_C_ID) bam_mad_emoji = self.bot.get_emoji( Constants.EMOJI_BAM_MAD_C_ID) el_yay_emoji = self.bot.get_emoji(Constants.EMOJI_EL_YAY_C_ID) miia_gasp_emoji = self.bot.get_emoji( Constants.EMOJI_MIIA_GASP_C_ID) if equals(reaction.emoji, el_sip_emoji): logger.info("%s (un)registered as a %s", ctx.message.author.display_name, Constants.CARAMEL_POPCORN) await self.set_popcorn_role(ctx) if equals(reaction.emoji, bam_mad_emoji): logger.info("%s (un)registered as a %s", ctx.message.author.display_name, Constants.DOUGHTART) await self.set_dota_role(ctx) if equals(reaction.emoji, el_yay_emoji): logger.info("%s (un)registered as a %s", ctx.message.author.display_name, Constants.DND_CRUMBS) await self.set_dnd_role(ctx) if equals(reaction.emoji, miia_gasp_emoji): logger.info("%s (un)registered as a %s", ctx.message.author.display_name, Constants.BOSS_HUNTER) await self.set_bh_role(ctx) await msg.delete() except asyncio.TimeoutError: await msg.delete()
def check(reaction, user): return equals(user, ctx.message.author)
def isGood( n ): return equals( *map( lambda x : sorted( digits( x ) ), ( n * i for i in xrange( 1, 7 ) ) ) )
from utils import triangleGen, pentagonGen, hexagonGen, argmin, equals Z = T, P, H = triangleGen(), pentagonGen(), hexagonGen() z = t, p, h = map( next, ( T, P, H ) ) while not equals( *z ) or z[0] in ( 1, 40755 ): m = argmin( *z ) z[ m ] = next( Z[ m ] ) print z[ 0 ]
# get author from DB db_author = session.query(ElibraryAuthor).filter( ElibraryAuthor.elibraryAuthorId == author['elibraryAuthorId']).first() was_updated = False was_created = False if not db_author: db_author = ElibraryAuthor() was_created = True for key in author: value = toCorrectType(author[key]) db_value = db_author.__getattribute__(key) if not equals(db_value, value): was_updated = True db_author.__setattr__(key, value) nowdate = datetime.now() if was_created: db_author.createdAt = nowdate if was_created or was_updated: db_author.updatedAt = nowdate session.add(db_author) session.commit() session.close()
product = el.get_product_by_id(product_id) was_updated = False was_created = False if not db_product: db_product = ElibraryProduct() was_created = True for key in product: if key != 'journal': value = toCorrectType(product[key]) db_value = db_product.__getattribute__(key) if not equals(db_value, value): was_updated = True db_product.__setattr__(key, value) if 'journal' in product: db_journal = session.query(ElibraryJournal).filter( ElibraryJournal.eLibraryJournalId == int(product['journal'] ['id'])).first() if db_journal: # if impact factor changed if not equals(db_journal.impactFactor, product['journal']['impactFactor']): db_journal.impactFactor = product['journal'][ 'impactFactor'] db_journal.updatedAt = datetime.now()
def test_source(d, s, time_err, pos_err): """ @param s: source (type: Source) d: data from trajectory file (type: dic) time_err: time threshold (type: float) time_pos: space threshold (type: float) @return: False if someting went wrong. Otherwise, return True """ logging.info("testing source ids: %s", ", ".join(map(str, s.ids))) debug_msg = ("source properties: \n\t\t\t\t time_min=" + str(s.time_min) + " time_max=" + str(s.time_max) + "\n" "\t\t\t\t xmin=" + str(s.xmin) + " xmax=" + str(s.xmax) + "\n" "\t\t\t\t ymin=" + str(s.ymin) + " ymax=" + str(s.ymax) + "\n" "\t\t\t\t startX=" + str(s.startX) + " startY=" + str(s.startY) + "\n" "\t\t\t\t frequency=" + str(s.frequency) + "\n" "\t\t\t\t percent=" + str(s.percent) + "\n" "\t\t\t\t rate=" + str(s.rate) + "\n" "\t\t\t\t n_create=" + str(s.N_create) + "\n" "\t\t\t\t agents_max=" + str(s.agents_max) + "\n" "\t\t\t\t time=" + str(s.time)) logging.info(debug_msg) times = [] # TODO # if s.N_create: # correct_length = s.N_create == len(s.ids) # if no correct_length: # logging.error("expected "+ str(s.N_create) # ", but got "+str(len(s.ids)) # ) # return False for j, source_id in enumerate(s.ids): in_time_interval = True in_box_x = True in_box_y = True on_time = True if not source_id in d.keys(): logging.error("source_id: %d is not in data", source_id) msg = ("Data keys : " + ", ".join(map(str, sorted(d.keys())))) logging.error(msg) return False if s.time: on_time = equals(d[source_id][0], s.time, err=time_err) if s.time_min and s.time_max: in_time_interval = contains(d[source_id][0], s.time_min, s.time_max, time_err) if s.xmin and s.xmax: in_box_x = contains(d[source_id][1], s.xmin, s.xmax, pos_err) if s.ymin and s.ymax: in_box_y = contains(d[source_id][2], s.ymin, s.ymax, pos_err) # frequency if s.frequency: times.append(d[source_id][0]) if not in_time_interval or \ not in_box_x or \ not in_box_y or \ not on_time: err_msg = ("source id " + str(source_id) + " " "creation time at " + str(d[source_id][0]) + " in position (" + str(d[source_id][1]) + ", " + str(d[source_id][2]) + ")") logging.error(err_msg) return False if not times: return True msg = ("Got times : " + ", ".join(map(str, times))) logging.info(msg) should_be = s.cycle() # test ids if len(s.ids) != len(should_be): logging.error("length of ids is not correct") msg = ("ids : " + ", ".join(map(str, s.ids))) logging.error(msg) msg = ("should be : " + ", ".join(map(str, should_be))) logging.error(msg) return False else: logging.info("length of ids is fine") if not np.all(np.less_equal(np.abs(times - should_be), time_err)): err_msg = ("frequency mismatch!\n" "Should be: " + ", ".join(map(str, should_be))) logging.error(err_msg) return False return True