Exemple #1
0
def exit_group(bot, update, args):
    if util.too_few_args(bot, util.get_chat_id(update), args, 1) is None:
        return
    if re.fullmatch("\w+", args[0]) is None:
        bot.send_message(chat_id=util.get_chat_id(update),
                         text=answers.incorrect_name)
        return
    try:
        admin_id = BD.get_admin(util.cursor, args[0])
        BD.unjoin_user(util.cursor,
                       user_id=util.get_user_id(update),
                       admin_id=admin_id,
                       group_name=args[0])
        bot.send_message(chat_id=admin_id,
                         text="Человек с ID " + str(util.get_user_id(update)) +
                         "покинул группу " + args[0])
    except util.GroupNotExistsException:
        bot.send_message(chat_id=util.get_chat_id(update),
                         text=answers.no_exists_name % "группа")
    except util.UserIsNotAdmin:
        bot.send_message(chat_id=util.get_chat_id(update),
                         text=answers.delete_no_admin % "пользователя")
Exemple #2
0
def create_group(bot, update, args):
    if util.too_few_args(bot, util.get_chat_id(update), args, 1) is None:
        return

    if re.fullmatch("\w+", args[0]) is None:
        bot.send_message(chat_id=util.get_chat_id(update),
                         text=answers.incorrect_name)
        return
    try:
        print("cursor = ", util.cursor)
        BD.create_group(util.cursor, util.get_user_id(update), args[0])
    except util.GroupAlreadyExistsException:
        bot.send_message(chat_id=util.get_chat_id(update),
                         text=answers.already_exists_name % "группа")
Exemple #3
0
def delete_project(bot, update, args):
    if util.too_few_args(bot, util.get_chat_id(update), args, 1) is None:
        return
    if re.fullmatch("\w+", args[0]) is None:
        bot.send_message(chat_id=util.get_chat_id(update),
                         text=answers.incorrect_name + "(проекта)")
        return
    try:
        BD.delete_project(util.cursor, util.get_user_id(update), args[0])
    except util.ProjectNotExistsException:
        bot.send_message(chat_id=util.get_chat_id(update),
                         text=answers.no_exists_name % "проект")
    except util.UserIsNotAdmin:
        bot.send_message(chat_id=util.get_chat_id(update),
                         text=answers.delete_no_admin % "проект")
Exemple #4
0
def enter_group(bot, update, args):
    if util.too_few_args(bot, util.get_chat_id(update), args, 1) is None:
        return
    if re.fullmatch("\w+", args[0]) is None:
        bot.send_message(chat_id=util.get_chat_id(update),
                         text=answers.incorrect_name)
        return
    try:
        admin_id = BD.get_admin(util.cursor, args[0])
        bot.send_message(chat_id=admin_id,
                         text="Пожалуйста присоедините меня к " + args[0] +
                         " мой ID: " + util.get_user_id(update))
    except util.GroupNotExistsException:
        bot.send_message(chat_id=util.get_chat_id(update),
                         text=answers.no_exists_name % "группа")
Exemple #5
0
def unjoin_user(bot, update, args):
    if util.too_few_args(bot, util.get_chat_id(update), args, 2) is None:
        return
    if re.fullmatch("\w+", args[0]) is None:
        bot.send_message(chat_id=util.get_chat_id(update),
                         text=answers.incorrect_name)
        return
    try:
        BD.unjoin_user(util.cursor, args[1], args[0], util.get_user_id(update))
    except util.GroupNotExistsException:
        bot.send_message(chat_id=util.get_chat_id(update),
                         text=answers.no_exists_name % "группа")
    except util.UserIsNotAdmin:
        bot.send_message(chat_id=util.get_chat_id(update),
                         text=answers.delete_no_admin % "пользователя")
Exemple #6
0
def hide_task(bot, update, args):
    if util.too_few_args(bot, util.get_chat_id(update), args, 2) is None:
        return
    names = ("(проекта)", "(таска)")
    for i in range(2):
        if re.fullmatch("\w+", args[i]) is None:
            bot.send_message(chat_id=util.get_chat_id(update), text=answers.incorrect_name + names[i])
            return
    try:
        BD.set_task(util.cursor, util.get_user_id(update), args[1], None, True)#,args[0])
    except util.ProjectNotExistsException:
        bot.send_message(chat_id=util.get_chat_id(update), text=answers.no_exists_name % "проект")
    except util.TaskNotExistsException:
        bot.send_message(chat_id=util.get_chat_id(update), text=answers.already_exists_name % "таск")
    except util.UserHasNotTask:
        bot.send_message(chat_id=util.get_chat_id(update), text=answers.create_no_admin % "таск")
    def create_from_tree(cls,
                         repo,
                         tree,
                         message,
                         parent_commits=None,
                         head=False):
        """Commit the given tree, creating a commit object.
		
		:param repo: Repo object the commit should be part of 
		:param tree: Tree object or hex or bin sha 
			the tree of the new commit
		:param message: Commit message. It may be an empty string if no message is provided.
			It will be converted to a string in any case.
		:param parent_commits:
			Optional Commit objects to use as parents for the new commit.
			If empty list, the commit will have no parents at all and become 
			a root commit.
			If None , the current head commit will be the parent of the 
			new commit object
		:param head:
			If True, the HEAD will be advanced to the new commit automatically.
			Else the HEAD will remain pointing on the previous commit. This could 
			lead to undesired results when diffing files.
			
		:return: Commit object representing the new commit
			
		:note:
			Additional information about the committer and Author are taken from the
			environment or from the git configuration, see git-commit-tree for 
			more information"""
        parents = parent_commits
        if parent_commits is None:
            try:
                parent_commits = [repo.head.commit]
            except ValueError:
                # empty repositories have no head commit
                parent_commits = list()
            # END handle parent commits
        # END if parent commits are unset

        # retrieve all additional information, create a commit object, and
        # serialize it
        # Generally:
        # * Environment variables override configuration values
        # * Sensible defaults are set according to the git documentation

        # COMMITER AND AUTHOR INFO
        cr = repo.config_reader()
        env = os.environ
        default_email = get_user_id()
        default_name = default_email.split('@')[0]

        conf_name = cr.get_value('user', cls.conf_name, default_name)
        conf_email = cr.get_value('user', cls.conf_email, default_email)

        author_name = env.get(cls.env_author_name, conf_name)
        author_email = env.get(cls.env_author_email, default_email)

        committer_name = env.get(cls.env_committer_name, conf_name)
        committer_email = env.get(cls.env_committer_email, conf_email)

        # PARSE THE DATES
        unix_time = int(time())
        offset = altzone

        author_date_str = env.get(cls.env_author_date, '')
        if author_date_str:
            author_time, author_offset = parse_date(author_date_str)
        else:
            author_time, author_offset = unix_time, offset
        # END set author time

        committer_date_str = env.get(cls.env_committer_date, '')
        if committer_date_str:
            committer_time, committer_offset = parse_date(committer_date_str)
        else:
            committer_time, committer_offset = unix_time, offset
        # END set committer time

        # assume utf8 encoding
        enc_section, enc_option = cls.conf_encoding.split('.')
        conf_encoding = cr.get_value(enc_section, enc_option,
                                     cls.default_encoding)

        author = Actor(author_name, author_email)
        committer = Actor(committer_name, committer_email)

        # if the tree is no object, make sure we create one - otherwise
        # the created commit object is invalid
        if isinstance(tree, str):
            tree = repo.tree(tree)
        # END tree conversion

        # CREATE NEW COMMIT
        new_commit = cls(repo, cls.NULL_BIN_SHA, tree, author, author_time,
                         author_offset, committer, committer_time,
                         committer_offset, message, parent_commits,
                         conf_encoding)

        stream = StringIO()
        new_commit._serialize(stream)
        streamlen = stream.tell()
        stream.seek(0)

        istream = repo.odb.store(IStream(cls.type, streamlen, stream))
        new_commit.binsha = istream.binsha

        if head:
            try:
                repo.head.commit = new_commit
            except ValueError:
                # head is not yet set to the ref our HEAD points to
                # Happens on first commit
                import git.refs
                master = git.refs.Head.create(repo,
                                              repo.head.ref,
                                              commit=new_commit)
                repo.head.reference = master
            # END handle empty repositories
        # END advance head handling

        return new_commit
scheduler = BackgroundScheduler()
'''
python -W ignore bellarena.py

1187 users
147 cloths

'''
create_dataset()
data = pd.read_sql_table(table_name, db_url)
recommendations = RecommenderSystem(data)
recommendations.run()
analyser = SentimentAnalyser(data)
analyser.run()


def train_task():
    recommendations.run_finetune_mf()


if __name__ == "__main__":
    scheduler.add_job(func=train_task, trigger="interval", seconds=300)
    scheduler.start()

    user_id = get_user_id(data)
    rec_cloth_ids, recommender_scores = recommendations.predict(user_id)
    sentiment_scores = analyser.predict_sentiments(rec_cloth_ids)

    # Final score
    recommended_ids, recommended_score = get_final_score(
        recommender_scores, sentiment_scores, rec_cloth_ids)
Exemple #9
0
	def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False):
		"""Commit the given tree, creating a commit object.
		
		:param repo: Repo object the commit should be part of 
		:param tree: Tree object or hex or bin sha 
			the tree of the new commit
		:param message: Commit message. It may be an empty string if no message is provided.
			It will be converted to a string in any case.
		:param parent_commits:
			Optional Commit objects to use as parents for the new commit.
			If empty list, the commit will have no parents at all and become 
			a root commit.
			If None , the current head commit will be the parent of the 
			new commit object
		:param head:
			If True, the HEAD will be advanced to the new commit automatically.
			Else the HEAD will remain pointing on the previous commit. This could 
			lead to undesired results when diffing files.
			
		:return: Commit object representing the new commit
			
		:note:
			Additional information about the committer and Author are taken from the
			environment or from the git configuration, see git-commit-tree for 
			more information"""
		parents = parent_commits
		if parent_commits is None:
			try:
				parent_commits = [ repo.head.commit ]
			except ValueError:
				# empty repositories have no head commit
				parent_commits = list()
			# END handle parent commits
		# END if parent commits are unset
		
		# retrieve all additional information, create a commit object, and 
		# serialize it
		# Generally: 
		# * Environment variables override configuration values
		# * Sensible defaults are set according to the git documentation
		
		# COMMITER AND AUTHOR INFO
		cr = repo.config_reader()
		env = os.environ
		default_email = get_user_id()
		default_name = default_email.split('@')[0]
		
		conf_name = cr.get_value('user', cls.conf_name, default_name)
		conf_email = cr.get_value('user', cls.conf_email, default_email)
		
		author_name = env.get(cls.env_author_name, conf_name)
		author_email = env.get(cls.env_author_email, default_email)
		
		committer_name = env.get(cls.env_committer_name, conf_name)
		committer_email = env.get(cls.env_committer_email, conf_email)
		
		# PARSE THE DATES
		unix_time = int(time())
		offset = altzone
		
		author_date_str = env.get(cls.env_author_date, '')
		if author_date_str:
			author_time, author_offset = parse_date(author_date_str)
		else:
			author_time, author_offset = unix_time, offset
		# END set author time
		
		committer_date_str = env.get(cls.env_committer_date, '')
		if committer_date_str: 
			committer_time, committer_offset = parse_date(committer_date_str)
		else:
			committer_time, committer_offset = unix_time, offset
		# END set committer time
		
		# assume utf8 encoding
		enc_section, enc_option = cls.conf_encoding.split('.')
		conf_encoding = cr.get_value(enc_section, enc_option, cls.default_encoding)
		
		author = Actor(author_name, author_email)
		committer = Actor(committer_name, committer_email)
		
		
		# if the tree is no object, make sure we create one - otherwise
		# the created commit object is invalid
		if isinstance(tree, str):
			tree = repo.tree(tree)
		# END tree conversion
		
		# CREATE NEW COMMIT
		new_commit = cls(repo, cls.NULL_BIN_SHA, tree, 
						author, author_time, author_offset, 
						committer, committer_time, committer_offset,
						message, parent_commits, conf_encoding)
		
		stream = StringIO()
		new_commit._serialize(stream)
		streamlen = stream.tell()
		stream.seek(0)
		
		istream = repo.odb.store(IStream(cls.type, streamlen, stream))
		new_commit.binsha = istream.binsha
		
		if head:
			try:
				repo.head.commit = new_commit
			except ValueError:
				# head is not yet set to the ref our HEAD points to
				# Happens on first commit
				import git.refs
				master = git.refs.Head.create(repo, repo.head.ref, commit=new_commit)
				repo.head.reference = master
			# END handle empty repositories
		# END advance head handling 
		
		return new_commit