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
Binary file not shown.
21 changes: 20 additions & 1 deletion month1_student_management/student_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
grades = []
for student in students:
print(student)
grades.append(student["grade"])
grade_average = sum(grades) / len(grades)
return grade_average
Binary file not shown.
Binary file not shown.
71 changes: 71 additions & 0 deletions month2_minimart_analysis/python/main.py
Original file line number Diff line number Diff line change
@@ -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.")
37 changes: 37 additions & 0 deletions month2_minimart_analysis/python/report_generator.py
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions month2_minimart_analysis/python/utils.py
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions month2_minimart_analysis/report/sales_report.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
32 changes: 32 additions & 0 deletions month2_minimart_analysis/sql/create_tables.sql
Original file line number Diff line number Diff line change
@@ -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()
);
32 changes: 32 additions & 0 deletions month2_minimart_analysis/sql/insert_data.sql
Original file line number Diff line number Diff line change
@@ -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', '[email protected]'),
('Charles John', '[email protected]'),
('John Dean', '[email protected]'),
('Jane Robinson', '[email protected]'),
('Joseph Gates', '[email protected]');


-- 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);
66 changes: 66 additions & 0 deletions month2_minimart_analysis/sql/queries.sql
Original file line number Diff line number Diff line change
@@ -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;