> Source URL: /ai-and-sports/projects/3-season-trend-tracker/season-trend-tracker.basketball.project
---
title: Who's Heating Up? Season Trend Tracker (Basketball)
student_outcomes:
  - use lists to store recent game stats
  - use for loops to scan game logs and spot trends
  - calculate simple streaks (current and best)
  - read a simple CSV file and analyze the data
---

# Project: Who's Heating Up? Season Trend Tracker

## Introduction

Scorers get hot. Analysts track recent **points per game** to spot who is trending up.

Today you will build a mini trend tracker that scans recent games and finds hot streaks.

### What we're building

- **Store recent game stats in a list**
- **Loop through the list** to find big games
- **Track streaks** to see how long the hot stretch lasts
- **Load a CSV game log** and analyze real data

---

## Part 1: Quick Start

### Download the Starter Pack

[>button: Download the Starter Pack](./season-trend-tracker-starter-pack.zip)

Open the starter pack in Cursor by going to `File > Open Folder` and selecting the folder you downloaded from your computer.

You should see a file called `trend_tracker.py`. Open it, this is where we will be writing our code.

### Download the Basketball Game Log

[>button: Download Basketball Game Log CSV](./data/basketball/game_log.csv)

Move the downloaded `game_log.csv` into the same folder as `trend_tracker.py`.

### Writing the code

Type the code below into `trend_tracker.py`:

```python
player_name = "Your Player"
recent_stats = [15, 22, 30, 18, 35]

print(f"Trend Tracker for {player_name}")
print("Recent games:", recent_stats)
```

### Running the code

Save the file (<Kbd>Cmd + S</Kbd> or <Kbd>Ctrl + S</Kbd>)

Run the code by clicking the "play" icon in the top right of the screen. Or open the terminal (<Kbd>Cmd + ~</Kbd> or <Kbd>Ctrl + ~</Kbd>) and type `python trend_tracker.py`.

If everything is working correctly, you should see:

```
Trend Tracker for Your Player
Recent games: [15, 22, 30, 18, 35]
```

Great! You just created your first list of game stats.

Here's what you need to know about lists:

- **List** stores multiple items in a single variable (like a shopping list!)
- **Lists** can hold numbers, text, or other data types
- **Items** in a list stay in order and you can change them
- Each item has a position number (called an index), starting at 0 for the first item

---

## Part 2: Project Milestones

### Milestone 1: Print every game in the list

A list is great, but we want to look at each game individually. That is where loops come in.

```python
for stat in recent_stats:
    print(stat)
```

Expected output:

```
15
22
30
18
35
```

Here's what you need to know about **loops**:

- A **loop** lets you go through each item in a list one by one
- The `for` loop repeats the same code for every item
- Think of it like checking each game on your list — you look at game 1, then game 2, then game 3...

---

### Milestone 2: Flag hot games above a threshold

Now we will define what counts as a "hot" game. For points, let us use **25 points**.

The `if` statement lets your program make decisions. Think of it like this: "If the stat is high enough, then print it!" The program checks each game — if it meets your threshold, it prints it. If not, it moves on to the next game.

```python
hot_threshold = 25

for stat in recent_stats:
    if stat >= hot_threshold:
        print(f"Hot game: {stat}")
```

Expected output:

```
Hot game: 30
Hot game: 35
```

---

### Milestone 3: Track the longest hot streak

Let us track **how many hot games in a row** the player had. This is a streak counter.

```python
hot_threshold = 25
current_streak = 0
best_streak = 0

for stat in recent_stats:
    if stat >= hot_threshold:
        current_streak = current_streak + 1
        if current_streak > best_streak:
            best_streak = current_streak
    else:
        current_streak = 0

print(f"Best hot streak: {best_streak}")
```

Expected output:

```
Best hot streak: 1
```

Here's what's happening with `if` and `else`:

- The `if` statement checks: "Is this stat hot enough?" If yes, add 1 to the streak.
- The `else` statement handles what happens when the answer is no: reset the streak to 0.
- Think of it like this: "If the game is hot, keep counting. Otherwise, start over!"

Try changing the list to include multiple hot games in a row and run it again.

---

### Milestone 4: Load stats from a CSV file

Lists are useful, but real data is often stored in files. Use the `game_log.csv` you downloaded earlier.

A CSV (Comma Separated Values) file is a plain text file where each line represents a data record, and fields within each record are separated by commas.

The file looks like this:

```
date,stat
2025-01-03,15
2025-01-05,22
2025-01-08,30
```

Now load it in Python:

```python
import csv

stats_from_file = []

with open("game_log.csv", "r") as file:
    reader = csv.DictReader(file)
    for row in reader:
        stats_from_file.append(int(row["stat"]))

print("Loaded stats:", stats_from_file)
```

Once you can load the stats, replace `recent_stats` with `stats_from_file` and re-run your trend tracker.

---

If you made it this far, you have built a real streak tracker. Nice work.

## Bonus Exercises: Push It Further with Your Agent

Use your AI assistant to explore more ideas with the same building blocks (lists, loops, and files).

### Bonus 1: Add Dates to the Output

Goal: Print both the date and the stat for every game.

Try prompts like:

- "Show me how to store both date and stat in a list and print them together."
- "Update my CSV loader so it prints `date - stat` for each row."

### Bonus 2: Calculate an Average

Goal: Find the average stat value across the games.

Try prompts like:

- "Help me calculate the average of a list of numbers."
- "Print the average and compare it to my hot threshold."

### Bonus 3: Visualize the Trend with ASCII Bars

Goal: Turn each stat into a simple bar chart in the terminal.

Try prompts like:

- "Print a row of `#` characters for each stat value."
- "Make the bars scale so big games look longer."

### Bonus 4: Compare Two Players

Goal: Load two lists of stats and compare who had the longer hot streak.

Try prompts like:

- "Help me load two CSV files and compare their best streaks."
- "Print which player is heating up more."

### Bonus 5: Trend Alerts

Goal: Print a special message when the player is on a hot streak of 3 or more.

Try prompts like:

- "If the best streak is 3 or more, print a trend alert message."


---

## Backlinks

The following sources link to this document:

- [>button: 🏀 Basketball](/ai-and-sports/projects/3-season-trend-tracker/season-trend-tracker.project.llm.md)
