<commit_before># MIT License
# Copyright (c) 2017 MassChallenge, Inc.

from impact.utils import compose_filter
from impact.v1.events.base_history_event import BaseHistoryEvent
from impact.v1.helpers import (
    INTEGER_FIELD,
    STRING_FIELD,
)


class OrganizationBecameWinnerEvent(BaseHistoryEvent):
    DESCRIPTION_FORMAT = "Became Winner for {}"
    EVENT_TYPE = "became winner"

    CLASS_FIELDS = {
        "cycle": STRING_FIELD,
        "cycle_id": INTEGER_FIELD,
        "program": STRING_FIELD,
        "program_id": INTEGER_FIELD,
        "winner_level": STRING_FIELD,
        "winner_level_name": STRING_FIELD,
    }

    def __init__(self, startup_status):
        super().__init__()
        self._program = startup_status.program_startup_status.program
        self.startup_status = startup_status

    @classmethod
    def events(cls, organization):
        result = []
        for startup in organization.startup_set.all():
            for ss in startup.startupstatus_set.filter(**compose_filter(
                    ["program_startup_status",
                     "startup_role",
                     "name",
                     "icontains"],
                    "winner")):
                result.append(cls(ss))
        return result

    def calc_datetimes(self):
        self.earliest = (self.startup_status.created_at
                         or self._program.end_date)

    def description(self):
        return self.DESCRIPTION_FORMAT.format(
            self.startup_status.program_startup_status.program.name)<commit_msg>[AC-5347] fix name of queryset manager.<commit_after># MIT License
# Copyright (c) 2017 MassChallenge, Inc.

from impact.utils import compose_filter
from impact.v1.events.base_history_event import BaseHistoryEvent
from impact.v1.helpers import (
    INTEGER_FIELD,
    STRING_FIELD,
)


class OrganizationBecameWinnerEvent(BaseHistoryEvent):
    DESCRIPTION_FORMAT = "Became Winner for {}"
    EVENT_TYPE = "became winner"

    CLASS_FIELDS = {
        "cycle": STRING_FIELD,
        "cycle_id": INTEGER_FIELD,
        "program": STRING_FIELD,
        "program_id": INTEGER_FIELD,
        "winner_level": STRING_FIELD,
        "winner_level_name": STRING_FIELD,
    }

    def __init__(self, startup_status):
        super().__init__()
        self._program = startup_status.program_startup_status.program
        self.startup_status = startup_status

    @classmethod
    def events(cls, organization):
        result = []
        for startup in organization.startups.all():
            for ss in startup.startupstatus_set.filter(**compose_filter(
                    ["program_startup_status",
                     "startup_role",
                     "name",
                     "icontains"],
                    "winner")):
                result.append(cls(ss))
        return result

    def calc_datetimes(self):
        self.earliest = (self.startup_status.created_at
                         or self._program.end_date)

    def description(self):
        return self.DESCRIPTION_FORMAT.format(
            self.startup_status.program_startup_status.program.name)
{'fraction_non_alphanumeric': 0.08907401473886575, 'fraction_numerical': 0.00512656199935918, 'mean_word_length': 2.393478260869565, 'pattern_counts': {'":': 12, '<': 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': '5395361', 'n_tokens_mistral': 938, 'n_tokens_neox': 875, 'n_words': 170}