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
32 changes: 20 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ Define each table with the following columns:
- `name`
- `email`
- `join_date`

- **`products`**

- `product_id` (Primary Key)
- `product_name`
- `category`
- `price`

- **`orders`**

- `order_id` (Primary Key)
Expand All @@ -70,21 +72,23 @@ Insert at least **5 rows** into each table with realistic sample values.

### 3. Practice the Following SQL Queries

* **Basic Queries**
- **Basic Queries**

- Use `SELECT` to retrieve all customers or all products.
- Use `WHERE` to filter products by category (e.g., `"Drinks"`).
- Use `ORDER BY` to list recent orders by date.

- **Aggregation**

* Use `SELECT` to retrieve all customers or all products.
* Use `WHERE` to filter products by category (e.g., `"Drinks"`).
* Use `ORDER BY` to list recent orders by date.
* **Aggregation**
- Use `COUNT()` to find the number of total orders.
- Use `SUM()` to calculate revenue per product (price × quantity).
- Use `AVG()` to find the average product price.

* Use `COUNT()` to find the number of total orders.
* Use `SUM()` to calculate revenue per product (price × quantity).
* Use `AVG()` to find the average product price.
* **Joins**
- **Joins**

* Use `INNER JOIN` to get detailed order information (with customer and product details).
* Use `LEFT JOIN` to list all customers and include their orders (if any).
* Use `LEFT JOIN` to show products even if they haven’t been ordered.
- Use `INNER JOIN` to get detailed order information (with customer and product details).
- Use `LEFT JOIN` to list all customers and include their orders (if any).
- Use `LEFT JOIN` to show products even if they haven’t been ordered.

#### 🧩 Python Tasks

Expand Down Expand Up @@ -114,6 +118,7 @@ python main.py
git clone https://github.com/SamDewriter/first-semester-projects.git
cd first-semester-projects
```

3. Complete all tasks inside `month1_student_management/` and `month2_minimart_analysis/`.
4. **Commit and Push**:

Expand All @@ -122,6 +127,7 @@ python main.py
git commit -m "Completed Month 1 & 2 projects"
git push origin main
```

5. **Submit your GitHub repo link**.

---
Expand All @@ -133,3 +139,5 @@ python main.py
- Any text editor or IDE (VSCode, PyCharm, etc.)

Happy coding! 🎉

/Users/jakpu/dev/data/alt-schl/first-semester-projects/month2_minimart_analysis/sql/json-report
Binary file not shown.
67 changes: 63 additions & 4 deletions month1_student_management/student_data.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,79 @@
students = []

def print_newline():
"""
Print a newline for better readability.
"""
print("--------------------------------------------------")
print("\n") # Print a newline for spacing
pass

def add_student():
"""
TODO: Prompt the user to enter student name, age, and grade.
Prompt the user to enter student name, age, and grade.
Append the student as a dictionary to the students list.
"""
print_newline()

name = input("Enter student name: ").strip()

if not name:
print(" ⚠️ Name cannot be blank.")
return
try:
age = int(input("Enter student age: ").strip())
if age <= 0:
print(" ⚠️ Age must be a positive integer.")
return
except ValueError:
print(" ⚠️ Invalid age. Please enter a valid integer.")
return

try:
grade = float(input("Enter student grade: ").strip())
if grade < 0 or grade > 100:
print(" ⚠️ Grade must be between 0 and 100.")
return
except ValueError:
print(" ⚠️ Invalid grade. Please enter a valid number.")
return

student = {
'name': name,
'age': age,
'grade': grade
}
students.append(student)
print(f"✅ Student {name} added successfully.\n")
print_newline()
pass

def view_students():
"""
TODO: Loop through the students list and print each student's info.
Loop through the students list and print each student's info.
"""
print_newline()
if not students:
print("📋 No students found.\n")
return

print("📋 List of Students: ")
for idx, student in enumerate(students, start=1):
print(f"{idx}. Name: {student['name']}, Age: {student['age']}, Grade: {student['grade']:.2f}")

print_newline()
pass

def get_average_grade():
"""
TODO: Return the average grade of all students.
Return the average grade of all students.
"""
pass
print_newline()
if not students:
print("📊 No students to calculate average grade.")
return 0.0

total_grade = sum(student['grade'] for student in students)
print_newline()
return total_grade / len(students)

Binary file not shown.
Binary file not shown.
46 changes: 46 additions & 0 deletions month2_minimart_analysis/python/main.py
Original file line number Diff line number Diff line change
@@ -1 +1,47 @@
# Entry point for the MiniMart data reporting system

from report_generator import generate_sales_summary
from utils import convert_currency, apply_discount
from utils import print_newline

# Sample product catalog
products = {
1: {"name": "Laptop", "price": 999.99},
2: {"name": "Headphones", "price": 199.99},
3: {"name": "Notebook", "price": 4.99},
4: {"name": "Mouse", "price": 49.99}
}

# Simulated orders list
orders = [
{"customer": "Alice", "product_id": 1, "quantity": 1},
{"customer": "Bob", "product_id": 2, "quantity": 2},
{"customer": "Alice", "product_id": 3, "quantity": 5},
{"customer": "Diana", "product_id": 4, "quantity": 3},
{"customer": "Ethan", "product_id": 2, "quantity": 1}
]

print_newline()
# Apply conditional flags
for order in orders:
product = products[order['product_id']]
total_cost = product['price'] * order['quantity']
if total_cost > 100:
print(f"⚠️ Large order flagged for {order['customer']}: ${total_cost:.2f}")
print('applying discount of 10%...')

discounted = apply_discount(total_cost)
print(f"Final price after discount: ${discounted:.2f}")
print(f"Price in EUR: €{convert_currency(discounted)}")
print_newline()

# Generate report
report = generate_sales_summary(orders, products)

# Print the report summary
print("\n📊 MiniMart Sales Report")
print("---------------------------")
print(f"Total products sold: {report['total_products_sold']}")
print(f"Most popular product: {report['most_popular_product']}")
print(f"Revenue per customer: {report['revenue_per_customer']}\n")

26 changes: 26 additions & 0 deletions month2_minimart_analysis/python/report_generator.py
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
# Code to generate dictionary summary reports
from collections import defaultdict
from utils import convert_currency, apply_discount

def generate_sales_summary(orders, products):
total_products_sold = 0
product_sales = defaultdict(int)
customer_revenue = defaultdict(float)

for order in orders:
product_id = order['product_id']
quantity = order['quantity']
price = products[product_id]['price']
customer = order['customer']

total_products_sold += quantity
product_sales[product_id] += quantity
customer_revenue[customer] += quantity * price

most_popular_product_id = max(product_sales, key=product_sales.get, default=None)
most_popular_product = products[most_popular_product_id]['name'] if most_popular_product_id else None

return {
'total_products_sold': total_products_sold,
'most_popular_product': most_popular_product,
'revenue_per_customer': dict(customer_revenue)
}
18 changes: 18 additions & 0 deletions month2_minimart_analysis/python/utils.py
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
# Utility functions for data conversion and filtering

def convert_currency(amount_usd, rate=0.85):
"""Convert USD to another currency (e.g., EUR at 0.85 rate)."""
return round(amount_usd * rate, 2)

def apply_discount(price, threshold=100, discount_rate=0.10):
"""Apply discount if price exceeds threshold."""
if price > threshold:
return round(price * (1 - discount_rate), 2)
return price

def print_newline():
"""
Print a newline for better readability.
"""
print("--------------------------------------------------")
print("\n") # Print a newline for spacing
pass
25 changes: 25 additions & 0 deletions month2_minimart_analysis/sql/create_tables.sql
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
-- SQL script to create necessary tables
CREATE TABLE customers (
customer_id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(100) UNIQUE NOT NULL,
join_date DATE DEFAULT CURRENT_DATE
);

CREATE TABLE products (
product_id SERIAL PRIMARY KEY,
product_name VARCHAR(100) NOT NULL,
category VARCHAR(100),
price DECIMAL(10, 2)
);

CREATE TABLE orders (
order_id SERIAL PRIMARY KEY,
customer_id INT,
product_id INT,
quantity INT,
order_date DATE NOT NULL DEFAULT CURRENT_DATE,

FOREIGN KEY (customer_id) REFERENCES customers(customer_id),
FOREIGN KEY (product_id) REFERENCES products(product_id)

);
97 changes: 97 additions & 0 deletions month2_minimart_analysis/sql/insert_data.sql
Original file line number Diff line number Diff line change
@@ -1 +1,98 @@
-- SQL script to insert sample data
INSERT INTO customers (name, email, join_date)
VALUES
('Alice Smith', 'alice.smith@example.com', '2024-02-14'),
('Bob Johnson', 'bob.johnson@example.com', '2024-03-21'),
('Charlie Davis', 'charlie.davis@example.com', '2024-05-10'),
('Diana Garcia', 'diana.garcia@example.com', '2024-06-01'),
('Ethan Brown', 'ethan.brown@example.com', '2024-06-15'),
('Fiona Lee', 'fiona.lee@example.com', '2024-07-09'),
('George Clark', 'george.clark@example.com', '2024-08-23'),
('Hannah Wilson', 'hannah.wilson@example.com', '2024-09-05'),
('Isaac Martinez', 'isaac.martinez@example.com','2024-10-11'),
('Julia Adams', 'julia.adams@example.com', '2024-11-29'),
('Kevin Turner', 'kevin.turner@example.com', '2025-01-03'),
('Laura Perez', 'laura.perez@example.com', '2025-01-17'),
('Michael Scott', 'michael.scott@example.com', '2025-02-01'),
('Natalie King', 'natalie.king@example.com', '2025-02-14'),
('Oliver Young', 'oliver.young@example.com', '2025-03-02');

INSERT INTO products (product_name, category, price)
VALUES
('Laptop Pro 15', 'Electronics', 1299.99),
('Wireless Mouse', 'Electronics', 29.99),
('Office Desk', 'Furniture', 249.99),
('Ergonomic Chair', 'Furniture', 399.99),
('Noise‑Cancelling Headphones','Electronics',199.99),
('Smartphone X', 'Electronics', 999.99),
('Standing Desk Converter', 'Furniture', 159.99),
('4K Monitor 27"', 'Electronics', 449.99),
('Portable SSD 1TB', 'Electronics', 119.99),
('LED Desk Lamp', 'Home', 39.99),
('Bluetooth Speaker', 'Electronics', 79.99),
('Gaming Keyboard', 'Electronics', 89.99),
('Coffee Maker', 'Home', 59.99),
('Water Bottle Stainless', 'Sports', 24.99),
('Yoga Mat', 'Sports', 34.99);

INSERT INTO orders (customer_id, product_id, quantity, order_date)
VALUES
((SELECT customer_id FROM customers WHERE email = 'alice.smith@example.com'),
(SELECT product_id FROM products WHERE product_name = 'Laptop Pro 15'),
1, '2025-03-10'),

((SELECT customer_id FROM customers WHERE email = 'bob.johnson@example.com'),
(SELECT product_id FROM products WHERE product_name = 'Wireless Mouse'),
2, '2025-03-11'),

((SELECT customer_id FROM customers WHERE email = 'charlie.davis@example.com'),
(SELECT product_id FROM products WHERE product_name = 'Ergonomic Chair'),
1, '2025-03-12'),

((SELECT customer_id FROM customers WHERE email = 'diana.garcia@example.com'),
(SELECT product_id FROM products WHERE product_name = '4K Monitor 27"'),
2, '2025-03-13'),

((SELECT customer_id FROM customers WHERE email = 'ethan.brown@example.com'),
(SELECT product_id FROM products WHERE product_name = 'Smartphone X'),
1, '2025-03-13'),

((SELECT customer_id FROM customers WHERE email = 'fiona.lee@example.com'),
(SELECT product_id FROM products WHERE product_name = 'Noise‑Cancelling Headphones'),
1, '2025-03-14'),

((SELECT customer_id FROM customers WHERE email = 'george.clark@example.com'),
(SELECT product_id FROM products WHERE product_name = 'Office Desk'),
1, '2025-03-15'),

((SELECT customer_id FROM customers WHERE email = 'hannah.wilson@example.com'),
(SELECT product_id FROM products WHERE product_name = 'Portable SSD 1TB'),
3, '2025-03-15'),

((SELECT customer_id FROM customers WHERE email = 'isaac.martinez@example.com'),
(SELECT product_id FROM products WHERE product_name = 'Standing Desk Converter'),
1, '2025-03-15'),

((SELECT customer_id FROM customers WHERE email = 'julia.adams@example.com'),
(SELECT product_id FROM products WHERE product_name = 'LED Desk Lamp'),
2, '2025-03-16'),

((SELECT customer_id FROM customers WHERE email = 'kevin.turner@example.com'),
(SELECT product_id FROM products WHERE product_name = 'Bluetooth Speaker'),
1, '2025-03-16'),

((SELECT customer_id FROM customers WHERE email = 'laura.perez@example.com'),
(SELECT product_id FROM products WHERE product_name = 'Gaming Keyboard'),
1, '2025-03-16'),

((SELECT customer_id FROM customers WHERE email = 'michael.scott@example.com'),
(SELECT product_id FROM products WHERE product_name = 'Coffee Maker'),
1, '2025-03-17'),

((SELECT customer_id FROM customers WHERE email = 'natalie.king@example.com'),
(SELECT product_id FROM products WHERE product_name = 'Water Bottle Stainless'),
4, '2025-03-17'),

((SELECT customer_id FROM customers WHERE email = 'oliver.young@example.com'),
(SELECT product_id FROM products WHERE product_name = 'Yoga Mat'),
2, '2025-03-18');
Loading