def check(problem): return (not cf_common.is_nonstandard_problem(problem) and not cf_common.is_contest_writer(problem.contestId, handle))
async def mashup(self, ctx, *args): """Create a mashup contest using problems within -200 and +400 of average rating of handles provided. Add tags with "+" before them. """ delta = 100 handles = [arg for arg in args if arg[0] != '+' and arg[0] != '?'] tags = [arg[1:] for arg in args if arg[0] == '+' and len(arg) > 1] deltaStr = [arg[1:] for arg in args if arg[0] == '?' and len(arg) > 1] if len(deltaStr) > 1: raise CodeforcesCogError('Only one delta argument is allowed') if len(deltaStr) == 1: try: delta += round(int(deltaStr[0]), -2) except ValueError: raise CodeforcesCogError( 'delta could not be interpreted as number') handles = handles or ('!' + str(ctx.author), ) handles = await cf_common.resolve_handles(ctx, self.converter, handles) resp = [await cf.user.status(handle=handle) for handle in handles] submissions = [sub for user in resp for sub in user] solved = {sub.problem.name for sub in submissions} info = await cf.user.info(handles=handles) rating = int( round( sum(user.effective_rating for user in info) / len(handles), -2)) rating += delta rating = max(800, rating) rating = min(3500, rating) problems = [ prob for prob in cf_common.cache2.problem_cache.problems if abs(prob.rating - rating) <= 300 and prob.name not in solved and not any( cf_common.is_contest_writer(prob.contestId, handle) for handle in handles) and not cf_common.is_nonstandard_problem(prob) ] if tags: problems = [prob for prob in problems if prob.tag_matches(tags)] if len(problems) < 4: raise CodeforcesCogError( 'Problems not found within the search parameters') problems.sort(key=lambda problem: cf_common.cache2.contest_cache. get_contest(problem.contestId).startTimeSeconds) choices = [] for i in range(4): k = max(random.randrange(len(problems) - i) for _ in range(2)) for c in choices: if k >= c: k += 1 choices.append(k) choices.sort() problems = sorted([problems[k] for k in choices], key=lambda problem: problem.rating) msg = '\n'.join(f'{"ABCD"[i]}: [{p.name}]({p.url}) [{p.rating}]' for i, p in enumerate(problems)) str_handles = '`, `'.join(handles) embed = discord_common.cf_color_embed(description=msg) await ctx.send(f'Mashup contest for `{str_handles}`', embed=embed)
def get_problems(rating): return [prob for prob in cf_common.cache2.problem_cache.problems if prob.rating == rating and prob.name not in solved and prob.name not in seen and not any(cf_common.is_contest_writer(prob.contestId, handle) for handle in handles) and not cf_common.is_nonstandard_problem(prob)]
def ok(problem): # acmsguru and gyms are fine for recent practice list if not problem.contestId or problem.contestId >= cf.GYM_ID_THRESHOLD: return True return not cf_common.is_nonstandard_problem(problem)