<commit_before>import json
import logging
import os

from google.appengine.ext import ndb
from google.appengine.ext.webapp import template

from controllers.base_controller import LoggedInHandler
from datafeeds.csv_awards_parser import CSVAwardsParser
from helpers.award_manipulator import AwardManipulator
from models.award import Award
from models.event import Event
from models.team import Team


class AdminAwardDashboard(LoggedInHandler):
    """
    Show stats about Awards
    """
    def get(self):
        self._require_admin()
        award_count = Award.query().count()

        self.template_values.update({
            "award_count": award_count
        })

        path = os.path.join(os.path.dirname(__file__), '../../templates/admin/award_dashboard.html')
        self.response.out.write(template.render(path, self.template_values))


class AdminAwardAdd(LoggedInHandler):
    """
    Add Award from JSON.
    """
    def post(self):
        self._require_admin()
        awards_csv = self.request.get('awards_csv')

        events = {}  # for reducing datastore fetches of events and teams
        awards = []
        for award in CSVAwardsParser.parse(awards_csv):
            event_key_name = '{}{}'.format(award['year'], award['event_short'])
            if event_key_name in events:
                event = events[event_key_name]
            else:
                event = Event.get_by_id(event_key_name)
                if event is None:
                    logging.warning("Event: {} doesn't exist!".format(event_key_name))
                    continue
                events[event_key_name] = event

            awards.append(Award(
                id=Award.render_key_name(event.key_name, award['award_type_enum']),
                name_str=award['name_str'],
                award_type_enum=award['award_type_enum'],
                year=event.year,
                event=event.key,
                event_type_enum=event.event_type_enum,
                team_list=[ndb.Key(Team, 'frc{}'.format(team_number)) for team_number in award['team_number_list']],
                recipient_json_list=award['recipient_json_list']<commit_msg>Fix comment<commit_after>import json
import logging
import os

from google.appengine.ext import ndb
from google.appengine.ext.webapp import template

from controllers.base_controller import LoggedInHandler
from datafeeds.csv_awards_parser import CSVAwardsParser
from helpers.award_manipulator import AwardManipulator
from models.award import Award
from models.event import Event
from models.team import Team


class AdminAwardDashboard(LoggedInHandler):
    """
    Show stats about Awards
    """
    def get(self):
        self._require_admin()
        award_count = Award.query().count()

        self.template_values.update({
            "award_count": award_count
        })

        path = os.path.join(os.path.dirname(__file__), '../../templates/admin/award_dashboard.html')
        self.response.out.write(template.render(path, self.template_values))


class AdminAwardAdd(LoggedInHandler):
    """
    Add Award from CSV.
    """
    def post(self):
        self._require_admin()
        awards_csv = self.request.get('awards_csv')

        events = {}  # for reducing datastore fetches of events and teams
        awards = []
        for award in CSVAwardsParser.parse(awards_csv):
            event_key_name = '{}{}'.format(award['year'], award['event_short'])
            if event_key_name in events:
                event = events[event_key_name]
            else:
                event = Event.get_by_id(event_key_name)
                if event is None:
                    logging.warning("Event: {} doesn't exist!".format(event_key_name))
                    continue
                events[event_key_name] = event

            awards.append(Award(
                id=Award.render_key_name(event.key_name, award['award_type_enum']),
                name_str=award['name_str'],
                award_type_enum=award['award_type_enum'],
                year=event.year,
                event=event.key,
                event_type_enum=event.event_type_enum,
                team_list=[ndb.Key(Team, 'frc{}'.format(team_number)) for team_number in award['team_number_list']],
                recipient_json_list=award['recipient_json_list']
{'fraction_non_alphanumeric': 0.09932699002088652, 'fraction_numerical': 0.0, 'mean_word_length': 2.5270049099836336, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '5990376', 'n_tokens_mistral': 1269, 'n_tokens_neox': 1235, 'n_words': 238}