Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,6 @@ python main.py

- Python 3.x
- PostgreSQL (recommended for Month 2)
- Any text editor or IDE (VSCode, PyCharm, etc.)
- VSCode

Happy coding! 🎉
Binary file not shown.
41 changes: 28 additions & 13 deletions month1_student_management/student_data.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
students = []

def add_student():
"""
TODO: Prompt the user to enter student name, age, and grade.
Append the student as a dictionary to the students list.
"""
pass
name = input('Enter student name: ')
age = int(input('Enter student age: '))
grade = float(input('Enter student grade: '))

student = {
'student_name' : name,
'age' : age,
'grade' : grade
}

students.append(student)


# TODO: Prompt the user to enter student name, age, and grade.
# Append the student as a dictionary to the students list.

def view_students():
"""
TODO: Loop through the students list and print each student's info.
"""
pass
print('======Student Profiles=====')
for student in students:
print(f"Student name: {student['name']} \n Age: {student['age']} \n grade: {student['grade']}")


# TODO: Loop through the students list and print each student's info.



def get_average_grade():
"""
TODO: Return the average grade of all students.
"""
pass
total_grade = sum(student['grade'] for student in students)
avg_grade = total_grade/len(students)


# TODO: Return the average grade of all students.
Binary file not shown.
11 changes: 11 additions & 0 deletions month2_minimart_analysis/python/customers.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"customer_id","name","email","join_date"
1,Michael Salazar,woneal@example.net,2023-12-28
2,Rodney Mckinney,lukehernandez@example.org,2024-11-15
3,Stephanie Edwards,tiffanydunn@example.com,2024-03-06
4,David Dunn,lindasmith@example.com,2024-09-20
5,Betty Cook,savageandrea@example.org,2023-12-08
6,Crystal Mccormick,melendeztara@example.org,2023-07-01
7,Joy Garrett,bryan71@example.net,2025-01-18
8,Katie Peters,epeterson@example.com,2025-03-10
9,Michael Freeman,ctyler@example.net,2024-03-22
10,Grace Mendoza,carl61@example.org,2023-12-06
24 changes: 24 additions & 0 deletions month2_minimart_analysis/python/main.py
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
# Entry point for the MiniMart data reporting system
# Entry point for the student management system
from utils import new_order, merge_product, convert_currency
import report_generator as rgt


print(" MiniMart Sales System")

while True:
print("\n1. New_orders \n2. Merge_products \n3. Convert_currency \n4. Report Generator \n5. Exit")
choice = input("Choose an option: ")

if choice == "1":
new_order()
elif choice == "2":
merge_product()
elif choice == "3":
convert_currency()
elif choice == "4":
rgt()
elif choice == "5":
print("Goodbye!")
break
else:
print("Invalid option.")
21 changes: 21 additions & 0 deletions month2_minimart_analysis/python/orders.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"order_id","customer_id","product_id","quantity","order_date"
1,9,1,6,2025-01-07
2,5,5,4,2025-02-01
3,1,2,1,2024-09-06
4,5,2,3,2025-03-07
5,9,3,1,2024-09-08
6,7,5,4,2025-04-16
7,8,4,1,2024-12-11
8,3,5,1,2025-02-22
9,8,4,6,2025-05-26
10,5,3,4,2025-02-28
11,8,4,8,2024-08-16
12,5,5,6,2024-10-13
13,6,3,8,2024-12-18
14,4,5,3,2025-03-12
15,4,1,8,2024-12-11
16,9,5,8,2024-09-12
17,4,2,2,2024-08-01
18,9,4,8,2025-04-24
19,7,5,6,2024-09-10
20,7,4,7,2025-04-10
6 changes: 6 additions & 0 deletions month2_minimart_analysis/python/products.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"product_id","product_name","category","price"
5,Military,Books,197.08
1,TV,Electronics,228.78
2,Lego,Toys,171.9
3,Alchemy ,Books,482.86
4,Business World,Books,336.73
27 changes: 27 additions & 0 deletions month2_minimart_analysis/python/report_generator.py
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
# Code to generate dictionary summary reports
from utils import customers_df, products_df, orders_df
import json

# Total products sold
total_sold = orders_df['quantity'].sum()

# Most popular product
merged = orders_df.merge(products_df, on='product_id')
popular = merged.groupby('product_name')['quantity'].sum().idxmax()

# Revenue per customer
revenue_df = merged.copy()
revenue_df['revenue'] = revenue_df['price'] * revenue_df['quantity']
revenue_per_customer = revenue_df.groupby('customer_id')['revenue'].sum().to_dict()

# Report dictionary
report = {
"total_products_sold": int(total_sold),
"most_popular_product": popular,
"revenue_per_customer": revenue_per_customer
}


# Save to JSON file
with open("sales_report.json", "w") as f:
json.dump(report, f, indent=4)

14 changes: 14 additions & 0 deletions month2_minimart_analysis/python/sales_report.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"total_products_sold": 95,
"most_popular_product": "Military",
"revenue_per_customer": {
"1": 171.9,
"3": 197.08,
"4": 2765.28,
"5": 4417.9400000000005,
"6": 3862.88,
"7": 4327.91,
"8": 5050.950000000001,
"9": 6126.02
}
}
63 changes: 63 additions & 0 deletions month2_minimart_analysis/python/utils.py
Original file line number Diff line number Diff line change
@@ -1 +1,64 @@
# Utility functions for data conversion and filtering
import pandas as pd
import random
from datetime import datetime


# Simulate new orders using lists or dictionaries
# Use conditionals to flag large orders (e.g., total > $100)
# Convert product prices to another currency and apply conditional discounts
# Generate a dictionary report including:
# ✅ Total products sold
# ✅ Most popular product
# ✅ Revenue per customer


customers_df = pd.read_csv("customers.csv")
products_df = pd.read_csv("products.csv")
orders_df = pd.read_csv("orders.csv")

new_orders = [ ]


## Simulate new orders using lists or dictionaries
def new_order():
for _ in range(5):
orders = {
"customer_id": random.choice(customers_df['customer_id']),
"product_id": random.choice(products_df['product_id']),
"quantity": random.randint(1, 5),
"order_date": datetime.now().date()
}
new_orders.append(orders)

# Save to CSV
new_orders_df = pd.DataFrame(new_orders)
new_orders_df[['customer_id', 'product_id', 'quantity', 'order_date']].to_csv(
"orders.csv", mode='a', index=False)


#Convert product prices to another currency
EXCHANGE_RATE = 1500 # e.g., USD to NGN
def convert_currency():
for order in new_orders:
order['total_ngn'] = order['total'] * EXCHANGE_RATE
# Apply 10% discount if order > 200 in USD
for order in new_orders:
if order['total'] > 200:
order['discount_applied'] = True
order['discounted_total'] = order['total'] * 0.9
else:
order['discount_applied'] = False
order['discounted_total'] = order['total']


#Use conditionals to flag large orders (e.g., total > $100)
def merge_product():
for order in new_orders:
product_price = products_df.loc[products_df['product_id'] == order['product_id'], 'price']
order['total'] = order['quantity'] * product_price
order['is_large_order'] = order['total'] > 100




23 changes: 23 additions & 0 deletions month2_minimart_analysis/sql/create_tables.sql
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
-- SQL script to create necessary tables
CREATE TABLE customers
(customer_id SERIAL PRIMARY KEY,
name VARCHAR(125),
email VARCHAR(125),
join_date DATE)

CREATE TABLE products(
product_id SERIAL PRIMARY KEY,
product_name VARCHAR(125),
category VARCHAR(125),
price INT
)

ALTER TABLE products
ALTER COLUMN price FLOAT

CREATE TABLE orders (
order_id SERIAL PRIMARY KEY,
quantity INT,
order_date DATE,
Foreign Key customer_id REFERENCES customers(customer_id),
Foreign Key product_id REFERENCES products(product_id)
)
11 changes: 11 additions & 0 deletions month2_minimart_analysis/sql/customers.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"customer_id","name","email","join_date"
1,Michael Salazar,woneal@example.net,2023-12-28
2,Rodney Mckinney,lukehernandez@example.org,2024-11-15
3,Stephanie Edwards,tiffanydunn@example.com,2024-03-06
4,David Dunn,lindasmith@example.com,2024-09-20
5,Betty Cook,savageandrea@example.org,2023-12-08
6,Crystal Mccormick,melendeztara@example.org,2023-07-01
7,Joy Garrett,bryan71@example.net,2025-01-18
8,Katie Peters,epeterson@example.com,2025-03-10
9,Michael Freeman,ctyler@example.net,2024-03-22
10,Grace Mendoza,carl61@example.org,2023-12-06
70 changes: 70 additions & 0 deletions month2_minimart_analysis/sql/insert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from faker import Faker
import pandas as pd
import random

fake = Faker()


def generate_customers(n=10):
data = []
for i in range(1, n + 1):
name = fake.name()
email = fake.email()
join_date = fake.date_between(start_date='-2y', end_date='today')
data.append({
"customer_id": i,
"name": name,
"email": email,
"join_date": join_date
})
return pd.DataFrame(data)


def generate_products(n=5):
categories = ["Books", "Electronics", "Toys", "Books", "Books"]
data = []
for i in range(1, n + 1):
product_name = fake.word().capitalize()
category = random.choice(categories)
price = round(random.uniform(10, 500), 2)
data.append({
"product_id": i,
"product_name": product_name,
"category": category,
"price": price
})
return pd.DataFrame(data)


def generate_orders(customers_df, products_df, n=20):
data = []
for i in range(1, n + 1):
customer_id = random.choice(customers_df["customer_id"].tolist())
product_id = random.choice(products_df["product_id"].tolist())
quantity = random.randint(1, 10)
order_date = fake.date_between(start_date='-1y', end_date='today')
data.append({
"order_id": i,
"customer_id": customer_id,
"product_id": product_id,
"quantity": quantity,
"order_date": order_date
})
return pd.DataFrame(data)


customers_df = generate_customers(10)
products_df = generate_products(5)
orders_df = generate_orders(customers_df, products_df, 20)


customers_df.dropna(inplace=True)
products_df.dropna(inplace=True)
orders_df.dropna(inplace=True)


customers_df.to_csv("customers.csv", index=False)
products_df.to_csv("products.csv", index=False)
orders_df.to_csv("orders.csv", index=False)

print("✅ All data generated with no NULLs and saved as CSVs.")
2 changes: 2 additions & 0 deletions month2_minimart_analysis/sql/insert_data.sql
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
-- SQL script to insert sample data
---using the faker library, I populated the data table
--kindly find the attached insert.py file
21 changes: 21 additions & 0 deletions month2_minimart_analysis/sql/orders.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"order_id","customer_id","product_id","quantity","order_date"
1,9,1,6,2025-01-07
2,5,5,4,2025-02-01
3,1,2,1,2024-09-06
4,5,2,3,2025-03-07
5,9,3,1,2024-09-08
6,7,5,4,2025-04-16
7,8,4,1,2024-12-11
8,3,5,1,2025-02-22
9,8,4,6,2025-05-26
10,5,3,4,2025-02-28
11,8,4,8,2024-08-16
12,5,5,6,2024-10-13
13,6,3,8,2024-12-18
14,4,5,3,2025-03-12
15,4,1,8,2024-12-11
16,9,5,8,2024-09-12
17,4,2,2,2024-08-01
18,9,4,8,2025-04-24
19,7,5,6,2024-09-10
20,7,4,7,2025-04-10
6 changes: 6 additions & 0 deletions month2_minimart_analysis/sql/products.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"product_id","product_name","category","price"
5,Military,Books,197.08
1,TV,Electronics,228.78
2,Lego,Toys,171.9
3,Alchemy ,Books,482.86
4,Business World,Books,336.73
Loading