<commit_before># -*- coding: utf-8 -*-
""" contest models: Contest, Contestant, and Donor

    :copyright: Copyright (c) 2014 Bivio Software, Inc.  All Rights Reserved.
    :license: Apache, see LICENSE for more details.
"""

import decimal
import random
import re

import flask
import sqlalchemy.orm

from .. import biv
from .. import common
from .. import controller
from ..contest import model as pcm
from ..auth import model as pam
from ..controller import db

class Contest(db.Model, pcm.ContestBase):
    """contest database model.

    Fields:
        biv_id: primary ID
        display_name: name of the contest
        tag_line: sub-name of the contest
        contest_logo: image blob
        logo_type: image type (gif, png, jpeg)
        is_scoring_completed: True if the contestant can view their scores
    """
    biv_id = db.Column(
        db.Numeric(18),
        db.Sequence('contest_s', start=1002, increment=1000),
        primary_key=True
    )
    tag_line = db.Column(db.String(500))
    # TODO(pjm): move logo and founder_avatar to separate model BivImage
    contest_logo = db.Column(db.LargeBinary)
    logo_type = db.Column(db.Enum('gif', 'png', 'jpeg', name='logo_type'))
    is_scoring_completed = db.Column(db.Boolean, nullable=False)

    def contestant_count(self):
        """Returns the number of contestants for the current contest"""
        return pam.BivAccess.query.select_from(Contestant).filter(
            pam.BivAccess.source_biv_id == self.biv_id,
            pam.BivAccess.target_biv_id == Contestant.biv_id,
            # not a real ==, Column() overrides __eq__ to generate SQL
            Contestant.is_public == True  # noqa
        ).count()

    def donor_count(self):
        """Returns the total donor count across all the contestants"""
        access_alias = sqlalchemy.orm.aliased(pam.BivAccess)
        return Donor.query.select_from(pam.BivAccess, access_alias).filter(
            pam.BivAccess.source_biv_id == self.biv_id,
            pam.BivAccess.target_biv_id == access_alias.source_biv_id,
            access_alias.target_biv_id == Donor.biv_id,
            Donor.donor_state == 'executed'
        ).count()

    def donor_executed_amount(self):
        """Returns the total amount raised for all executed donors"""<commit_msg>removed unused contest_logo and logo_type fields<commit_after># -*- coding: utf-8 -*-
""" contest models: Contest, Contestant, and Donor

    :copyright: Copyright (c) 2014 Bivio Software, Inc.  All Rights Reserved.
    :license: Apache, see LICENSE for more details.
"""

import decimal
import random
import re

import flask
import sqlalchemy.orm

from .. import biv
from .. import common
from .. import controller
from ..contest import model as pcm
from ..auth import model as pam
from ..controller import db

class Contest(db.Model, pcm.ContestBase):
    """contest database model.

    Fields:
        biv_id: primary ID
        display_name: name of the contest
        tag_line: sub-name of the contest
        is_scoring_completed: True if the contestant can view their scores
    """
    biv_id = db.Column(
        db.Numeric(18),
        db.Sequence('contest_s', start=1002, increment=1000),
        primary_key=True
    )
    tag_line = db.Column(db.String(500))
    is_scoring_completed = db.Column(db.Boolean, nullable=False)

    def contestant_count(self):
        """Returns the number of contestants for the current contest"""
        return pam.BivAccess.query.select_from(Contestant).filter(
            pam.BivAccess.source_biv_id == self.biv_id,
            pam.BivAccess.target_biv_id == Contestant.biv_id,
            # not a real ==, Column() overrides __eq__ to generate SQL
            Contestant.is_public == True  # noqa
        ).count()

    def donor_count(self):
        """Returns the total donor count across all the contestants"""
        access_alias = sqlalchemy.orm.aliased(pam.BivAccess)
        return Donor.query.select_from(pam.BivAccess, access_alias).filter(
            pam.BivAccess.source_biv_id == self.biv_id,
            pam.BivAccess.target_biv_id == access_alias.source_biv_id,
            access_alias.target_biv_id == Donor.biv_id,
            Donor.donor_state == 'executed'
        ).count()

    def donor_executed_amount(self):
        """Returns the total amount raised for all executed donors"""
{'fraction_non_alphanumeric': 0.0984360625574977, 'fraction_numerical': 0.00827966881324747, 'mean_word_length': 2.8899821109123436, 'pattern_counts': {'":': 0, '<': 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': '5361993', 'n_tokens_mistral': 1377, 'n_tokens_neox': 1320, 'n_words': 365}