def show_poll_votes(): poll_id = int(input("Какой опрос хотите посмотреть?: ")) try: options = Poll.get(poll_id).options votes_per_option = [len(option.votes) for option in options] total_votes = sum(votes_per_option) try: for option, votes in zip(options, votes_per_option): percentage = votes / total_votes * 100 if votes % 10 in [2, 3, 4]: print( f"Пункт {option.text} получил {votes} голоса ({percentage:.1f}% от общего числа)" ) elif votes % 10 == 1: print( f"Пункт {option.text} получил {votes} голос ({percentage:.1f}% от общего числа)" ) else: print( f"Пункт {option.text} получил {votes} голосов ({percentage:.1f}% от общего числа)" ) except ZeroDivisionError: print("В нем ещё нет голосов.") vote_log = input("Хотите увидеть логи? (да/Нет): ") if vote_log == "да": _print_vote_for_options(options) except TypeError: print("Нет опроса под этим номером!")
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)
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]}.")
def show_poll_votes(): poll_id = int(input("Enter poll you would like to see votes for: ")) poll = Poll.get(poll_id) options = Poll.get(poll_id).options votes_per_option = [len(option.votes) for option in options] total_votes = sum(votes_per_option) try: for option, votes in zip(options, votes_per_option): percentage = votes / total_votes * 100 print(f"{option.text} got {votes} votes ({percentage:.2f}% of total)") except ZeroDivisionError: print("No votes cast for this poll yet.") vote_log = input("Would you like to see the vote log? (y/N) ") if vote_log == "y": _print_votes_for_options(options)
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]}!")
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)
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("Нет опроса под этим номером!")
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]}.")
def show_poll_votes(): poll_id = int(input("Input id of poll you would like to see: ")) poll = Poll.get(poll_id) options = poll.options votes_for_option = [len(option.votes) for option in options] sum_of_votes = sum(votes_for_option) try: for option, votes in zip(options, votes_for_option): vote_percentage = votes / sum_of_votes * 100 print(f"{option.text} got {votes} ({vote_percentage}% of total)") except ZeroDivisionError: print("Poll didnt'd get any votes")
def show_poll_votes(): poll_id = int(input("Enter poll you would like to see votes for: ")) poll = Poll.get(poll_id) options = poll.options votes_per_option = [len(option.votes) for option in options] total_votes = sum(votes_per_option) try: for option, votes in zip(options, votes_per_option): percentage = votes / total_votes * 100 print(f"{option.text} for {votes} ({percentage:.2f}% of total)") except ZeroDivisionError: print("No votes yet cast for this poll.")
def group_start(update: Update, context: CallbackContext) -> State: if update.effective_chat.type == 'group': # create poll based on received event ID words = update.effective_message.text.split(' ') if len(words) <= 1: update.message.reply_text('Please specify the event ID') else: event_uuid = words[1] event = Event.get(uuid=event_uuid) if event == None: update.message.reply_text( f"Event with ID {event_uuid} does not exist\nPlease try again" ) return None context.chat_data['event_id'] = event.id poll = Poll.get(event=event.id) event_dates = poll.options if len(event_dates) == 1: update.message.reply_text( f'Hi everybody ! You have been invited to the event {event.name} which will take place on the {event.date}.\n The location is : {event.location}. \n\n Have a nice event !!!' ) else: message: Message = context.bot.send_poll( update.effective_chat.id, f"Hi everybody ! You have been invited to the event {event.name} which will take place at : {event.location}.\n\nPlease answer the following poll with your availability so that the date can be chosen.", event_dates, is_anonymous=False, allows_multiple_answers=True, ) update.effective_user.send_message( "Here is the poll for your event") message.forward(update.effective_user.id) options = [event_dates] update.effective_user.send_message( "Have you made your choice for the date ?", reply_markup=ReplyKeyboardMarkup(options, one_time_keyboard=True)) return State.VOTING else: update.message.reply_text('This command can only be issued in a group')
def final_date_response(update: Update, context: CallbackContext) -> State: event = Event[context.user_data['id']] poll = Poll.get(event=event.id, type=Poll.TYPES['dates']) text = update.message.text if text in poll.options: event.date = text commit() update.message.reply_text(f"The event will take place on {text}") update.message.reply_text( "Use /kick in the group chat to ask your guests to confirm their participation" ) update.message.reply_text( "Use /guests here the list of guests that have confirmed their participation" ) return State.GUESTLIST else: update.message.reply_text("Please try again")