Ejemplo n.º 1
0
 def summary(self):
     LOGGER.info("Summary for %s data set", utils.colour(self.param.phase))
     LOGGER.info("Number of users: %s", utils.colour(self.num_users))
     LOGGER.info("Number of items: %s",
                 utils.colour(",".join(map(str, self.item_size))))
     LOGGER.info("Number of positive outfits: %s",
                 utils.colour(self.num_posi))
Ejemplo n.º 2
0
 def summary(self):
     LOGGER.info("Summary for fill-in-the-blank data set")
     LOGGER.info("Number of outfits: %s", utils.colour(len(self.fitb)))
     LOGGER.info(
         "Number of candidates (include ground-truth): %s",
         utils.colour(self.param.num_cand),
     )
 def log(self):
     msg, arg = code_to_str(self.codes)
     LOGGER.debug(self.message)
     LOGGER.debug(msg, *arg)
     LOGGER.debug(
         "Codes balance: %s(p) vs %s(n).",
         utils.colour("%.3f" % self.balance),
         utils.colour("%.3f" % (1.0 - self.balance)),
     )
     LOGGER.debug(
         "Codes value: %s percent whose absolute value greater then 0.95",
         utils.colour("%.3f" % (self.ratio * 100)),
     )
Ejemplo n.º 4
0
 async def nick(self, ctx, member: Member, *, nickname):
     if len(nickname) <= 32:
         await member.edit(nick=nickname)
         changed_embed = Embed(
             title='Nickname',
             description=
             f'The nickname was changed successfully to {nickname}',
             colour=colour())
         await ctx.send(embed=changed_embed)
     else:
         too_long_embed = Embed(
             title='Nickname',
             description='The length of the nickname must be fewer than 32',
             colour=colour())
         await ctx.send(embed=too_long_embed)
Ejemplo n.º 5
0
def main():
    parser = argparse.ArgumentParser(
        description="DeGeŠ Markdown style checker", )
    parser.add_argument('infiles',
                        nargs='+',
                        type=argparse.FileType('r'),
                        default=[sys.stdin])
    parser.add_argument('-v', '--verbose', action='store_true')
    args = parser.parse_args()

    for filename in args.infiles:
        if checkMarkdownFile(filename):
            if args.verbose:
                print("File {name} {ok}".format(
                    name=colour(filename.name, 'name'),
                    ok=colour('OK', 'ok'),
                ))
Ejemplo n.º 6
0
 async def joke(self, ctx):
     joke_embed = Embed(title='Joke', color=colour())
     joke = get('https://official-joke-api.appspot.com/jokes/random').json()
     joke_embed.description = joke['setup']
     sent_message = await ctx.send(embed=joke_embed)
     await sleep(10)
     joke_embed.description = joke['punchline']
     await sent_message.edit(embed=joke_embed, delete_after=10)
Ejemplo n.º 7
0
 def set_nega_mode(self, mode):
     """Set negative outfits mode."""
     assert mode in [
         "RandomOnline",
         "RandomFix",
         "HardOnline",
         "HardFix",  # not implemented
     ], "Unknown negative mode."
     if self.param.data_mode == "PosiOnly":
         LOGGER.warning(
             "Current data-mode is %s. "
             "The negative mode will be ignored!",
             utils.colour(self.param.data_mode, "Red"),
         )
     else:
         LOGGER.info("Set negative mode to %s.", utils.colour(mode))
         self.param.nega_mode = mode
         self.make_nega()
Ejemplo n.º 8
0
    async def colour(self, ctx, *, colour):
        # Grabbing existing colors and parsing into a dictionary
        coloursJSON = (await dbcontrol.get_guild(ctx.guild.id))['colours']
        coloursDict = json.loads(coloursJSON)

        # Getting the hex code for the color using the utils function
        colour = utils.colour(colour)

        if not colour:
            # utils.colour returns False if the colour is invalid
            await ctx.send(":x: **Invalid Colour**")
        else:
            # Checking through each existing colour role to delete it from db if it doesn't exist or remove it from the
            # user if they have it
            for key in list(coloursDict.keys()):
                role = ctx.guild.get_role(coloursDict[str(key)])
                # If the role doesn't exist for some reason its removed from the db
                if role is None:
                    coloursDict.pop(key)
                    coloursJSON = json.dumps(coloursDict)
                    await dbcontrol.modify_guild(ctx.guild.id, 'colours',
                                                 coloursJSON)
                # If the user already has a colour role it is removed
                if role in ctx.author.roles:
                    await ctx.author.remove_roles(
                        role, reason="Automated colour role removal")
                    await ctx.send("**Your existing colour role was removed**")

            # If a role already exists for chosen colour we don't want to make a new one so the existing role is given
            if str(colour.value) in list(coloursDict.keys()):
                role = ctx.guild.get_role(coloursDict[str(colour.value)])
                # If the target colour role is higher than the bots top role then it can't assign it
                if role > ctx.guild.me.top_role:
                    return await ctx.send(
                        ":x: **I don't have permission to give you that role**"
                    )
                if role in ctx.author.roles:
                    return await ctx.send(":x: **You already have this role**")
                await ctx.author.add_roles(role,
                                           reason="Automated colour command")
                await ctx.send(
                    f":thumbsup: **You have been given the role ``{colour.value}``**"
                )

            # If role doesn't exist then the new role is created, added to db, and given to the user
            else:
                role = await ctx.guild.create_role(name=str(colour.value),
                                                   colour=colour)
                coloursDict[colour.value] = role.id
                coloursJSON = json.dumps(coloursDict)
                await dbcontrol.modify_guild(ctx.guild.id, 'colours',
                                             coloursJSON)
                await ctx.author.add_roles(role,
                                           reason="Automated colour command")
                await ctx.send(
                    f":thumbsup: **You have been given the role ``{colour.value}``**"
                )
Ejemplo n.º 9
0
    async def color(self, ctx, *, colour):

        colour = utils.colour(colour)
        if colour:
            await dbcontrol.modify_user(ctx.author.id, 'profile_color',
                                        colour.value)
            await ctx.send(
                f":thumbsup: **Profile color set to `{colour.value}`.**")
        else:
            await ctx.send(":x: **Invalid colour**")
Ejemplo n.º 10
0
 def set_prob_hard(self, p):
     """Set the proportion for hard negative examples."""
     if self.param.data_mode == "PosiOnly":
         LOGGER.warning(
             "Current data-mode is %s. "
             "The proportion will be ignored!",
             utils.colour(self.param.data_mode, "Red"),
         )
     elif self.param.nega_mode != "HardOnline":
         LOGGER.warning(
             "Current negative-sample mode is %s. "
             "The proportion will be ignored!",
             utils.colour(self.param.nega_mode, "Red"),
         )
     else:
         self.phard = p
         LOGGER.info(
             "Set the proportion of hard negative outfits to %s",
             utils.colour("%.3f" % p),
         )
Ejemplo n.º 11
0
 def set_data_mode(self, mode):
     """Set data mode."""
     assert mode in [
         "TupleOnly",
         "PosiOnly",
         "NegaOnly",
         "PairWise",
         "TripleWise",  # not implemented
     ], ("Unknown data mode: %s" % mode)
     LOGGER.info("Set data mode to %s.", utils.colour(mode))
     self.param.data_mode = mode
Ejemplo n.º 12
0
def checkMarkdownFile(file):
    ok = True

    try:
        check.encoding(file.name)
    except check.EncodingError as e:
        print("File {name} is not valid: {message}".format(
            name=colour(file.name, 'name'),
            message=colour(e.message, 'error'),
        ))
        return False

    for number, line in enumerate(file):
        try:
            checkSingleLine(line)
        except check.SingleLineError as e:
            print("File {name} line {num}: {message}".format(
                name=colour(file.name, 'name'),
                message=colour(e.message, 'error'),
                num=colour(number, 'no')))
            print(colour(line, 'no', 'hv'), end='')
            print('-' * (e.column - 2) + '^')
            ok = False

    return ok
Ejemplo n.º 13
0
 def __init__(self, param):
     """Initialize a loader for FITBDataset."""
     LOGGER = logging.getLogger(__name__)
     LOGGER.info(
         "Loading data (%s) in phase (%s)",
         utils.colour(param.data_set),
         utils.colour(param.phase),
     )
     LOGGER.info(
         "Data loader configuration: batch size (%s) "
         "number of workers (%s)",
         utils.colour(param.num_cand),
         utils.colour(param.num_workers),
     )
     transforms = get_img_trans(param.phase, param.image_size)
     self.dataset = FITBDataset(param, transforms)
     self.loader = DataLoader(
         dataset=self.dataset,
         batch_size=param.num_cand,
         num_workers=param.num_workers,
         shuffle=False,
         pin_memory=True,
     )
Ejemplo n.º 14
0
 def __init__(self, param):
     """Initialize a loader for Polyvore."""
     LOGGER.info(
         "Loading data (%s) in phase (%s)",
         utils.colour(param.data_set),
         utils.colour(param.phase),
     )
     LOGGER.info(
         "Data loader configuration: batch size (%s) "
         "number of workers (%s)",
         utils.colour(param.batch_size),
         utils.colour(param.num_workers),
     )
     transforms = get_img_trans(param.phase, param.image_size)
     self.dataset = PolyvoreDataset(param, transforms)
     self.loader = DataLoader(
         dataset=self.dataset,
         batch_size=param.batch_size,
         num_workers=param.num_workers,
         shuffle=param.shuffle,
         pin_memory=True,
     )
     self.num_users = self.dataset.num_users
Ejemplo n.º 15
0
 def make_carry(self):
     shape = g.carry_shape
     ind = random.randint(0, 4)
     img = shape.imgs[ind]
     if g.scale < 1:
         w = int(img.get_width() * g.scale)
         h = int(img.get_height() * g.scale)
         try:
             img = pygame.transform.smoothscale(img, (w, h))
         except:
             img = pygame.transform.scale(img, (w, h))
     img = utils.colour(img, colours[g.colour_ind])
     if g.angle != 0: img = pygame.transform.rotate(img, g.angle)
     w2 = img.get_width() / 2
     h2 = img.get_height() / 2
     g.carry_img = img
     g.carry_dxy = w2, h2