diff --git a/__pycache__/analytics.cpython-312.pyc b/__pycache__/analytics.cpython-312.pyc new file mode 100644 index 0000000..c8d02f4 Binary files /dev/null and b/__pycache__/analytics.cpython-312.pyc differ diff --git a/analytics.py b/analytics.py index 8acadc8..2024bca 100644 --- a/analytics.py +++ b/analytics.py @@ -17,7 +17,14 @@ def filter_sales_above_threshold(sales: list, threshold: int): - Use a loop or list comprehension """ # TODO: Write your code here - pass + above_treshold = [] + if len(sales) == 0: + return above_treshold + else: + for i in sales: + if i > threshold: + above_treshold.append(i) + return above_treshold def count_product_codes(codes: list, prefix: str): @@ -33,8 +40,11 @@ def count_product_codes(codes: list, prefix: str): - Return 0 if no matches found """ # TODO: Write your code here - pass - + count = 0 + for string in codes: + if prefix in string: + count += 1 + return count def calculate_moving_average(numbers: list, window_size: int): """ @@ -51,7 +61,19 @@ def calculate_moving_average(numbers: list, window_size: int): - Return 0.0 for empty list """ # TODO: Write your code here - pass + count = 0 + if len(numbers) == 0: + return 0.0 + elif len(numbers) >= 3: + for i in range(-window_size, 0): + count += numbers[i] + average = count/window_size + return average + else: + for i in numbers: + count += i + average = count/len(numbers) + return average # ========================================== @@ -72,7 +94,16 @@ def get_top_seller(sales_data: dict): - If there's a tie, return the name that appears first alphabetically """ # TODO: Write your code here - pass + tie = [] + if len(sales_data) == 0: + return f"No Data" + else: + max_sale = max(sales_data.values()) + for name, sale in sales_data.items(): + if sale == max_sale: + tie.append(name) + #name = [name for name in tie] + return sorted(tie)[0] def merge_inventory(warehouse_a: dict, warehouse_b: dict): @@ -93,7 +124,19 @@ def merge_inventory(warehouse_a: dict, warehouse_b: dict): - Do NOT modify the original dictionaries """ # TODO: Write your code here - pass + new_warehouse = {} + if warehouse_a and warehouse_b: + return new_warehouse + else: + for a in warehouse_a: + for b in warehouse_b: + if a == b: + new_warehouse[a] = warehouse_a[a] + warehouse_b[b] + else: + new_warehouse[a] = warehouse_a[a] + new_warehouse[b] = warehouse_b[b] + return new_warehouse + # ========================================== @@ -136,4 +179,18 @@ def check_inventory_status(stock_level: int, reorder_point: int, max_capacity: i - All other cases: return "OPTIMAL" """ # TODO: Write your code here - pass + if stock_level < 0 or reorder_point < 0 or max_capacity < 0 or daily_sales < 0: + return f"Invalid Input" + elif stock_level > max_capacity: + return f"Invalid Input" + elif stock_level > (max_capacity * 0.9): + f"OVERSTOCKED" + elif stock_level < (reorder_point*0.5): + return f"CRITICAL" + elif stock_level <= reorder_point: + return f"REORDER" + elif (daily_sales > 0) and (stock_level < 7 or daily_sales < 7): + return F"LOW STOCK" + else: + return F"OPTIMAL" + diff --git a/test_inventory.py b/test_inventory.py new file mode 100644 index 0000000..e69f81b --- /dev/null +++ b/test_inventory.py @@ -0,0 +1,37 @@ +import unittest +from analytics import check_inventory_status +class TestInventory(unittest.TestCase): + def test_q6_inventory_invalid_input(self): + print("Grading Q6: Inventory Status (Invalid Input)...") + self.assertEqual(check_inventory_status(-10, 50, 100, 10), "Invalid Input") + self.assertEqual(check_inventory_status(50, -10, 100, 10), "Invalid Input") + self.assertEqual(check_inventory_status(50, 50, -100, 10), "Invalid Input") + self.assertEqual(check_inventory_status(50, 50, 100, -10), "Invalid Input") + self.assertEqual(check_inventory_status(150, 50, 100, 10), "Invalid Input") + + def test_q6_inventory_overstocked(self): + print("Grading Q6: Inventory Status (Overstocked)...") + self.assertEqual(check_inventory_status(95, 50, 100, 10), "OVERSTOCKED") + self.assertEqual(check_inventory_status(91, 50, 100, 10), "OVERSTOCKED") + + def test_q6_inventory_critical(self): + print("Grading Q6: Inventory Status (Critical)...") + self.assertEqual(check_inventory_status(20, 50, 100, 10), "CRITICAL") + self.assertEqual(check_inventory_status(10, 100, 200, 5), "CRITICAL") + + def test_q6_inventory_reorder(self): + print("Grading Q6: Inventory Status (Reorder)...") + self.assertEqual(check_inventory_status(50, 50, 100, 5), "REORDER") + self.assertEqual(check_inventory_status(45, 50, 100, 5), "REORDER") + + def test_q6_inventory_low_stock(self): + print("Grading Q6: Inventory Status (Low Stock)...") + self.assertEqual(check_inventory_status(60, 50, 100, 10), "LOW STOCK") + self.assertEqual(check_inventory_status(69, 50, 100, 10), "LOW STOCK") + + def test_q6_inventory_optimal(self): + print("Grading Q6: Inventory Status (Optimal)...") + self.assertEqual(check_inventory_status(70, 50, 100, 10), "OPTIMAL") + self.assertEqual(check_inventory_status(80, 50, 100, 5), "OPTIMAL") + # Zero daily sales should not trigger low stock + self.assertEqual(check_inventory_status(60, 50, 100, 0), "OPTIMAL") \ No newline at end of file