<commit_before>"""A webapp2 server for ChunaaviTukka."""

import os
import urllib
import json
import logging
import re

from google.appengine.api import users
from google.appengine.ext import ndb

from models import CTUser 
from models import CTCandidate 
from models import CTConstituency
from models import CTTukka 

import jinja2
import webapp2


JINJA_ENVIRONMENT = jinja2.Environment(
    loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
    extensions=['jinja2.ext.autoescape'],
    autoescape=True)

def user_setup(self):
    '''Function to do basic user URL setup'''
    google_user = users.get_current_user()
    if google_user:
        url = users.create_logout_url(self.request.uri)
        url_linktext = 'Logout'
        ct_user = CTUser.get_or_insert(google_user)
    else:
        url = users.create_login_url(self.request.uri)
        url_linktext = 'Login'
        ct_user = None
    return (ct_user, url, url_linktext)

def get_predictions(user_id):
    return [{'cons':{'name':'Varanasi','slug':'varanasi-up'},'candidate':{'id':'1234','name':'M.M.Malaviya','party':'BHU','coalition': 'ABC'}},{'cons':{'name':'Amritsar','slug':'amritsar-pu'},'candidate':{'id':'5678','name':'<NAME>','party':'Gurdwara','coalition': 'XYZ'}}]

def get_constituency_info(contest_slug):
    if contest_slug != 'varanasi' and contest_slug != 'lucknow':
        return {'name':'Some city', 'state': 'some state', 'predictions':[{'candidate':{'id':'1234','name':'M.M.Malaviya','party':'BHU','coalition': 'ABC'},'support':100},{'candidate':{'id':'5678','name':'<NAME>','party':'Gurdwara','coalition': 'XYZ'},'support':75}]}
    else:
        conskey = ndb.Key(CTConstituency, contest_slug)
#        logging.error(conskey)
        #TODO exception handling
        cons = conskey.get()
#        logging.error(cons)
        predictions = []
        for candidate_key in cons.candidates:
            c = candidate_key.get()<commit_msg>Added display name to logout text.<commit_after>"""A webapp2 server for ChunaaviTukka."""

import os
import urllib
import json
import logging
import re

from google.appengine.api import users
from google.appengine.ext import ndb

from models import CTUser 
from models import CTCandidate 
from models import CTConstituency
from models import CTTukka 

import jinja2
import webapp2


JINJA_ENVIRONMENT = jinja2.Environment(
    loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
    extensions=['jinja2.ext.autoescape'],
    autoescape=True)

def user_setup(self):
    '''Function to do basic user URL setup'''
    google_user = users.get_current_user()
    if google_user:
        ct_user = CTUser.get_or_insert(google_user)
        url = users.create_logout_url(self.request.uri)
        url_linktext = 'Logout ' + ct_user.display_name
    else:
        url = users.create_login_url(self.request.uri)
        url_linktext = 'Login'
        ct_user = None
    return (ct_user, url, url_linktext)

def get_predictions(user_id):
    return [{'cons':{'name':'Varanasi','slug':'varanasi-up'},'candidate':{'id':'1234','name':'M.M.Malaviya','party':'BHU','coalition': 'ABC'}},{'cons':{'name':'Amritsar','slug':'amritsar-pu'},'candidate':{'id':'5678','name':'<NAME>','party':'Gurdwara','coalition': 'XYZ'}}]

def get_constituency_info(contest_slug):
    if contest_slug != 'varanasi' and contest_slug != 'lucknow':
        return {'name':'Some city', 'state': 'some state', 'predictions':[{'candidate':{'id':'1234','name':'M.M.Malaviya','party':'BHU','coalition': 'ABC'},'support':100},{'candidate':{'id':'5678','name':'<NAME>','party':'Gurdwara','coalition': 'XYZ'},'support':75}]}
    else:
        conskey = ndb.Key(CTConstituency, contest_slug)
#        logging.error(conskey)
        #TODO exception handling
        cons = conskey.get()
#        logging.error(cons)
        predictions = []
        for candidate_key in cons.candidates:
            c = candidate_key.get()
{'fraction_non_alphanumeric': 0.16227958088423206, 'fraction_numerical': 0.013800153335037056, 'mean_word_length': 4.599427753934192, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1312656', 'n_tokens_mistral': 1392, 'n_tokens_neox': 1316, 'n_words': 243}