コード例 #1
0
ファイル: mainPollApp.py プロジェクト: Luksos9/PythonSQL
def prompt_vote_poll():
    poll_id = int(input("Enter poll you would like to vote on: "))

    _print_poll_options(Poll.get(poll_id).options)

    option_id = int(input("Enter option you'd like to vote for: "))
    username = input("Enter the username you'd like to vote as: ")
    Option.get(option_id).vote(username)
コード例 #2
0
def generate_questions(conf, group_conf):
    df = group_conf['df']
    name = f"Comité exécutif {group_conf['semester']}"
    description = "Pour cette section, seulement une personne peut-être élue par poste."
    group = Group(name, description)
    postes = conf['postes_exec']

    questions = []
    questions_map = {}

    # clean poste vise
    for poste in postes:
        df.loc[df[POSTE_VISE].str.
               contains(pat=f"(?:^{postes[poste]}|{poste})", regex=True),
               POSTE_VISE] = poste

    applied_posts = [
        poste for poste in postes if poste in df[POSTE_VISE].unique().tolist()
    ]

    for i, poste in enumerate(applied_posts):
        question = Question(
            code=poste + group_conf['semester'],
            gid=group.gid,
            title=f"Qui voulez-vous au poste de {postes[poste]}?",
            qtype='L',
            order=i)

        questions.append(question)
        questions_map[poste] = question

    if 'unused_posts' not in group_conf.keys():
        group_conf['unused_posts'] = []

    for poste in postes:
        if poste not in applied_posts:
            group_conf['unused_posts'].append(poste)

    for _, candidat in df.iterrows():
        poste = candidat[POSTE_VISE]
        option = Option(nom=candidat[NOM_USUEL],
                        promotion=candidat[PROMOTION],
                        concentration=candidat[CONCENTRATION],
                        order=questions_map[poste].answer_count(),
                        description=candidat[TEXTE_DESCRIPTIF],
                        image=candidat[PHOTO])

        questions_map[poste].add_answer(option)
        questions_map[poste].add_option(option)

    for poste in questions_map:
        lachaise = Option.add_chaise(questions_map[poste].answer_count())
        questions_map[poste].add_answer(lachaise)
        questions_map[poste].add_option(lachaise)

    return group, questions
コード例 #3
0
ファイル: app.py プロジェクト: Tvister7/PollApp
def prompt_vote_poll():
    poll_id = int(input("Введите номер опроса, где хотели бы проголосовать: "))
    try:
        _print_poll_options(Poll.get(poll_id).options)

        option_id = int(input("Выберете интересующий Вас пункт: "))
        username = input("Введите свой ник: ")

        Option.get(option_id).vote(username)
    except TypeError:
        print("Нет опроса под этим номером!")
コード例 #4
0
ファイル: player.py プロジェクト: Cesar947/TA2_IA
 def __init__(self, i, x, y, nombre1, nombre2, width=500, height=500):
     Component.__init__(self, x, y, width, height)
     if i == 1:
         self.asset = n_player
     else:
         self.asset = n_ia
     self.i = i
     #options
     self.opt1 = Option(1, x + 80, y + 100)
     self.opt2 = Option(2, x + 80, y + 160)
     self.opcion1 = nombre1
     self.opcion2 = nombre2
     self.opciones_seleccionadas = 0
コード例 #5
0
    def create_new_poll(cls):
        owner = input("Please provide your name: ")
        while not owner:
            owner = input("Try again. Please provide your name: ")
        poll_question = input(
            "Please provide a question you want your poll respond for: ")
        while not poll_question:
            poll_question = input(
                "Try again. Please provide a question you want your poll responds for: "
            )
        options = []
        option = input("Please provide the first option: ")
        while option != '':
            options.append(option)
            option = input(
                "Please provide the next option or leave it blank to finish the process, then press Enter : "
            )
        try:
            new_poll = Poll(poll_question, owner)
            poll_id = new_poll.save_to_db()[0]
            for option in options:
                Option(poll_id, option).save_to_db()
        except Exception as e:
            print(e)
            return

        input("Your poll has been created! Press Enter to see it...")
        print("\nPoll id: ", poll_id)
        print(poll_question)
        for option in options:
            print("\t", option)
        input("\nPres Enter to continue...")
        cls.select_from_menu()
コード例 #6
0
def randomize_poll_winner():
    poll_id = int(input("Enter poll you'd like to pick a winner for: "))
    _print_poll_options(Poll.get(poll_id).options)

    option_id = int(input("Enter which is the winning option, we'll pick a random winner from voters: "))
    votes = Option.get(option_id).votes
    winner = random.choice(votes)
    print(f"The randomly selected winner is {winner[0]}.")
コード例 #7
0
def randomize_poll_winner():
    poll_id = int(input("Enter poll you'd like to see a winner for: "))
    poll = Poll.get(poll_id)
    print_poll_options(poll.options)
    option_id = int(input("Input id of option: "))
    option = Option.get(option_id)
    votes = option.votes
    winner = random.choice(votes)
    print(f"winner is {winner[0]}!")
コード例 #8
0
def prompt_vote_poll():
    poll_id = int(input("Enter poll would you like to vote: "))
    poll = Poll.get(poll_id)
    poll_options = poll.options
    print_poll_options(poll_options)
    users_choice = int(input("Now choice the option: "))
    option = Option.get(users_choice)
    users_name = input("Enter your name: ")
    option.vote(users_name)
コード例 #9
0
    def __init__(self, window, pipeline, som):
        self.window = window
        self.sbar = SearchBar(70, 140)
        self.tbar = ToolBar(0, 20)
        self.btn = Button(480, 200)
        self.good_option = Option(1, 200, 550)
        self.bad_option = Option(2, 400, 550)
        self.searched = False
        cwd = os.getcwd()
        files = os.listdir(cwd)
        print("Files in %r: %s" % (cwd, files))

        #CREACION DE INSTANCIA SOM
        self.som = som
        self.pipeline = pipeline
        # Pasando el pipeline como parámetro al TweetDetail
        # TweetDetail: Clase en donde se realiza la extracción y muestra del tweet
        self.tweet_detail = TweetDetail(120, 260, self.pipeline, self.som)
        self.tweet_id = ''
        self.clicked_bar = False
コード例 #10
0
ファイル: app.py プロジェクト: Tvister7/PollApp
def randomize_poll_winner():
    poll_id = int(
        input("Введите номер опроса, где хотите выбрать победителя: "))
    _print_poll_options(Poll.get(poll_id).options)

    option_id = int(
        input(
            "Введите номер выигрышного ответа, победитель будет выбран из проголосавших за него: "
        ))
    votes = Option.get(option_id).votes
    winner = random.choice(votes)
    print(f"Произвольно выбранный победитель: {winner[0]}.")
コード例 #11
0
ファイル: admin.py プロジェクト: ageg/generateur-elections
def generate_questions(group_conf):
    df = group_conf['df']
    name = f"Conseil d'administration {group_conf['semester']}"
    if group_conf['semester'] == 'Annuel':
        description = "Vote de confiance pour les postes annuels au conseil d'administration de l'AGEG."
        code = f"CA{group_conf['semester']}"
        title = "Qui voulez-vous comme administrateurs annuels de l'AGEG?"
    else:
        description = "Vote de confiance pour les postes saisonniers au conseil d'administration de l'AGEG."
        code = "CAS" + group_conf['semester']
        title = "Qui voulez-vous comme administrateurs saisonniers de l'AGEG?"
    group = Group(name, description)

    question_admin = Question(code=code, gid=group.gid, title=title, qtype='F')

    question_admin.add_answer(
        Answer(qid=question_admin.qid, value="Oui", code="A1", order=1))
    question_admin.add_answer(
        Answer(qid=question_admin.qid, value="Non", code="A2", order=2))
    question_admin.add_answer(
        Answer(qid=question_admin.qid,
               value="Non confiance",
               code="A3",
               order=3))

    sous_questions = []
    for index, candidat in df.iterrows():
        subquestion = Subquestion(parent=question_admin.qid,
                                  gid=question_admin.gid,
                                  code=f"SQ{index + 1:02}",
                                  value=candidat[NOM_USUEL],
                                  order=index,
                                  qtype='T')
        sous_questions.append(subquestion)

        question_admin.add_option(
            Option(nom=candidat[NOM_USUEL],
                   promotion=candidat[PROMOTION],
                   concentration=candidat[CONCENTRATION],
                   order=index,
                   description=candidat[TEXTE_DESCRIPTIF],
                   image=candidat[PHOTO]))

    return group, question_admin, sous_questions
コード例 #12
0
    def vote_on_a_poll(cls):
        poll_id = input("Enter the id of the poll you want to vote on: ")
        try:
            poll = Poll.select_by_id(int(poll_id))
        except:
            print(
                "An error occurred. I can't find the poll id '{}' in the database. Please make sure you've entered a valid poll id."
                .format(poll_id))
            cls.vote_on_a_poll()
            return

        options_list = Option.select_by_poll_id(poll_id)

        poll.print_poll_question()
        for option in options_list:
            option.print_option()

        users_vote = input("Enter an id of you answer: ")
        while users_vote not in [
                str(option.option_id) for option in options_list
        ]:
            users_vote = input(
                "This is not a valid answer. Enter an id of you answer: ")
        users_name = input("Enter your name: ")
        while not users_name:
            users_name = input("Enter your name: ")
        users_timezone = input("Enter your timezone: ")
        while users_timezone not in pytz.all_timezones:
            users_timezone = input(
                "This is not a valid timezone. Try again. Enter your timezone: "
            )

        users_timezone_obj = pytz.timezone(users_timezone)
        local_time_of_vote = users_timezone_obj.localize(
            datetime.datetime.now())
        utc_timestamp = local_time_of_vote.astimezone(pytz.utc).timestamp()

        vote = Vote(users_vote, users_name, utc_timestamp)
        vote.save_to_db()

        input(
            f'\nThank you for participating in the poll, {users_name}! Press Enter to continue...'
        )
        cls.select_from_menu()
コード例 #13
0
def generer_options_admin():
    options = []

    for index, candidat in enumerate(fichier_admin.values):
        nom = candidat[colonnes[NOM_USUEL]]
        concentration = candidat[colonnes[CONCENTRATION]]
        promotion = candidat[colonnes[PROMOTION]]

        description = "<p><strong>{nom} ({concentration}, {promotion})</strong></p>".format(
            nom=nom, concentration=concentration, promotion=promotion)
        for line in candidat[colonnes[TEXTE_DESCRIPTIF]].split('\n'):
            description += "<p>{line}</p>\n".format(line=line)

        options.append(
            Option(value=candidat[colonnes[NOM_USUEL]],
                   code="A{numeral}".format(numeral=index + 1),
                   order=index,
                   description=description,
                   image=candidat[colonnes[PHOTO]]))

    return options
コード例 #14
0
        for POSTE in POSTES_VISES:
            poste = candidat[colonnes[POSTE]]
            if isinstance(poste, str):
                nom = candidat[colonnes[NOM_USUEL]]
                order = questions_map[poste].answer_count()
                code = "A{numeral}".format(numeral=order + 1)
                concentration = candidat[colonnes[CONCENTRATION]]

                description = "<p><strong>{name} ({concentration})</strong></p>".format(
                    name=nom, concentration=concentration)
                for line in candidat[colonnes[TEXTE_DESCRIPTIF]].split('\n'):
                    description += "<p>{line}</p>\n".format(line=line)

                option = Option(value=nom,
                                code=code,
                                order=order,
                                description=description,
                                image=candidat[colonnes[PHOTO]])
                questions_map[poste].add_option(option)
                questions_map[poste].add_answer(option)

    for poste in questions_map:
        order = questions_map[poste].answer_count()
        lachaise = Option(
            value="La chaise",
            code="A{numeral}".format(numeral=order + 1),
            order=order,
            description=
            "<p><strong>La chaise (Whatever)</strong></p><p>La chaise ne vous laisseras pas tomber. Elle offre un bon support et connait bien son dossier. Elle connait sa place et ne s'exprime pas quand ce n'est pas son tour.</p>",
            image="http://vote.association.usherbrooke.ca/images/chaise.jpg")
        questions_map[poste].add_option(lachaise)
コード例 #15
0
 def options(self) -> List[Option]:
     with get_connection() as connection:
         options = database.get_poll_options(connection, self.id)
         return [
             Option(option[1], option[2], option[0]) for option in options
         ]
コード例 #16
0
ファイル: player.py プロジェクト: Cesar947/TA2_IA
class Player(Component):
    def __init__(self, i, x, y, nombre1, nombre2, width=500, height=500):
        Component.__init__(self, x, y, width, height)
        if i == 1:
            self.asset = n_player
        else:
            self.asset = n_ia
        self.i = i
        #options
        self.opt1 = Option(1, x + 80, y + 100)
        self.opt2 = Option(2, x + 80, y + 160)
        self.opcion1 = nombre1
        self.opcion2 = nombre2
        self.opciones_seleccionadas = 0

    def draw_player(self, window):
        window.blit(self.asset, (self.x, self.y))
        if self.opt1.get_selected():
            self.opt2.to_block()
        if self.opt2.get_selected():
            self.opt1.to_block()
        #options
        self.opt1.draw_option(window, self.opcion1)
        self.opt2.draw_option(window, self.opcion2)
        #points
        if self.i == 1:
            global puntos_player
            points = font.render("Puntos: " + str(puntos_player), 1, (0, 0, 0))
        if self.i == 2:
            global puntos_ia
            points = font.render("Puntos: " + str(puntos_ia), 1, (0, 0, 0))
        window.blit(points, (self.x + 60, self.y + 30))

    def select_option(self, pos):
        self.opt1.is_over(pos)
        self.opt2.is_over(pos)

    def click_option(self, pos):
        self.opt1.select(pos)
        self.opt2.select(pos)

    def answer(self, opcion):
        if opcion == 0:
            self.opt1.ia_options()
        elif opcion == 1:
            self.opt2.ia_options()

    def validar_opciones(self):
        if self.opt1.get_selected() == True or self.opt2.get_selected(
        ) == True:
            self.opciones_seleccionadas += 1
        return self.opciones_seleccionadas

    def opcion_elegida(self):
        if self.opt1.get_selected() == True:
            return 0
        elif self.opt2.get_selected() == True:
            return 1

    def sumar_puntos(self):
        if self.i == 1:
            global puntos_player
            puntos_player += 1
        if self.i == 2:
            global puntos_ia
            puntos_ia += 1

    def reset(self):
        self.opt1.deselect()
        self.opt2.deselect()

    def get_puntos(self):
        if self.i == 1:
            global puntos_player
            return puntos_player
        if self.i == 2:
            global puntos_ia
            return puntos_ia
コード例 #17
0
 def add_option(self, option_text: str):
     Option(option_text, self.id).save()
コード例 #18
0
def generer_questions_exec(gid):
    questions = []
    questions_map = {}

    fichier_exec = read_csv('example/executif.csv')

    colonnes = {
        CONCENTRATION: -1,
        PROMOTION: -1,
        NOM_USUEL: -1,
        PHOTO: -1,
        TEXTE_DESCRIPTIF: -1,
        POSTE_VISE: -1
    }

    for col in colonnes.keys():
        try:
            colonnes[col] = fichier_exec.columns.get_loc(col)
        except KeyError:
            print(f"Colonne \"{col}\" manquante")
            exit()

    for i in range(0, len(postes)):
        question_code = abbreviations[postes[i]] + SESSION
        question_name = "Qui voulez-vous au poste de {poste}?".format(
            poste=postes[i])
        question = Question(id=i,
                            code=question_code,
                            gid=gid,
                            title=question_name,
                            type='L',
                            order=i)

        questions.append(question)
        questions_map[postes[i]] = question

    for candidat in fichier_exec.values:
        poste = candidat[colonnes[POSTE_VISE]]
        nom = candidat[colonnes[NOM_USUEL]]
        order = questions_map[poste].answer_count()
        code = "A{numeral}".format(numeral=order + 1)
        concentration = candidat[colonnes[CONCENTRATION]]
        promotion = candidat[colonnes[PROMOTION]]

        description = "<p><strong>{name} ({concentration}, {promotion})</strong></p>".format(
            name=nom, concentration=concentration, promotion=promotion)
        for line in candidat[colonnes[TEXTE_DESCRIPTIF]].split('\n'):
            description += "<p>{line}</p>\n".format(line=line)

        option = Option(value=nom,
                        code=code,
                        order=order,
                        description=description,
                        image=candidat[colonnes[PHOTO]])
        questions_map[poste].add_answer(option)
        questions_map[poste].add_option(option)

    for poste in questions_map:
        order = questions_map[poste].answer_count()
        lachaise = Option(
            value="La chaise",
            code="A{numeral}".format(numeral=order + 1),
            order=order,
            description=
            "<p><strong>La chaise</strong></p><p>La chaise ne vous laisseras pas tomber. Elle offre un bon support et connait bien son dossier. Elle connait sa place et ne s'exprime pas quand ce n'est pas son tour.</p>",
            image="http://vote.association.usherbrooke.ca/images/chaise.jpg")
        questions_map[poste].add_answer(lachaise)
        questions_map[poste].add_option(lachaise)

    return questions
コード例 #19
0
 def options(self) -> List[Option]:
     connection = pool.getconn()
     options = database.get_poll_options(connection, self.id)
     pool.putconn(connection)
     return [Option(option[1], option[2], option[0]) for option in options]
コード例 #20
0
    for x in POSTE_VISES:
        poste = candidat[x]
        if isinstance(poste, str):
            nom = candidat[NOM_USUEL]
            order = questions_map[poste].option_count()
            code = "A{numeral}".format(numeral=order + 1)
            concentration = candidat[CONCENTRATION]

            description = "<p><strong>{name} ({concentration})</strong></p>".format(
                name=nom, concentration=concentration)
            for line in candidat[9].split('\n'):
                description += "<p>{line}</p>\n".format(line=line)

            option = Option(value=nom,
                            code=code,
                            order=order,
                            description=description,
                            image=candidat[PHOTO])
            questions_map[poste].add_option(option)

for poste in questions_map:
    order = questions_map[poste].option_count()
    lachaise = Option(
        value="La chaise",
        code="A{numeral}".format(numeral=order + 1),
        order=order,
        description=
        "<p><strong>La chaise (Whatever)</strong></p><p>La chaise ne vous laisseras pas tomber. Elle offre un bon support et connait bien son dossier. Elle connait sa place et ne s'exprime pas quand ce n'est pas son tour.</p>",
        image=
        "/upload/surveys/893586/images/markus_1.jpgd2fe39c4-d929-477e-ae08-ca0ec8e8a9e7Original.jpg"
    )
コード例 #21
0
class App():
    def __init__(self, window, pipeline, som):
        self.window = window
        self.sbar = SearchBar(70, 140)
        self.tbar = ToolBar(0, 20)
        self.btn = Button(480, 200)
        self.good_option = Option(1, 200, 550)
        self.bad_option = Option(2, 400, 550)
        self.searched = False
        cwd = os.getcwd()
        files = os.listdir(cwd)
        print("Files in %r: %s" % (cwd, files))

        #CREACION DE INSTANCIA SOM
        self.som = som
        self.pipeline = pipeline
        # Pasando el pipeline como parámetro al TweetDetail
        # TweetDetail: Clase en donde se realiza la extracción y muestra del tweet
        self.tweet_detail = TweetDetail(120, 260, self.pipeline, self.som)
        self.tweet_id = ''
        self.clicked_bar = False

    def draw_app(self):
        self.sbar.draw_search_bar(self.window)
        self.tbar.draw_tool_bar(self.window)
        self.btn.draw_button(self.window)
        if self.searched == False:
            self.good_option.draw_option(self.window)
            self.bad_option.draw_option(self.window)
        if self.searched == True:
            self.tweet_detail.draw_tweet(self.window)
            if self.tweet_detail.get_result() == 0:
                self.good_option.change_opacity(self.window)
                self.bad_option.increment(self.window)
            if self.tweet_detail.get_result() == 1:
                self.bad_option.change_opacity(self.window)
                self.good_option.increment(self.window)

    def search(self, pos):
        self.sbar.is_clicked(pos)
        if self.clicked_bar == False:
            self.clicked_bar = True
        elif self.clicked_bar == True:
            self.clicked_bar = False

    def erase_text(self, pos):
        if self.clicked_bar == True:
            self.sbar.erase_text(pos)

    def search_text_write(self, event):
        if self.clicked_bar == True:
            self.sbar.write_search_text(event)

    def search_text_space(self, event):
        self.sbar.space_search_text(event)

    def search_text_paste(self):
        self.sbar.paste_search_text()

    def over_button(self, pos):
        self.btn.is_over(pos)

    def click_button(self, pos):
        if self.sbar.get_text() != '':
            self.btn.is_over(pos)
            self.tweet_id = self.sbar.get_tweet_id()
            self.tweet_detail.get_tweet(self.tweet_id)
            self.searched = True