PPR BLOG
π AP CSP Component C: Personalized Project Reference
Date: March 12, 2025
π Overview
This submission includes four required code segments demonstrating key programming concepts:
- Student-Developed Procedure: A function implementing **sequencing, selection, and iteration**.
- Function Call: Shows where the student-developed procedure is used in the program.
- List Implementation: A **list (or collection type)** used to store and manage data efficiently.
- List Processing: Using data from the list to fulfill program functionality.
1οΈβ£ Student-Developed Procedure
π Code Segment: Comment Creation Function
@token_required()
def add_comment(user_id, post_id, content):
if not content.strip():
return jsonify({"message": "Comment cannot be empty"}), 400
comment = CarComments(user_id=user_id, post_id=post_id, content=content)
comment.create()
return jsonify(comment.read())
π Explanation
- Sequencing: The function follows a structured order: validating input, creating a comment, saving it, and returning a response.
- Selection: An `if` condition ensures that an empty comment is not submitted.
- Iteration: The `get` function later iterates over all comments for retrieval.
2οΈβ£ Function Call
π Code Segment: Calling the Procedure
@app.route("/api/add_comment", methods=["POST"])
@token_required()
def post_comment():
data = request.get_json()
return add_comment(g.current_user.id, data["post_id"], data["content"])
π Explanation
- This function calls `add_comment()`, passing the current userβs ID, post ID, and comment content.
- It ensures secure authentication with `@token_required()`.
- The API processes user input and interacts with the database.
3οΈβ£ List Implementation
π Code Segment: Storing Data in a List
def get_comments_for_post(post_id):
comments = CarComments.query.filter_by(post_id=post_id).all()
return [comment.read() for comment in comments]
π Explanation
- This function retrieves all comments related to a specific post.
- A list comprehension processes multiple comments efficiently.
4οΈβ£ List Processing
π Code Segment: Processing the List
def format_comments(comments):
formatted = []
for comment in comments:
formatted.append(f"{comment['user_id']} said: {comment['content']}")
return formatted
π Explanation
- A for loop iterates over the comments list.
- Each comment is formatted into a structured text output.
- The function creates a processed list for display.
π Summary of PPR Components
| Component | Purpose |
|---|---|
| Student-Developed Procedure | Validates, creates, and stores user-submitted comments. |
| Function Call | Securely calls the procedure through an API endpoint. |
| List Implementation | Retrieves and stores multiple comments efficiently. |
| List Processing | Uses iteration (for loop) to process and format comment data. |
π Final Thoughts
This submission highlights my ability to design, implement, and process structured data in a web-based comment system.
By using sequencing, selection, iteration, lists, and function calls, I successfully created a functional, interactive, and well-structured program for my AP CSP Create Performance Task.