From 73151b6250ba15d359bd1838c4be26ac52c21fa0 Mon Sep 17 00:00:00 2001 From: Chidubem Date: Sun, 15 Jun 2025 15:26:32 +0100 Subject: [PATCH 1/2] Completed Month 1 & 2 projects --- .../report_generator.cpython-312.pyc | Bin 0 -> 1689 bytes .../python/__pycache__/utils.cpython-312.pyc | Bin 0 -> 1338 bytes month2_minimart_analysis/python/main.py | 71 ++++++++++++++++++ .../python/report_generator.py | 37 +++++++++ month2_minimart_analysis/python/utils.py | 36 +++++++++ .../report/sales_report.json | 12 +++ .../sql/create_tables.sql | 32 ++++++++ month2_minimart_analysis/sql/insert_data.sql | 32 ++++++++ month2_minimart_analysis/sql/queries.sql | 66 ++++++++++++++++ 9 files changed, 286 insertions(+) create mode 100644 month2_minimart_analysis/python/__pycache__/report_generator.cpython-312.pyc create mode 100644 month2_minimart_analysis/python/__pycache__/utils.cpython-312.pyc create mode 100644 month2_minimart_analysis/report/sales_report.json 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 0000000000000000000000000000000000000000..697a5fa1eaecbbcf5c244c71dcb24e33e2839d1e GIT binary patch literal 1689 zcmZuxUuYaf7@yfccbmIh+O$b?Nqg5sYs{j#vwwmXuF;rlM8!Z6M62y}yE{oX?4NUH z&*s7|1nEN_3IzolXbX9a6d{lCE%+q(a@({d?318^eM^lGHcx)DcNegBV0P#GGxL4l z@Au98lF6hHjMC%jxnUWh-?-2oLTj;i3>J5gfedUR8(+p48Ny9;S*VMu^n^R9I7&{s zHOC`VZ|~xI1*Qmd?;Ffd@Zj4V2EK`WR7MY4@`IKo5IpW5kG3rkx#yK$gaXMIeaR5| z!M-3Y#D9=QE-z*f(nVb;!TMI8gnV%x>Un+`Qah3%^IgqvAp6*F$_cIw5+(|ganv($ zRLMxjdIkJi@#Eb}tnKhS4zhrlLCR0gC!ddukgpi>gBCh|Y7rd#q_4#Jo`Zao^Bw=+ z)5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2_minimart_analysis/python/__pycache__/utils.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a4b34634f631392583649aa716d4748874cab873 GIT binary patch literal 1338 zcmY*Z&rcjx9DlPj!wyT4Wx-vc1s(y!)o!D^LBU2&dmDW z+sbYR-Ge5m_0SV2Y2@Gmu)&asAhatl_{syK^ z%%8(Cd|h;J*8P z0)kL+4Tm%`xNI=H zM@gaje2JeTLXE6diOUFM@HPkwJ1OPMkdn7*pAaW+8QjPbw`9A7P}?o#jS6RG+4Cy- zqD>jkG2#%$3C#iJePVK!cRZJuXLQGQZO5QoH(aAqXEw`M>%8o_`5Lz?>`JvBCZTGb zQ^RG3$!*VNv>%EPACZ|bHBq}CKSK$1S=vzBso~Abk1lW3c2-(rGk>J6Z^ZxXNwqVh zTc5Qu)4Nl@CR(rGXk~6}yw~o_Y|VW8`BC!aLx?_j^hJ=K4yFrxYy0w^8w@V~D@*;$ z(mw-&_ZW^r=8GaY6U!DvKv>ecWX0B@;IB<$oU8wBBZH9*?`QSJfxBfxPtTmh!jX1?CM!{KX|wULJ96nYW`)CK%`6*k ziRjeeL@!d$5q{k*xnZiqtn)G@tn5{+u=mU-@Es>U-Xs0eV-#=2igA3z3+1+<`#)7N2_dgCky1Ty|BvuZTdrvi_^#=n}zsIKzhbMNN z*6{U>zIJ+SC*Mk6+vqvcdV}Qbf%ay!$?dN0O$50@@Y2l#ZLZyuh7+l%WGNeq?m$%9 q&nWUmuX3Wj?ZBU+LJD*Qa6)@byy8= 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 From f18e0aa61be14b2e3e66fb893160ada5a3f7faae Mon Sep 17 00:00:00 2001 From: Chidubem Date: Sun, 15 Jun 2025 15:31:37 +0100 Subject: [PATCH 2/2] Completed Month 1 & 2 projects --- .../__pycache__/student_data.cpython-312.pyc | Bin 0 -> 1564 bytes month1_student_management/student_data.py | 21 +++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 month1_student_management/__pycache__/student_data.cpython-312.pyc 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 0000000000000000000000000000000000000000..99ea4a109effecdaec3144c27a397ffd1c643b98 GIT binary patch literal 1564 zcmZWp&2Jk;6rcTa)*tKGC2i93p)G;7t2Q-=6A?l}q#Q~bBMPcisfrfwWWAAh*P59v z*m9*sRH79@Sn8oYa6p0!;(y>D;F2mJMJpdF@eibNPCfBv?6DVk(!PEBdo%CN{@#1@ zhh>!z$nNlZ`=N%=-~2<0GBw8Mz<7*&bQ^i-KDw=V3TV|+L2EtD(OYr{e;e>XBsBgV z)MLbC6yzztP3?PmRGpzpZml*$)d6BWo{+&TMh=@r@bn+Gdm7W_>fHrt&EJDrWCgLJ z#OHftUIq0Gr_leVWP^Ox+-R=bpO850GMlxrols0{7TY*tU{IELVA+uy;w!f6a}{~E zPh1aQ6#+izb}=A)t6c0-+qJ!*#ez6;NsmX%xvAX=D4T5V*RP2*y*MEv$GY9GDO&X%XEIQOoMfqAr7_W7?}}7-GpUY5V6dh?xI=26(`M%E&+$56HYzh zj1pehtTJ7>9Yi}ZIxc6(Xb^*p(bSdgC|klq57qLUJ; z)c5Oe9F*ToH%6t!{o3mXrPcJq5um3oA5^ZS*NzIPetNWcYWU7~UybTZ!_Oa`d%mDA z71GU<3Noy3n_oAFn}6!(M|yGZ(*5S4ZjK=|YH=ln|25A#ehUNL0ecZmTVO2a3z-pLEBTqY@L65kAO{ zk}b$u@?o<{1$1WJ4e*zeHA?D$oq>nG3JPd5(b6l&NHLZlER0O+f&YE=NQ19ux=E_A z;$J^M8}B{v@Jj)H7p#c@0q21LB}c$)U==h#yL|V5WB}L6S-^5ct?G!)Mt4r(d|c;P zzYO`*fqD}GvG3-H{S>o=M1oTHE+)`UlYy|~9oy}6B$aeRqG)c%m=j6()sSg42{WyO zBN(EBm>f!K++m52?P+An>kVTtA-nElCOz9?9a#qdYw*zPpi*>XqG~PuX!O#{$4E6U zO4o`T7<)+vzfU;RyfG*@pvsDJShiC0Sg$L^;|m3)IIb0y HvtsK%YmRA6 literal 0 HcmV?d00001 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