<commit_before>from datetime import datetime, timedelta
from typing import Any, Callable, cast, Dict, Tuple

from flask import Response
from google.appengine.ext import ndb

from backend.common.consts.landing_type import LandingType
from backend.common.decorators import cached_public
from backend.common.flask_cache import make_cached_response
from backend.common.helpers.event_helper import EventHelper
from backend.common.helpers.firebase_pusher import FirebasePusher
from backend.common.helpers.season_helper import SeasonHelper
from backend.common.helpers.team_helper import TeamHelper
from backend.common.models.insight import Insight
from backend.common.sitevars.landing_config import LandingConfig
from backend.web.profiled_render import render_template


@cached_public
def index() -> Response:
    HANDLER_MAP: Dict[
        LandingType, Tuple[Callable[[Dict[str, Any]], str], timedelta]
    ] = {
        # map landing type -> (handler function, cache ttl)
        LandingType.KICKOFF: (index_kickoff, timedelta(minutes=5)),
        LandingType.BUILDSEASON: (index_buildseason, timedelta(minutes=5)),
        LandingType.COMPETITIONSEASON: (
            index_competitionseason,
            timedelta(minutes=5),
        ),
        LandingType.CHAMPS: (index_champs, timedelta(minutes=5)),
        LandingType.OFFSEASON: (index_offseason, timedelta(days=1)),
        LandingType.INSIGHTS: (index_insights, timedelta(minutes=5)),
    }
    landing_type = LandingConfig.current_landing_type()
    landing_type_handler, cache_ttl = HANDLER_MAP[landing_type]
    template_values = cast(Dict[str, Any], LandingConfig.get())
    return make_cached_response(landing_type_handler(template_values), ttl=cache_ttl)


def index_kickoff(template_values: Dict[str, Any]) -> str:
    # special_webcasts = FirebasePusher.get_special_webcasts()
    effective_season_year = SeasonHelper.effective_season_year()
    template_values.update(
        {
            "is_kickoff": SeasonHelper.is_kickoff_at_least_one_day_away(
                year=effective_season_year
            ),
            "kickoff_datetime_est": SeasonHelper.kickoff_datetime_est(
                effective_season_year
            ),
            "kickoff_datetime_utc": SeasonHelper.kickoff_datetime_utc(
                effective_season_year
            ),<commit_msg>Decrease offseason landing TTL [clowntown]<commit_after>from datetime import datetime, timedelta
from typing import Any, Callable, cast, Dict, Tuple

from flask import Response
from google.appengine.ext import ndb

from backend.common.consts.landing_type import LandingType
from backend.common.decorators import cached_public
from backend.common.flask_cache import make_cached_response
from backend.common.helpers.event_helper import EventHelper
from backend.common.helpers.firebase_pusher import FirebasePusher
from backend.common.helpers.season_helper import SeasonHelper
from backend.common.helpers.team_helper import TeamHelper
from backend.common.models.insight import Insight
from backend.common.sitevars.landing_config import LandingConfig
from backend.web.profiled_render import render_template


@cached_public
def index() -> Response:
    HANDLER_MAP: Dict[
        LandingType, Tuple[Callable[[Dict[str, Any]], str], timedelta]
    ] = {
        # map landing type -> (handler function, cache ttl)
        LandingType.KICKOFF: (index_kickoff, timedelta(minutes=5)),
        LandingType.BUILDSEASON: (index_buildseason, timedelta(minutes=5)),
        LandingType.COMPETITIONSEASON: (
            index_competitionseason,
            timedelta(minutes=5),
        ),
        LandingType.CHAMPS: (index_champs, timedelta(minutes=5)),
        LandingType.OFFSEASON: (index_offseason, timedelta(minutes=5)),
        LandingType.INSIGHTS: (index_insights, timedelta(minutes=5)),
    }
    landing_type = LandingConfig.current_landing_type()
    landing_type_handler, cache_ttl = HANDLER_MAP[landing_type]
    template_values = cast(Dict[str, Any], LandingConfig.get())
    return make_cached_response(landing_type_handler(template_values), ttl=cache_ttl)


def index_kickoff(template_values: Dict[str, Any]) -> str:
    # special_webcasts = FirebasePusher.get_special_webcasts()
    effective_season_year = SeasonHelper.effective_season_year()
    template_values.update(
        {
            "is_kickoff": SeasonHelper.is_kickoff_at_least_one_day_away(
                year=effective_season_year
            ),
            "kickoff_datetime_est": SeasonHelper.kickoff_datetime_est(
                effective_season_year
            ),
            "kickoff_datetime_utc": SeasonHelper.kickoff_datetime_utc(
                effective_season_year
            ),
{'fraction_non_alphanumeric': 0.08088548318433376, 'fraction_numerical': 0.002554278416347382, 'mean_word_length': 4.047261009667024, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 9, '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': '2866887', 'n_tokens_mistral': 1438, 'n_tokens_neox': 1386, 'n_words': 260}