diff --git a/README.md b/README.md index 4446309..00eeb38 100644 --- a/README.md +++ b/README.md @@ -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! πŸŽ‰ diff --git a/month1_student_management/__pycache__/student_data.cpython-312.pyc b/month1_student_management/__pycache__/student_data.cpython-312.pyc new file mode 100644 index 0000000..d81a5dd Binary files /dev/null and b/month1_student_management/__pycache__/student_data.cpython-312.pyc differ diff --git a/month1_student_management/student_data.py b/month1_student_management/student_data.py index 38ded7e..806f99d 100644 --- a/month1_student_management/student_data.py +++ b/month1_student_management/student_data.py @@ -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 \ No newline at end of file + total_grade = sum(student['grade'] for student in students) + avg_grade = total_grade/len(students) + + + # TODO: Return the average grade of all students. \ No newline at end of file diff --git a/month2_minimart_analysis/python/__pycache__/utils.cpython-312.pyc b/month2_minimart_analysis/python/__pycache__/utils.cpython-312.pyc new file mode 100644 index 0000000..8398a31 Binary files /dev/null and b/month2_minimart_analysis/python/__pycache__/utils.cpython-312.pyc differ diff --git a/month2_minimart_analysis/python/customers.csv b/month2_minimart_analysis/python/customers.csv new file mode 100644 index 0000000..bd52ed9 --- /dev/null +++ b/month2_minimart_analysis/python/customers.csv @@ -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 diff --git a/month2_minimart_analysis/python/main.py b/month2_minimart_analysis/python/main.py index 583f1c8..cf013b0 100644 --- a/month2_minimart_analysis/python/main.py +++ b/month2_minimart_analysis/python/main.py @@ -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.") \ No newline at end of file diff --git a/month2_minimart_analysis/python/orders.csv b/month2_minimart_analysis/python/orders.csv new file mode 100644 index 0000000..ad51308 --- /dev/null +++ b/month2_minimart_analysis/python/orders.csv @@ -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 diff --git a/month2_minimart_analysis/python/products.csv b/month2_minimart_analysis/python/products.csv new file mode 100644 index 0000000..6274fc2 --- /dev/null +++ b/month2_minimart_analysis/python/products.csv @@ -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 diff --git a/month2_minimart_analysis/python/report_generator.py b/month2_minimart_analysis/python/report_generator.py index fb6ddb8..aa2d996 100644 --- a/month2_minimart_analysis/python/report_generator.py +++ b/month2_minimart_analysis/python/report_generator.py @@ -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) + diff --git a/month2_minimart_analysis/python/sales_report.json b/month2_minimart_analysis/python/sales_report.json new file mode 100644 index 0000000..34ed867 --- /dev/null +++ b/month2_minimart_analysis/python/sales_report.json @@ -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 + } +} \ No newline at end of file diff --git a/month2_minimart_analysis/python/utils.py b/month2_minimart_analysis/python/utils.py index 7049a76..e6bae3c 100644 --- a/month2_minimart_analysis/python/utils.py +++ b/month2_minimart_analysis/python/utils.py @@ -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 + + + + diff --git a/month2_minimart_analysis/sql/create_tables.sql b/month2_minimart_analysis/sql/create_tables.sql index 1411bac..6353c94 100644 --- a/month2_minimart_analysis/sql/create_tables.sql +++ b/month2_minimart_analysis/sql/create_tables.sql @@ -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) +) \ No newline at end of file diff --git a/month2_minimart_analysis/sql/customers.csv b/month2_minimart_analysis/sql/customers.csv new file mode 100644 index 0000000..bd52ed9 --- /dev/null +++ b/month2_minimart_analysis/sql/customers.csv @@ -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 diff --git a/month2_minimart_analysis/sql/insert.py b/month2_minimart_analysis/sql/insert.py new file mode 100644 index 0000000..88d447d --- /dev/null +++ b/month2_minimart_analysis/sql/insert.py @@ -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.") diff --git a/month2_minimart_analysis/sql/insert_data.sql b/month2_minimart_analysis/sql/insert_data.sql index 97dc4da..4489210 100644 --- a/month2_minimart_analysis/sql/insert_data.sql +++ b/month2_minimart_analysis/sql/insert_data.sql @@ -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 \ No newline at end of file diff --git a/month2_minimart_analysis/sql/orders.csv b/month2_minimart_analysis/sql/orders.csv new file mode 100644 index 0000000..ad51308 --- /dev/null +++ b/month2_minimart_analysis/sql/orders.csv @@ -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 diff --git a/month2_minimart_analysis/sql/products.csv b/month2_minimart_analysis/sql/products.csv new file mode 100644 index 0000000..6274fc2 --- /dev/null +++ b/month2_minimart_analysis/sql/products.csv @@ -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 diff --git a/month2_minimart_analysis/sql/queries.sql b/month2_minimart_analysis/sql/queries.sql index 883d8ae..e5a80cd 100644 --- a/month2_minimart_analysis/sql/queries.sql +++ b/month2_minimart_analysis/sql/queries.sql @@ -1 +1,37 @@ --- SQL queries for retrieving insights +-- Use SELECT to retrieve all customers or all products. +SELECT * FROM customers; +SELECT * FROM products; + +-- Use WHERE to filter products by category (e.g., 'Books'). +SELECT * FROM products +WHERE category = 'Books'; + +-- Use ORDER BY to list recent orders by date. +SELECT * FROM orders +ORDER BY order_date DESC; + +-- Use COUNT() to find the number of total orders. +SELECT COUNT(*) FROM orders; + +-- Use SUM() to calculate revenue per product (price Γ— quantity). +SELECT SUM(quantity * price) AS total_revenue +FROM orders +JOIN products ON orders.product_id = products.product_id; + +-- Use AVG() to find the average product price. +SELECT AVG(price) AS average_price FROM products; + +--Use INNER JOIN to get detailed order information (with customer and product details). +SELECT customers.name, products.product_name, orders.quantity +FROM orders +INNER JOIN customers ON orders.customer_id = customers.customer_id +INNER JOIN products ON orders.product_id = products.product_id +ORDER BY customers.name; + +-- Use LEFT JOIN to list all customers and include their orders (if any). +SELECT * FROM customers c +LEFT JOIN orders o ON o.customer_id = c.customer_id; + +--Use LEFT JOIN to show products even if they haven’t been ordered. +SELECT * FROM products p +LEFT JOIN orders o ON o.product_id = p.product_id;