CPT Requirements
Requirement | Input from User | Use of at least 1 list (or other collection type) | Procedure | Algorithm with sequencing, selection, and iteration | Call to procedure | Instructions for output |
---|---|---|---|---|---|---|
Coolfacts feature | Y | Y | Y | Y | Y | Y |
Input from user
<input type="text" id="new-fact-text" placeholder="Enter cool fact" />
<button id="add-fact-btn">Add Cool Fact</button>
async function addCoolFact() {
const age = document.getElementById('new-fact-age').value;
const coolfacts = document.getElementById('new-fact-text').value;
try {
const response = await fetch(`${pythonURI}/api/coolfacts`, {
...fetchOptions,
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ age, coolfacts })
});
if (!response.ok) {
throw new Error('Failed to add cool fact: ' + response.statusText);
}
alert('Cool fact added successfully!');
document.getElementById('new-fact-age').value = ''; // Clear input
document.getElementById('new-fact-text').value = ''; // Clear input
fetchCoolFacts(); // Refresh cool facts list
} catch (error) {
console.error('Error adding cool fact:', error);
alert('Error adding cool fact: ' + error.message);
}
}
Use of at least 1 list or other collection type
def initCoolFacts():
"""
Initializes the QuizCreation table and inserts test data for development purposes.
"""
with app.app_context():
db.create_all() # Create the database and tables
# Sample test data
quizzes = [
CoolFacts(coolfacts="Elon Musk saved Tesla from bankruptcy", age="37"),
CoolFacts(coolfacts="Messi moved to Barcelona, Spain to play soccer and recieve proper medical treatment", age="13"),
CoolFacts(coolfacts="Lebron James was scouted by the Cleveland Cavaliers and played his first NBA game there", age="18")
]
for quiz in quizzes:
try:
quiz.create()
print(f"Created quiz: {repr(quiz)}")
except IntegrityError as e:
db.session.rollback()
print(f"Record already exists or error occurred: {str(e)}")
Procedure
@staticmethod
def restore(data):
with app.app_context():
db.session.query(CoolFacts).delete()
db.session.commit()
restored_facts = {}
for fact_data in data:
fact = CoolFacts(
coolfacts=fact_data['coolfacts'],
age=fact_data['age']
)
fact.create()
restored_facts[fact_data['id']] = fact
return restored_facts
Algorithm with sequencing, selection, and iteration
def restore(data):
with app.app_context():
db.session.query(CoolFacts).delete()
db.session.commit()
restored_facts = {}
for fact_data in data:
fact = CoolFacts(
coolfacts=fact_data['coolfacts'],
age=fact_data['age']
)
fact.create()
restored_facts[fact_data['id']] = fact
return restored_facts
Call to procedure
def restore_data(data):
with app.app_context():
users = User.restore(data['users'])
_ = CoolFacts.restore(data['coolfacts'])
_ = Section.restore(data['sections'])
_ = Group.restore(data['groups'], users)
_ = Channel.restore(data['channels'])
# _ = Post.restore(data['posts'])
_ = Hobby.restore(data['hobbies'])
_ = Steps.restore(data['steps'])
_ = Quote.restore(data['quotes'])
_ = BucketList.restore(data['bucketlists'])
_ = StriverGoals.restore(data['strivergoals'])
print("Data restored to the new database.")
Instruction for output
const updateButton = document.createElement('button');
updateButton.textContent = 'Update';
updateButton.style.marginLeft = '10px';
updateButton.style.padding = '2px 5px';
updateButton.onclick = () => promptUpdateCoolFact(fact.id, fact.age, fact.coolfacts);
const data = await response.json();
const coolFactsList = document.getElementById('coolfacts-list');
coolFactsList.innerHTML = "";
data.forEach(fact => {
const listItem = document.createElement('li');
listItem.style.display = 'flex';
listItem.style.alignItems = 'center';
listItem.style.justifyContent = 'space-between';
const factText = document.createElement('span');
factText.textContent = `${fact.age}: ${fact.coolfacts}`;
const updateButton = document.createElement('button');
updateButton.textContent = 'Update';
updateButton.style.marginLeft = '10px';
updateButton.style.padding = '2px 5px';
updateButton.onclick = () => promptUpdateCoolFact(fact.id, fact.age, fact.coolfacts);
const deleteButton = document.createElement('button');
deleteButton.textContent = 'Delete';
deleteButton.style.marginLeft = '10px';
deleteButton.style.padding = '2px 5px';
deleteButton.onclick = () => deleteCoolFact(fact.id);
listItem.appendChild(factText);
listItem.appendChild(updateButton);
listItem.appendChild(deleteButton);
coolFactsList.appendChild(listItem);
try {
const response = await fetch(`${pythonURI}/api/coolfacts`, {
...fetchOptions,
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ age, coolfacts })
});
if (!response.ok) {
throw new Error('Failed to add cool fact: ' + response.statusText);
}
PPR Requirements
- First Code segment
- It defines the procedures name as restore
- It has a parameter, data, that affects to purpose of the function
- It has sequencing, selection, and iteration
@staticmethod
def restore(data):
with app.app_context():
db.session.query(CoolFacts).delete()
db.session.commit()
restored_facts = {}
for fact_data in data:
fact = CoolFacts(
coolfacts=fact_data['coolfacts'],
age=fact_data['age']
)
fact.create()
restored_facts[fact_data['id']] = fact
return restored_facts
- Second code segment
- The above function is being called in another function below
def restore_data(data):
with app.app_context():
users = User.restore(data['users'])
_ = CoolFacts.restore(data['coolfacts'])
_ = Section.restore(data['sections'])
_ = Group.restore(data['groups'], users)
_ = Channel.restore(data['channels'])
# _ = Post.restore(data['posts'])
_ = Hobby.restore(data['hobbies'])
_ = Steps.restore(data['steps'])
_ = Quote.restore(data['quotes'])
_ = BucketList.restore(data['bucketlists'])
_ = StriverGoals.restore(data['strivergoals'])
print("Data restored to the new database.")
- Third code segment
- Static data to be stored in the database is created as a list
def initCoolFacts():
"""
Initializes the QuizCreation table and inserts test data for development purposes.
"""
with app.app_context():
db.create_all() # Create the database and tables
# Sample test data
quizzes = [
CoolFacts(coolfacts="Elon Musk saved Tesla from bankruptcy", age="37"),
CoolFacts(coolfacts="Messi moved to Barcelona, Spain to play soccer and recieve proper medical treatment", age="13"),
CoolFacts(coolfacts="Lebron James was scouted by the Cleveland Cavaliers and played his first NBA game there", age="18")
]
for quiz in quizzes:
try:
quiz.create()
print(f"Created quiz: {repr(quiz)}")
except IntegrityError as e:
db.session.rollback()
print(f"Record already exists or error occurred: {str(e)}")
- Fourth code segment
- A function is made where the list data above is added to a function and that data will later be added into the database
def generate_data():
initGoals()
initCoolFacts()
initBucketlists()
initSteps()
initHobbies()
init_quotes()
initUsers()
initSections()
initGroups()
# initChannels()
initPosts()
CPT Requirements
Big Idea 1.1 & 1.2 Collaboration, Program Function, and Purpose:
Iteration, SCRUM, Agile, Issues, Kanban – Applied agile methodologies to efficiently manage project tasks and track progress. Utilized Kanban boards to organize issues and iterations, creating burndown lists to monitor completion.
Big Idea 1.3 Program Design and Development: Frontend and Backend Integration – Focused on creating a user-friendly and visually engaging frontend to enhance the overall user experience.
Big Idea 1.3 Program Design and Development: Design Documentation – Used diagramming tools such as draw.io to create flowcharts and UML diagrams, ensuring clear and structured design documentation.
Big Idea 1.4 Debugging Code and Fixing Errors: Backend Debugging & Testing – Conducted thorough backend testing using Postman to verify the functionality and stability of implemented features.
Big Idea 2 Data: Database Management with SQLite – Designed and managed SQLite databases to store essential user data, including posts and images. Developed efficient schemas to optimize data handling for social media functionality.
Data Backup and Recovery – Implemented backup strategies to safeguard data and established recovery procedures to restore lost or corrupted information.
Big Idea 4 Internet: Authentication and Security – Integrated authentication mechanisms such as JWT to enhance application security and protect user data.
HTTP and RESTful APIs – Developed RESTful APIs using HTTP methods (GET, POST, PUT, DELETE) to facilitate seamless communication between the frontend and backend.