Transforming and Combining Data · capstone
Capstone project: Project: Normalize, Rank, and Summarize Attempts
This chapter developed several ways to transform and summarize collections. The project now combines them to handle attempt data that arrives as unclean
The program will move that data through a three-stage flow:
Normalize values into one consistent shape.
Rank attempts by score and completion time.
Summarize the normalized collection.
Each stage receives the result of the stage before it and returns a new
Normalize
Raw records contain strings:
{
"learner": " mina ",
"score": "8",
"total": "10",
"seconds": "75",
}
Clean a learner name
You already know that .strip() removes surrounding whitespace:
This prints mina jansen. The original string is unchanged.
Normalize each learner with strip() and convert numeric fields with int().
Rank
Use a
(-attempt["score"], attempt["seconds"])
Higher scores come first. Equal scores are resolved by lower completion time.
Summarize
The summary reports:
count: the number of attempts;points: the sum of scores;lowestandhighest;has_perfect: whether any score equals its total;all_complete: whether every record has a non-negative completion time.
For an empty None, and both False.
Put the operations in a safe order:
Drag the options into order, or use the arrow buttons.
Convert raw strings to normalized values.
Rank the normalized records.
Extract scores and Boolean checks.
Display the returned results.
Calculate the summary.
Keep stages independent
Hidden checks call each
This is the final
Task
Complete the three project
normalize_attempts:
Return new
that strip surrounding whitespace from learner names without changing letter case, and convert numeric fields to integers. Do not modify the raw input.
rank_attempts:
Return a new
sorted by descending score, then ascending seconds.
summarize_attempts:
Return the six documented fields.
Use
sum,min,max,any, andall.Build the score and
collections with readable list comprehensions. Use the list’s truthiness to handle an empty list with the documented values.
The provided program normalizes first, then ranks and summarizes.