code: def generate_team_frame(team, tf, home_team, away_team, window):
      r"""Calculate statistics for each team.
  
      Parameters
      ----------
      team : str
          The abbreviation for the team.
      tf : pandas.DataFrame
          The initial team frame.
      home_team : str
          Label for the home team.
      away_team : str
          Label for the away team.
      window : int
          The value for the rolling window to calculate means and sums.
  
      Returns
      -------
      tf : pandas.DataFrame
          The completed team frame.
  
      """
      # Initialize new features
      tf = add_features(tf, sports_dict, len(tf))
      # Daily Offsets
      tf["days_since_first_game"] = get_day_offset(tf["date"])
      tf["days_since_previous_game"] = get_series_diff(
          tf["days_since_first_game"]
      )
      # Team Loop
      for index, row in tf.iterrows():
          if team == row[home_team]:
              tf["point_margin_game"].at[index] = get_point_margin(
                  row, "home.score", "away.score"
              )
              line = row["line"]
          elif team == row[away_team]:
              tf["point_margin_game"].at[index] = get_point_margin(
                  row, "away.score", "home.score"
              )
              line = -row["line"]
          else:
              raise KeyError("Team not found in Team Frame")
          if index == 0:
              tf["wins"].at[index] = get_wins(
                  tf["point_margin_game"].at[index]
              )
              tf["losses"].at[index] = get_losses(
                  tf["point_margin_game"].at[index]
              )
              tf["ties"].at[index] = get_ties(
                  tf["point_margin_game"].at[index]
              )
          else:
              tf["wins"].at[index] = tf["wins"].at[
                  index - 1
              ] + get_wins(tf["point_margin_game"].at[index])
              tf["losses"].at[index] = tf["losses"].at[
                  index - 1
              ] + get_losses(tf["point_margin_game"].at[index])
              tf["ties"].at[index] = tf["ties"].at[
                  index - 1
              ] + get_ties(tf["point_margin_game"].at[index])
          tf["won_on_points"].at[index] = (
              True if tf["point_margin_game"].at[index] > 0 else False
          )
          tf["lost_on_points"].at[index] = (
              True if tf["point_margin_game"].at[index] < 0 else False
          )
          tf["cover_margin_game"].at[index] = (
              tf["point_margin_game"].at[index] + line
          )
          tf["won_on_spread"].at[index] = (
              True if tf["cover_margin_game"].at[index] > 0 else False
          )
          tf["lost_on_spread"].at[index] = (
              True if tf["cover_margin_game"].at[index] <= 0 else False
          )
          nans = math.isnan(row["home.score"]) or math.isnan(
              row["away.score"]
          )
          if not nans:
              tf["total_points"].at[index] = (
                  row["home.score"] + row["away.score"]
              )
          nans = math.isnan(row["over_under"])
          if not nans:
              tf["overunder_margin"].at[index] = (
                  tf["total_points"].at[index] - row["over_under"]
              )
          tf["over"].at[index] = (
              True if tf["overunder_margin"].at[index] > 0 else False
          )
          tf["under"].at[index] = (
              True if tf["overunder_margin"].at[index] < 0 else False
          )
          tf["point_win_streak"].at[index] = get_streak(
              tf["won_on_points"], index, 0
          )
          tf["point_loss_streak"].at[index] = get_streak(
              tf["lost_on_points"], index, 0
          )
          tf["cover_win_streak"].at[index] = get_streak(
              tf["won_on_spread"], index, 0
          )
          tf["cover_loss_streak"].at[index] = get_streak(
              tf["lost_on_spread"], index, 0
          )
          tf["over_streak"].at[index] = get_streak(tf["over"], index, 0)
          tf["under_streak"].at[index] = get_streak(
              tf["under"], index, 0
          )
          # Handle the streaks
          if tf["point_win_streak"].at[index] > 0:
              streak = tf["point_win_streak"].at[index]
          elif tf["point_loss_streak"].at[index] > 0:
              streak = tf["point_loss_streak"].at[index]
          else:
              streak = 1
          tf["point_margin_streak"].at[index] = tf["point_margin_game"][
              index - streak + 1 : index + 1
          ].sum()
          tf["point_margin_streak_avg"].at[index] = tf[
              "point_margin_game"
          ][index - streak + 1 : index + 1].mean()
          if tf["cover_win_streak"].at[index] > 0:
              streak = tf["cover_win_streak"].at[index]
          elif tf["cover_loss_streak"].at[index] > 0:
              streak = tf["cover_loss_streak"].at[index]
          else:
              streak = 1
          tf["cover_margin_streak"].at[index] = tf["cover_margin_game"][
              index - streak + 1 : index + 1
          ].sum()
          tf["cover_margin_streak_avg"].at[index] = tf[
              "cover_margin_game"
          ][index - streak + 1 : index + 1].mean()
          if tf["over_streak"].at[index] > 0:
              streak = tf["over_streak"].at[index]
          elif tf["under_streak"].at[index] > 0:
              streak = tf["under_streak"].at[index]
          else:
              streak = 1
          tf["overunder_streak"].at[index] = tf["overunder_margin"][
              index - streak + 1 : index + 1
          ].sum()
          tf["overunder_streak_avg"].at[index] = tf["overunder_margin"][
              index - streak + 1 : index + 1
          ].mean()
      # Rolling and Expanding Variables
      tf["point_margin_season"] = tf["point_margin_game"].cumsum()
      tf["point_margin_season_avg"] = (
          tf["point_margin_game"].expanding().mean()
      )
      tf["point_margin_ngames"] = (
          tf["point_margin_game"]
          .rolling(window=window, min_periods=1)
          .sum()
      )
      tf["point_margin_ngames_avg"] = (
          tf["point_margin_game"]
          .rolling(window=window, min_periods=1)
          .mean()
      )
      tf["cover_margin_season"] = tf["cover_margin_game"].cumsum()
      tf["cover_margin_season_avg"] = (
          tf["cover_margin_game"].expanding().mean()
      )
      tf["cover_margin_ngames"] = (
          tf["cover_margin_game"]
          .rolling(window=window, min_periods=1)
          .sum()
      )
      tf["cover_margin_ngames_avg"] = (
          tf["cover_margin_game"]
          .rolling(window=window, min_periods=1)
          .mean()
      )
      tf["overunder_season"] = tf["overunder_margin"].cumsum()
      tf["overunder_season_avg"] = (
          tf["overunder_margin"].expanding().mean()
      )
      tf["overunder_ngames"] = (
          tf["overunder_margin"]
          .rolling(window=window, min_periods=1)
          .sum()
      )
      tf["overunder_ngames_avg"] = (
          tf["overunder_margin"]
          .rolling(window=window, min_periods=1)
          .mean()
      )
      return tf
  
imports: import warnings
  from alphapy.__main__ import main_pipeline
  from alphapy.frame import read_frame
  from alphapy.frame import write_frame
  from alphapy.globals import ModelType
  from alphapy.globals import Partition, datasets
  from alphapy.globals import PSEP, SSEP, USEP
  from alphapy.globals import WILDCARD
  from alphapy.model import get_model_config
  from alphapy.model import Model
  from alphapy.space import Space
  from alphapy.utilities import valid_date
  import argparse
  import datetime
  from itertools import groupby
  import logging
  import math
  import numpy
  import os
  import pandas
  import sys
  import yaml
label_desc: Use image node_id 10 for calling a global function with example usage: generate_team_frame(team, tf, home_team, away_team, window) and returns: tf