Open lesson

Mission: the worker that never finishes

Command palette

This mission workspace keeps code and notes in this browser tab. Export them before closing it. Running code is practice, not an automatic grade for the mission.

Brief

Diagnose an overloaded partition and choose a suitable redistribution without assuming it removes every imbalance.

The trip map fills up. Three workers finish quickly; a fourth still handles D7 passages. Voss wants to delete 'repeated' trips to accelerate the job, which could erase the lead. Mara asks for a diagnosis without touching originals. The meeting presses the characters, but the exercise has no timer.

Your mission

  1. Calculate total rows and the ratio between maximum and median loads.
  2. Explain what a shuffle does when grouping by depot.
  3. Say whether repartitioning by trip_id guarantees that D7 is fixed.
  4. State the counts that any optimized output must retain.

How to check your work

  • 18 trips; ratio 6.
  • Shuffle gathers rows sharing a key.
  • No: independent per-trip work may balance, then groupBy gathers D7.
  • D7=12, D8=D9=D10=2, total 18.

Course example

from collections import Counter
from statistics import median

depot_counts = Counter({"D7": 12, "D8": 2, "D9": 2, "D10": 2})
loads_by_depot = sorted(depot_counts.values())
balanced_row_tasks = [5, 5, 4, 4]

print("rows", sum(loads_by_depot))
print("depot_loads", loads_by_depot)
print("largest_to_median", max(loads_by_depot) / median(loads_by_depot))
print("hypothetical_row_tasks", balanced_row_tasks)
print("same_rows", sum(balanced_row_tasks) == sum(loads_by_depot))

Code

Use Tab to leave the editor. Ctrl+Enter runs the source. The lines beginning with # are task reminders. Python ignores them. Write your code beneath them.

Python console

Loading laboratory…

Explore Python or SQL here; this is not an operating-system shell.

This is a disposable browser experiment. The code run here is not recorded as a completed mission.

Each command starts a fresh disposable worker: it runs a captured copy of your current source, then your command with the lesson fixtures. Changes are discarded afterward. Commands never save source or award XP. Ctrl+Enter executes the command.

Virtual workspace files

Source and declarative assets are readable here without JavaScript. Python input files are created at runtime; SQL setup initializes the disposable database.

source.py

Current editor source. Inspection shows your current edits.

# Calculate total rows and the ratio between maximum and median loads.
# Explain what a shuffle does when grouping by depot.
# Say whether repartitioning by trip_id guarantees that D7 is fixed.
# State the counts that any optimized output must retain.

exemple.py

Declarative lesson asset; this is not a file created in the Python filesystem.

from collections import Counter
from statistics import median

depot_counts = Counter({"D7": 12, "D8": 2, "D9": 2, "D10": 2})
loads_by_depot = sorted(depot_counts.values())
balanced_row_tasks = [5, 5, 4, 4]

print("rows", sum(loads_by_depot))
print("depot_loads", loads_by_depot)
print("largest_to_median", max(loads_by_depot) / median(loads_by_depot))
print("hypothetical_row_tasks", balanced_row_tasks)
print("same_rows", sum(balanced_row_tasks) == sum(loads_by_depot))