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..99ea4a1 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..df16b3b 100644 --- a/month1_student_management/student_data.py +++ b/month1_student_management/student_data.py @@ -5,16 +5,35 @@ def add_student(): TODO: Prompt the user to enter student name, age, and grade. Append the student as a dictionary to the students list. """ + name = input("Enter your name: ") + age = input("Enter your age: ") + grade = input("Enter student's grade: ") + + student_info = { + "name": name, + "age": int(age), + "grade": int(grade) + } + + students.append(student_info) + print(students) pass def view_students(): """ TODO: Loop through the students list and print each student's info. """ + for student in students: + print(student) pass def get_average_grade(): """ TODO: Return the average grade of all students. """ - pass \ No newline at end of file + grades = [] + for student in students: + print(student) + grades.append(student["grade"]) + grade_average = sum(grades) / len(grades) + return grade_average \ No newline at end of file diff --git a/month2_minimart_analysis/python/__pycache__/report_generator.cpython-312.pyc b/month2_minimart_analysis/python/__pycache__/report_generator.cpython-312.pyc new file mode 100644 index 0000000..697a5fa Binary files /dev/null and b/month2_minimart_analysis/python/__pycache__/report_generator.cpython-312.pyc differ 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..a4b3463 Binary files /dev/null and b/month2_minimart_analysis/python/__pycache__/utils.cpython-312.pyc differ diff --git a/month2_minimart_analysis/python/main.py b/month2_minimart_analysis/python/main.py index 583f1c8..ef89c01 100644 --- a/month2_minimart_analysis/python/main.py +++ b/month2_minimart_analysis/python/main.py @@ -1 +1,72 @@ # Entry point for the MiniMart data reporting system +from utils import get_transactions, convert_currency_get_discount +from report_generator import generate_sales_report +import json + +while True: + print("\n1. get transactions\n2. Convert Currency and Apply Discount\n3. Get Report\n4. Exit") + choice = input("Choose an option: ") + + if choice == "1": # get transactions + # define your products + products = { + 1: {"name": "Organic Apples", "price": 3.50}, + 2: {"name": "Whole Wheat Bread", "price": 4.25}, + 3: {"name": "Cheddar Cheese Block", "price": 7.99}, + 4: {"name": "Free-Range Eggs (Dozen)", "price": 5.49}, + 5: {"name": "Natural Peanut Butter", "price": 6.00} + } + + # define your orders + customers_order = [ + {"customer_id": 5, "product_id": 1, "quantity": 30}, + {"customer_id": 2, "product_id": 3, "quantity": 2}, + {"customer_id": 1, "product_id": 5, "quantity": 5}, + {"customer_id": 3, "product_id": 2, "quantity": 10}, + ] + + get_transactions(products, customers_order) + + elif choice == "2": # currency conversion + print("\n--- Applying Currency Conversions and Discounts ---") + print("Enter Amount (USD): \n") + amount = int(input()) + convert_currency_get_discount(amount) + + elif choice == "3": # reporting + # Let's assume this is our full order history from the database + + order_history = [ + {'customer_id': 1, 'product_id': 2, 'quantity': 1}, + {'customer_id': 2, 'product_id': 5, 'quantity': 2}, + {'customer_id': 1, 'product_id': 4, 'quantity': 1}, + {'customer_id': 3, 'product_id': 1, 'quantity': 5}, + {'customer_id': 4, 'product_id': 3, 'quantity': 1} + ] + + products = { + 1: {"name": "Organic Apples", "price": 3.50}, + 2: {"name": "Whole Wheat Bread", "price": 4.25}, + 3: {"name": "Cheddar Cheese Block", "price": 7.99}, + 4: {"name": "Free-Range Eggs (Dozen)", "price": 5.49}, + 5: {"name": "Natural Peanut Butter", "price": 6.00} + } + + # --- Generate and display the report --- + sales_report = generate_sales_report(order_history, products) + + print("\n--- Sales Report (JSON) ---") + print(json.dumps(sales_report, indent=4)) + + # Save the report to a .json file + with open('report/sales_report.json', 'w') as f: + json.dump(sales_report, f, indent=4) + + print("\nReport saved to sales_report.json") + + elif choice == "4": + print("Goodbye!") + break + + else: + print("Invalid Option.") diff --git a/month2_minimart_analysis/python/report_generator.py b/month2_minimart_analysis/python/report_generator.py index fb6ddb8..5cfe7b4 100644 --- a/month2_minimart_analysis/python/report_generator.py +++ b/month2_minimart_analysis/python/report_generator.py @@ -1 +1,38 @@ # Code to generate dictionary summary reports +from collections import Counter + + +def generate_sales_report(orders, products): + # 1. Total products sold + total_products_sold = sum(order['quantity'] for order in orders) + + # 2. Most popular product + product_quantities = Counter() + for order in orders: + product_quantities[order['product_id']] += order['quantity'] + + most_popular_product_id = product_quantities.most_common(1)[0][0] + most_popular_product_name = products[most_popular_product_id]['name'] + + # 3. Revenue per customer + revenue_per_customer = {} + for order in orders: + customer = order['customer_id'] + product_price = products[order['product_id']]['price'] + order_revenue = product_price * order['quantity'] + + revenue_per_customer[customer] = revenue_per_customer.get(customer, 0) + order_revenue + + # Format the revenue to two decimal places + formatted_revenue = {f"Customer_{c}": f"${rev:.2f}" for c, rev in revenue_per_customer.items()} + + # Assemble the final report dictionary + report = { + "sales_summary": { + "total_items_sold": total_products_sold, + "most_popular_product": most_popular_product_name + }, + "customer_revenue": formatted_revenue + } + + return report diff --git a/month2_minimart_analysis/python/utils.py b/month2_minimart_analysis/python/utils.py index 7049a76..e294e6d 100644 --- a/month2_minimart_analysis/python/utils.py +++ b/month2_minimart_analysis/python/utils.py @@ -1 +1,37 @@ # Utility functions for data conversion and filtering + +def get_transactions(products, customers_order): + + for order in customers_order: + # get the product detials: + product = products.get(order["product_id"]) + + if product: + # get total amount of buying that product + expenses = product["price"] * order["quantity"] + + if expenses >= 70: + print( + f"{product["name"]} has a large order of ${expenses:.2f}") + + +def convert_currency_get_discount(price_usd): + exchange_rate_from_usd_ngn = 1700 + discount_threshold = 2000.00 + discount_rate = 0.10 # @10% discount + + price_ngn = price_usd * exchange_rate_from_usd_ngn + + final_price = price_ngn + print(f"\nItem Price (NGN): #{price_ngn:.2f} -> Initial Price (USD): ${price_usd:.2f}") + + + # Applying conditional discount + if price_ngn > discount_threshold: + discount_amount = price_ngn * discount_rate + + final_price = price_ngn - discount_amount + print(f" > Item qualifies for a 10% discount!") + print(f" > Final discounted price: ${final_price:.2f}") + + return final_price diff --git a/month2_minimart_analysis/report/sales_report.json b/month2_minimart_analysis/report/sales_report.json new file mode 100644 index 0000000..27c5565 --- /dev/null +++ b/month2_minimart_analysis/report/sales_report.json @@ -0,0 +1,12 @@ +{ + "sales_summary": { + "total_items_sold": 10, + "most_popular_product": "Organic Apples" + }, + "customer_revenue": { + "Customer_1": "$9.74", + "Customer_2": "$12.00", + "Customer_3": "$17.50", + "Customer_4": "$7.99" + } +} \ No newline at end of file diff --git a/month2_minimart_analysis/sql/create_tables.sql b/month2_minimart_analysis/sql/create_tables.sql index 1411bac..59264bc 100644 --- a/month2_minimart_analysis/sql/create_tables.sql +++ b/month2_minimart_analysis/sql/create_tables.sql @@ -1 +1,33 @@ -- SQL script to create necessary tables + +-- Create Database +CREATE DATABASE mini_mart_db; + +-- Grant Permissions +GRANT ALL PRIVILEGES ON DATABASE mini_mart_db TO dubem_user; + +-- Create customers Table +CREATE TABLE IF NOT EXISTS customers ( + customer_id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY, + name TEXT NOT NULL, + email TEXT NOT NULL UNIQUE, + join_date TIMESTAMPTZ DEFAULT NOW() +); + +-- Create products table +CREATE TABLE IF NOT EXISTS products ( + product_id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY, + product_name TEXT NOT NULL UNIQUE, -- to aviod duplicate names + category TEXT NOT NULL, + price NUMERIC(10, 2) NOT NULL CHECK (price >= 0) +); + + +-- Create orders table +CREATE TABLE IF NOT EXISTS orders ( + order_id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY, + customer_id INTEGER NOT NULL REFERENCES customers(customer_id), + product_id INTEGER NOT NULL REFERENCES products(product_id), + quantity INTEGER NOT NULL CHECK(quantity > 0), + order_date TIMESTAMPTZ DEFAULT NOW() +); \ No newline at end of file diff --git a/month2_minimart_analysis/sql/insert_data.sql b/month2_minimart_analysis/sql/insert_data.sql index 97dc4da..96b3bf1 100644 --- a/month2_minimart_analysis/sql/insert_data.sql +++ b/month2_minimart_analysis/sql/insert_data.sql @@ -1 +1,33 @@ -- SQL script to insert sample data + +-- INSERT data into in customer table +INSERT INTO mini_mart.customers ( + name, + email +) VALUES + ('Chidubem Celestine', 'dubemC@gmail.com'), + ('Charles John', 'charlesJohn@gmail.com'), + ('John Dean', 'johnDean@gmail.com'), + ('Jane Robinson', 'janeRob@gmail.com'), + ('Joseph Gates', 'josephGates@gmail.com'); + + +-- Insert 5 rows into the products table +-- Note: product_id is auto-generated by the database +INSERT INTO mini_mart.products (product_name, category, price) VALUES + ('Organic Apples', 'Groceries', 3.50), + ('Whole Wheat Bread', 'Bakery', 4.25), + ('Cheddar Cheese Block', 'Dairy', 7.99), + ('Free-Range Eggs (Dozen)', 'Dairy', 5.49), + ('Natural Peanut Butter', 'Pantry', 6.00); + + +-- Insert 5 rows into the orders table +-- This connects customers to products. +-- Note: order_id and order_date are auto-generated. +INSERT INTO mini_mart.orders (customer_id, product_id, quantity) VALUES + (1, 2, 1), + (2, 5, 2), + (1, 4, 1), + (3, 1, 5), + (4, 3, 1); \ No newline at end of file diff --git a/month2_minimart_analysis/sql/queries.sql b/month2_minimart_analysis/sql/queries.sql index 883d8ae..ad10cfa 100644 --- a/month2_minimart_analysis/sql/queries.sql +++ b/month2_minimart_analysis/sql/queries.sql @@ -1 +1,67 @@ -- SQL queries for retrieving insights + +-- Get all customers +SELECT * FROM mini_mart.customers; + +-- Get all products +SELECT * FROM mini_mart.products; + +-- Get products under Drinks category +SELECT * from mini_mart.products +WHERE category = 'Drinks'; + +-- Get recent orders by data +SELECT * from mini_mart.orders +ORDER BY order_date DESC; + +-- Find the total orders +SELECT COUNT(order_id) AS total_customer_orders FROM mini_mart.orders; + +-- Calculate the total revenue by customers +SELECT + prod.product_name, + sum(o.quantity * prod.price) AS total_revenue +FROM mini_mart.orders as o +JOIN mini_mart.products AS prod ON o.product_id = prod.product_id +GROUP BY prod.product_name +ORDER BY total_revenue DESC; + +-- Calculate the average product price +SELECT round(avg(price), 2) AS average_product_price FROM mini_mart_db.mini_mart.products; + + +-- get detailed order information (with customer and product details). +SELECT + o.order_id, + c.name as customer_name, + prod.product_name, + prod.price, + o.quantity, + (o.quantity * prod.price) AS Amount_Spent, + o.order_date +FROM mini_mart.orders AS o +JOIN mini_mart.customers AS c ON o.customer_id = c.customer_id +JOIN mini_mart.products as prod ON o.product_id = prod.product_id; + +-- list all customers and include their orders (if any). +-- use the customers table and the orders table. +-- customers name, order_id, product ordered +SELECT + c.customer_id, + c.name as customer_name, + o.order_id, + prod.product_name as item_ordered + FROM mini_mart.customers as c + LEFT JOIN mini_mart.orders as o ON c.customer_id = o.customer_id + LEFT JOIN mini_mart.products as prod ON prod.product_id = o.product_id; + +-- Show all products, even if they haven’t been ordered + +SELECT + p.product_id, + p.product_name, + COUNT(o.order_id) AS times_ordered +FROM mini_mart.products AS p +LEFT JOIN mini_mart.orders AS o ON p.product_id = o.product_id +GROUP BY p.product_id, p.product_name +ORDER BY p.product_id; \ No newline at end of file