From f5e4d822807fd4a8f96f905f6adfdbe4bc5e3d8a Mon Sep 17 00:00:00 2001 From: Ayomide Emmanuel Date: Fri, 13 Jun 2025 16:23:25 +0100 Subject: [PATCH 1/6] first-month-exam-project-submission --- month1_student_management/student_data.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/month1_student_management/student_data.py b/month1_student_management/student_data.py index 38ded7e..50b4847 100644 --- a/month1_student_management/student_data.py +++ b/month1_student_management/student_data.py @@ -1,6 +1,17 @@ students = [] def add_student(): + 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. @@ -8,12 +19,20 @@ def add_student(): pass def view_students(): - """ + print('======Student Profiles=====') + for student in students.items(): + print(f"Student name: {student['name']} \n Age: {student['age']} \n ") + + """ TODO: Loop through the students list and print each student's info. """ pass def get_average_grade(): + + total_grade = sum(student['grade'] for student in students.item()) + avg_grade = total_grade/len(students) + """ TODO: Return the average grade of all students. """ From 1c550360c19bcdc54ee151de2eea236a86b6f4d5 Mon Sep 17 00:00:00 2001 From: Ayomide Emmanuel Date: Fri, 13 Jun 2025 18:49:06 +0100 Subject: [PATCH 2/6] My first month submission --- .../__pycache__/student_data.cpython-312.pyc | Bin 0 -> 1512 bytes month1_student_management/student_data.py | 29 ++++++++---------- 2 files changed, 13 insertions(+), 16 deletions(-) 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..d81a5dd3616be2525db60991e36a28387c8ea189 GIT binary patch literal 1512 zcmZuxO>7%Q6rR~1$MJ8SZYZQ_SP&&yplPdKprn?diHbyV5lPjkY-KIpiQ{y=Yt2lO z#stllIN?`PP4Rd}Ei z>f8affq2vf+4x@1ZXzx+LfIFWqIh&RF&EvQ&6A^ebT*|1YT$-sE1Pmt=CP<|X)v;$ zo{ha~jMk8$7V6rJ%L&yPU$%+Mb=Rtr)B3Yss|-%PKHQ&Mrj`wULk?2C@}ejYWJnLx zFlwlQT5)U3Jdi6c57Y(6vv?5irL!Pr)oR4G4JA-SDOF%pD&9I6h;oEW2l;#H>}m5N zBb1pJXJbZRJ zWHB1HYPm3J6<*tnT(-rn$=X_wv}`-dqZyb$Y>a&Xs)crw2mIW4J2}ys-c6)$5?_0* zoq4^Tc%yZ8H)&_RxuT>SSx?Q4EcY?Ho9`Gj!YWnjF*DtJ} z+g3(9&=B?UNANM^&k`8_&mWAqB~SL8 zp&GjO5)jKO+f9j7Nzq|JRp&y1Hj`?rC_hZtZ``9;2TXVKQOZ?2jcD(#pM%pONLYqEt z1(iZ@=fLO(_eLM6_aH7Lf~kobXy3=U2Y(c=0~}2ZFiM5e-X@@4Ty_ec&a0r_M;I<` zpeukz6F0Dp#5TUd8yL2bge~CjcqPkW`N_R39ctNgpngYxwveyo@6X>IU%zzg()RGt`}2P>fy!su z9ER^$X3N!ZS%K^j7Y0ajk6TW+buehHl)EO|KTqyIL(oxZIVP^vLAB6tIc-bJKbUW8 z`F1YfdV423vUzIr+U+x2*@^3Kg?lO(N_cVjv4up literal 0 HcmV?d00001 diff --git a/month1_student_management/student_data.py b/month1_student_management/student_data.py index 50b4847..0b52871 100644 --- a/month1_student_management/student_data.py +++ b/month1_student_management/student_data.py @@ -12,28 +12,25 @@ def add_student(): } students.append(student) - """ - TODO: Prompt the user to enter student name, age, and grade. - Append the student as a dictionary to the students list. - """ - pass + + # TODO: Prompt the user to enter student name, age, and grade. + # Append the student as a dictionary to the students list. + def view_students(): print('======Student Profiles=====') - for student in students.items(): - print(f"Student name: {student['name']} \n Age: {student['age']} \n ") + 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. + - """ - TODO: Loop through the students list and print each student's info. - """ - pass def get_average_grade(): - total_grade = sum(student['grade'] for student in students.item()) + total_grade = sum(student['grade'] for student in students) avg_grade = total_grade/len(students) - """ - TODO: Return the average grade of all students. - """ - pass \ No newline at end of file + + # TODO: Return the average grade of all students. \ No newline at end of file From 68f807faacb71d188e87518acf31a6f1af6b414e Mon Sep 17 00:00:00 2001 From: Ayomide Emmanuel Date: Sat, 14 Jun 2025 11:29:56 +0100 Subject: [PATCH 3/6] Completed Month 1 & 2 projects --- month2_minimart_analysis/python/customers.csv | 11 +++++ month2_minimart_analysis/python/main.py | 21 +++++++++ month2_minimart_analysis/python/orders.csv | 21 +++++++++ month2_minimart_analysis/python/products.csv | 6 +++ .../python/report_generator.py | 22 ++++++++++ month2_minimart_analysis/python/utils.py | 43 +++++++++++++++++++ 6 files changed, 124 insertions(+) create mode 100644 month2_minimart_analysis/python/customers.csv create mode 100644 month2_minimart_analysis/python/orders.csv create mode 100644 month2_minimart_analysis/python/products.csv 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..1098b9c 100644 --- a/month2_minimart_analysis/python/main.py +++ b/month2_minimart_analysis/python/main.py @@ -1 +1,22 @@ # Entry point for the MiniMart data reporting system +# Entry point for the student management system +from utils import customers_df, products_df, orders_df, new_order, merge_product, convert_currency + + +print(" MiniMart Sales System") + +while True: + print("\n1. New_orders \n2. Merge_products \n3. Convert_currency \n4. Exit") + choice = input("Choose an option: ") + + if choice == "1": + new_order() + elif choice == "2": + merge_product() + elif choice == "3": + convert_currency() + elif choice == "4": + 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..6c71164 100644 --- a/month2_minimart_analysis/python/report_generator.py +++ b/month2_minimart_analysis/python/report_generator.py @@ -1 +1,23 @@ # 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 +} + diff --git a/month2_minimart_analysis/python/utils.py b/month2_minimart_analysis/python/utils.py index 7049a76..ad6c8e8 100644 --- a/month2_minimart_analysis/python/utils.py +++ b/month2_minimart_analysis/python/utils.py @@ -1 +1,44 @@ # Utility functions for data conversion and filtering +import pandas as pd +import random +from datetime import datetime + +customers_df = pd.read_csv("customers.csv") +products_df = pd.read_csv("products.csv") +orders_df = pd.read_csv("orders.csv") + + + +# Sample new orders using dictionaries +new_orders = [] +def new_order(): + for _ in range(5): + order = { + "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(order) + + +# Merge product prices into new_orders +def merge_product(): + for order in new_orders: + product_price = products_df.loc[products_df['product_id'] == order['product_id'], 'price'].values[0] + order['total'] = order['quantity'] * product_price + order['is_large_order'] = order['total'] > 100 + +#Convert product prices to another currency and apply conditional discounts +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 + 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'] + From 9a993df6850d4d828988c2eb75eed9d79e209716 Mon Sep 17 00:00:00 2001 From: Ayomide Emmanuel Date: Sat, 14 Jun 2025 12:57:06 +0100 Subject: [PATCH 4/6] Completed Month 1 & 2 projects --- README.md | 2 +- .../python/__pycache__/utils.cpython-312.pyc | Bin 0 -> 2082 bytes .../python/report_generator.py | 8 ++ .../python/sales_report.json | 14 ++++ .../sql/create_tables.sql | 20 +++++ month2_minimart_analysis/sql/customers.csv | 11 +++ month2_minimart_analysis/sql/insert.py | 70 ++++++++++++++++++ month2_minimart_analysis/sql/insert_data.sql | 2 + month2_minimart_analysis/sql/orders.csv | 21 ++++++ month2_minimart_analysis/sql/products.csv | 6 ++ month2_minimart_analysis/sql/queries.sql | 38 +++++++++- 11 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 month2_minimart_analysis/python/__pycache__/utils.cpython-312.pyc create mode 100644 month2_minimart_analysis/python/sales_report.json create mode 100644 month2_minimart_analysis/sql/customers.csv create mode 100644 month2_minimart_analysis/sql/insert.py create mode 100644 month2_minimart_analysis/sql/orders.csv create mode 100644 month2_minimart_analysis/sql/products.csv 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/month2_minimart_analysis/python/__pycache__/utils.cpython-312.pyc b/month2_minimart_analysis/python/__pycache__/utils.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ff9dc8015be92c9dcb85258e5dea1387f5d425c3 GIT binary patch literal 2082 zcmah~O>EOv9DjD~e8>Gjg*3EKx}hbbDcUBj8Y>{68JpO8U?5dlnC1GJ)QMwZ635*plSwM}KxG!?;tKe7s5wT$3%&iy8!XGV;#85ek7r0oWdc1KdVd=NJe;@V7FB zE?h$B8nS$#P>FkX3eUEJehjmNVEUu~XH*wV9C*nnmpFfJug4thj`eIS;pa+%Z|(H= zI%cVFC+1sz4)b4e*O(h7hpc`-R~qoGo&NJKA`GgdOmKPwl!Tm^54)&hC)xoW>9NiQl+5ISsBoS-~ssIub3{fSKxUvy$Vozw}@ zQdPGIrNjy7#ubO7lQ~gcxgvU0J3*;hRdk$T9Y%C`FGxWf8Tng1b)<0K1U(eaf1Ep8 zm{QELWmF5Yft6XqC>JEn5@k&?&B8^Mm{!(QDvD_-Bnz7;DWIuB#n7#}H^qvos}+e@ zqNGb&-Bis&wQkKBdZA{inmJyrJCW{=ND>yO9GNOK4YZ!#33D>{9lA?7@e2`a~;ray_|kSy&S8Tv|EMN{+3kMwiEy#=abXl*-zv zY%6tmE5i3h7x>Kp5_bP3Ain1jH(+xEx0GMFp>0?UJ*Rm}o2&V6!2r$E0`~)@pLUhr z(H8n|rFXNKp_=^+?h5V8X}C4)MOXc$?rrd9rmd&&YYfzL?l@*1b^;zh30d0HC=QmV zTrWhUH$LE~*22@Cg7_){We~an5`o6yEyI$u4NPr8HAPJ#Ma2^UNN*Rd>!G=TX2?$P zvZU1%GsBYIG?wtS>P~8U(ja@>6ucrZPp5#4LM#P8a~7Hg`n_*&lV4B1vfQ)O)8Xic z^A9KO+>D)`ST?WERBvLDZ$~Iv6j|HbH6giLmHV+^+*L+X2|6 z2?r>^qz`k?K<{OOoq7-YLpc0m1^8a>9ha8KG#P?*oQTVUs2BB(hv1)cda-KCMoou% zQLSpKf{Q=@M87|e@1ztgy2IWBJ}6O6A~$pD{S(utbK=<(=W-dwWyz$k$cV>EuWaa- z6}W72jSxkb>m&n7N{)%4=@8Q%9=$WM^y&SIJ^U^JUADui$Fbg9dlrr@o?46TZ>Pta zxz+wx?fAiVI=fQ5D}2ApPEWeAwfMou>Ff(>KeN^6Q)e{rhxhe8i{Q-!c4e}{|lH}-MIh& literal 0 HcmV?d00001 diff --git a/month2_minimart_analysis/python/report_generator.py b/month2_minimart_analysis/python/report_generator.py index 6c71164..aeb071a 100644 --- a/month2_minimart_analysis/python/report_generator.py +++ b/month2_minimart_analysis/python/report_generator.py @@ -21,3 +21,11 @@ "revenue_per_customer": revenue_per_customer } + +# Save to JSON file +with open("sales_report.json", "w") as f: + json.dump(report, f, indent=4) + +# Print nicely +import pprint +pprint.pprint(report) 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/sql/create_tables.sql b/month2_minimart_analysis/sql/create_tables.sql index 1411bac..db55ca9 100644 --- a/month2_minimart_analysis/sql/create_tables.sql +++ b/month2_minimart_analysis/sql/create_tables.sql @@ -1 +1,21 @@ -- 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 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; From 3e6d526cb9d709ea0633254a325bd646e9126cb5 Mon Sep 17 00:00:00 2001 From: Ayomide Emmanuel Date: Sat, 14 Jun 2025 12:58:56 +0100 Subject: [PATCH 5/6] Completed Month 1 & 2 projects --- month1_student_management/student_data.py | 1 - month2_minimart_analysis/sql/create_tables.sql | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/month1_student_management/student_data.py b/month1_student_management/student_data.py index 0b52871..806f99d 100644 --- a/month1_student_management/student_data.py +++ b/month1_student_management/student_data.py @@ -28,7 +28,6 @@ def view_students(): def get_average_grade(): - total_grade = sum(student['grade'] for student in students) avg_grade = total_grade/len(students) diff --git a/month2_minimart_analysis/sql/create_tables.sql b/month2_minimart_analysis/sql/create_tables.sql index db55ca9..6353c94 100644 --- a/month2_minimart_analysis/sql/create_tables.sql +++ b/month2_minimart_analysis/sql/create_tables.sql @@ -9,9 +9,12 @@ CREATE TABLE products( product_id SERIAL PRIMARY KEY, product_name VARCHAR(125), category VARCHAR(125), - price FLOAT + price INT ) + ALTER TABLE products + ALTER COLUMN price FLOAT + CREATE TABLE orders ( order_id SERIAL PRIMARY KEY, quantity INT, From 99e60a550031e9dfbd2ec57266b24432b69cfc9f Mon Sep 17 00:00:00 2001 From: Ayomide Emmanuel Date: Mon, 16 Jun 2025 16:40:20 +0100 Subject: [PATCH 6/6] fixed report generator file and utils --- .../python/__pycache__/utils.cpython-312.pyc | Bin 2082 -> 2287 bytes month2_minimart_analysis/python/main.py | 7 ++- .../python/report_generator.py | 3 - month2_minimart_analysis/python/utils.py | 54 ++++++++++++------ 4 files changed, 42 insertions(+), 22 deletions(-) diff --git a/month2_minimart_analysis/python/__pycache__/utils.cpython-312.pyc b/month2_minimart_analysis/python/__pycache__/utils.cpython-312.pyc index ff9dc8015be92c9dcb85258e5dea1387f5d425c3..8398a31a1c9e23a3ccbaba94c88c30809cc00c5f 100644 GIT binary patch delta 623 zcmYLFJ#Q015Z$>i?u_qzh6Kll0)YsbqerGdNRbkE0UDZsuuiv2La^_wy|W<*30IH; zp;%iaC8R+i6sc+W0aOl(Vy%RP;0F*4bO^C~k;xRZGjHb2%-c=(d$ID-wsS~WT)VOK z-azP^OhzX1%zpmuRo>iD5P@ZHR6BZ!xebTefasHjX ztsP>3R={_9yAeENGw_vFlrx1VFq#PH#j3_`Dn4wn$I3c{?1Y*^nLStUmR9v&d1Rg3 zH_Lsqym4XAocd8f&MEds9YBulY3IE$v4Xn7akUYL+~@?2Hc5PimRM2u$`i6;Hwj%N z^%jkBJ51@cz)rJS{Q-DvM}G^G?6xrnW9+ptUMY!MBBf5zjOvDQ)FCvjhiytp6t2)q zqBzYy8_lQkpQt4qhoI)GTx-UdaAS!Cm{6|Yk1%=UyWD665e^crv@o?LMU@njine-~ zbZ9|hnF1@Of|=CuJ(|gqKb&1leHqEk+?oy2phklxxx(#;Jgooca3hW7z%4|x%d-2; ztKz73gIuFk!Ir|3m+Zr_nOk3Mx0@T9CY&338dMJ)R2=WxL&XyD1S(FhDeL)Oeq-U2 md$DT|kiF~7^-*mf&G*s#Ky%lUSC@D60~Nt__>BOn+0K9NL77Yd delta 466 zcmXw#Jxc>Y5QcZ|BVM9+MkFSRN=Oq=5GzTef=E!1Scrunc!az4Gr5a%NkA;L6)co3 zM9{{<&(fb^r69^Rg8l#xwX<>e)G3D9_Z=SQ-S>{OWd2Uq6NK04OlkF7CFD&!{!9KF zKF<&H7s?ix2{s5WY_el`RrY;_ux+Wobq8+XcM;g7WP-^aq$8MQ>vA13>_uKm@2R0o zjIJ+(sO?Wm>Rw45&_|`0%`49kXG3bP)X4$Z&RZZ?JUfUr%asQ8O$ob%rq|GO8g|{P z;hIf-iEG&`rX#CLafNatTEHCFdf17&0o_cCT|+OsjTOfPJjYpQr+q1lc@)>TG@5VejwExY~vD&9||<2WyiAp zCK^JEV#GakDEgMOj8V3XaKv>uAetaw5fs?p9NK7=C#cYI9Ojz1%3tIylmXz4Fk36+ e!UQpryNM4;gT9Z90)@~Z9jRUYQ;I_&Lj3^HcX5*d diff --git a/month2_minimart_analysis/python/main.py b/month2_minimart_analysis/python/main.py index 1098b9c..cf013b0 100644 --- a/month2_minimart_analysis/python/main.py +++ b/month2_minimart_analysis/python/main.py @@ -1,12 +1,13 @@ # Entry point for the MiniMart data reporting system # Entry point for the student management system -from utils import customers_df, products_df, orders_df, new_order, merge_product, convert_currency +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. Exit") + print("\n1. New_orders \n2. Merge_products \n3. Convert_currency \n4. Report Generator \n5. Exit") choice = input("Choose an option: ") if choice == "1": @@ -16,6 +17,8 @@ elif choice == "3": convert_currency() elif choice == "4": + rgt() + elif choice == "5": print("Goodbye!") break else: diff --git a/month2_minimart_analysis/python/report_generator.py b/month2_minimart_analysis/python/report_generator.py index aeb071a..aa2d996 100644 --- a/month2_minimart_analysis/python/report_generator.py +++ b/month2_minimart_analysis/python/report_generator.py @@ -26,6 +26,3 @@ with open("sales_report.json", "w") as f: json.dump(report, f, indent=4) -# Print nicely -import pprint -pprint.pprint(report) diff --git a/month2_minimart_analysis/python/utils.py b/month2_minimart_analysis/python/utils.py index ad6c8e8..e6bae3c 100644 --- a/month2_minimart_analysis/python/utils.py +++ b/month2_minimart_analysis/python/utils.py @@ -3,42 +3,62 @@ 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 = [ ] -# Sample new orders using dictionaries -new_orders = [] -def new_order(): +## Simulate new orders using lists or dictionaries +def new_order(): for _ in range(5): - order = { + 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(order) - - -# Merge product prices into new_orders -def merge_product(): - for order in new_orders: - product_price = products_df.loc[products_df['product_id'] == order['product_id'], 'price'].values[0] - order['total'] = order['quantity'] * product_price - order['is_large_order'] = order['total'] > 100 + 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 and apply conditional discounts + +#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 + # 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 + 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 + + + +