<commit_before>"""
Back-end for the vote page.
"""

__authors__ = ['<NAME> <<EMAIL>>',
               '<NAME> <<EMAIL>>']

import authentication
import database
import datetime
import logging
import webapp2

from authentication import require_login
from main import render_page

class VoteHandler(webapp2.RequestHandler):
    """
    Handles GET requests for the Vote page.
    """

    def get(self):
        page_data = {'open_elections': [], 'election_results': []}

        # Authenticate user
        voter = authentication.get_voter()
        if not voter:
            require_login(self)

        # Elections the user is eligible to vote for
        elections = voter.elections
        election_keys = [election.key() for election in elections]

        # Add universal elections
        universal_elections = database.Election.gql("WHERE universal=TRUE").run()
        for election in universal_elections:
            if datetime.datetime.now() < election.end and election.key() not in election_keys:
                elections.append(election)

        logging.info(elections)

        for election in elections:
            logging.info('Found election')
            data = {}
            data['id'] = str(election.key())
            data['name'] = election.name
            now = datetime.datetime.now()
            if now > election.end:      # Election passed
                result_delay = election.result_delay
                data['end_date'] = election.end.strftime('%a, %B %d, %Y, %I:%M %p') + ' UTC'
                data['time_remaining'] = result_delay * 1000 - (now - election.end).seconds * 1000
                data['result_delay'] = result_delay
                page_data['election_results'].append(data)
            else:
                data['user_action'] = 'not_started' # Initial assumption<commit_msg>Vote: Fixed bug where vote counters would reappear after 24 hours<commit_after>"""
Back-end for the vote page.
"""

__authors__ = ['<NAME> <<EMAIL>>',
               '<NAME> <<EMAIL>>']

import authentication
import database
import datetime
import logging
import webapp2

from authentication import require_login
from main import render_page

class VoteHandler(webapp2.RequestHandler):
    """
    Handles GET requests for the Vote page.
    """

    def get(self):
        page_data = {'open_elections': [], 'election_results': []}

        # Authenticate user
        voter = authentication.get_voter()
        if not voter:
            require_login(self)

        # Elections the user is eligible to vote for
        elections = voter.elections
        election_keys = [election.key() for election in elections]

        # Add universal elections
        universal_elections = database.Election.gql("WHERE universal=TRUE").run()
        for election in universal_elections:
            if datetime.datetime.now() < election.end and election.key() not in election_keys:
                elections.append(election)

        logging.info(elections)

        for election in elections:
            logging.info('Found election')
            data = {}
            data['id'] = str(election.key())
            data['name'] = election.name
            now = datetime.datetime.now()
            if now > election.end:      # Election passed
                result_delay = election.result_delay
                data['end_date'] = election.end.strftime('%a, %B %d, %Y, %I:%M %p') + ' UTC'
                data['result_delay'] = result_delay

                # Compute how much time the user will have to wait to view the election
                time_since_election_end = (now - election.end).seconds + (now - election.end).days * 86400
                if time_since_election_end > result_delay:
                    data['time_remaining'] = -1
                else:
                    data['time_remaining'] = (result_delay - time_since_election_end) *1000
                page_data['election_results'].append(data)
            else:
                data['user_action'] = 'not_started' # Initial assumption
{'fraction_non_alphanumeric': 0.10421836228287841, 'fraction_numerical': 0.005955334987593052, 'mean_word_length': 2.2481869460112813, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3040058', 'n_tokens_mistral': 1106, 'n_tokens_neox': 1041, 'n_words': 291}