Skip to content

Ntsika Gajula#4

Open
DyanCoded wants to merge 1 commit into
micanipho:mainfrom
DyanCoded:main
Open

Ntsika Gajula#4
DyanCoded wants to merge 1 commit into
micanipho:mainfrom
DyanCoded:main

Conversation

@DyanCoded
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements solutions to 6 programming questions in analytics.py covering list processing, dictionary operations, and inventory management logic, along with a test suite in test_inventory.py for the inventory status function.

Key Changes:

  • Implemented 5 core functions: filter_sales_above_threshold, count_product_codes, calculate_moving_average, get_top_seller, and merge_inventory
  • Implemented check_inventory_status function with multi-condition logic tree for inventory analysis
  • Created comprehensive unit tests for the inventory status function in test_inventory.py

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 9 comments.

File Description
analytics.py Implemented 6 functions for data analytics including sales filtering, product code counting, moving averages, top seller identification, inventory merging, and inventory status checking
test_inventory.py Added unit test suite with 6 test methods covering various scenarios for check_inventory_status function
pycache/analytics.cpython-313.pyc Python bytecode cache file generated from analytics.py compilation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread analytics.py
Comment on lines +116 to +121
for product, quantity in warehouse_a:
if product in merged_inventory:
merged_inventory[product] += quantity
else:
merged_inventory[product] = quantity
for product, quantity in warehouse_b:
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line iterates over dictionary keys only, not key-value pairs. When iterating with for product, quantity in warehouse_a:, Python only yields keys, causing a ValueError: too many values to unpack. Use for product, quantity in warehouse_a.items(): to correctly iterate over key-value pairs.

Suggested change
for product, quantity in warehouse_a:
if product in merged_inventory:
merged_inventory[product] += quantity
else:
merged_inventory[product] = quantity
for product, quantity in warehouse_b:
for product, quantity in warehouse_a.items():
if product in merged_inventory:
merged_inventory[product] += quantity
else:
merged_inventory[product] = quantity
for product, quantity in warehouse_b.items():

Copilot uses AI. Check for mistakes.
Comment thread analytics.py
merged_inventory[product] += quantity
else:
merged_inventory[product] = quantity
for product, quantity in warehouse_b:
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line iterates over dictionary keys only, not key-value pairs. When iterating with for product, quantity in warehouse_b:, Python only yields keys, causing a ValueError: too many values to unpack. Use for product, quantity in warehouse_b.items(): to correctly iterate over key-value pairs.

Suggested change
for product, quantity in warehouse_b:
for product, quantity in warehouse_b.items():

Copilot uses AI. Check for mistakes.
Comment thread analytics.py
Comment on lines +6 to 26
"""
QUESTION 1
----------------------------------------
Given a list of sales amounts (integers), return a NEW list containing
only values above the threshold.

Example: filter_sales_above_threshold([100, 250, 75, 300], 150) → [250, 300]

Example: filter_sales_above_threshold([100, 250, 75, 300], 150) → [250, 300]

Logic:
- Do NOT modify the original list
- Return empty list if no values qualify
- Use a loop or list comprehension
"""
# TODO: Write your code here
pass
Logic:
- Do NOT modify the original list
- Return empty list if no values qualify
- Use a loop or list comprehension
"""
# TODO: Write your code here
for sale in sales:
if sale < threshold:
sales.remove(sale)
return sales


def count_product_codes(codes: list, prefix: str):
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation: The code uses 3 spaces for indentation in some places and 4 spaces in others. Python code should consistently use 4 spaces per indentation level according to PEP 8. Update all indentation to use 4 spaces consistently throughout the file.

Copilot uses AI. Check for mistakes.
Comment thread analytics.py
# TODO: Write your code here
count = 0
for code in codes:
if prefix in code:
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This uses substring matching (prefix in code) instead of checking if the code starts with the prefix. This will incorrectly match codes where the prefix appears anywhere in the string. Use code.startswith(prefix) instead to match only codes that START with the prefix as specified in the requirements.

Suggested change
if prefix in code:
if code.startswith(prefix):

Copilot uses AI. Check for mistakes.
Comment thread analytics.py
"""
# TODO: Write your code here
if stock_level < 0 or reorder_point < 0 or max_capacity < 0 or daily_sales < 0:
return "Invalid Input"
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing validation for stock_level > max_capacity as specified in the docstring logic tree. According to the requirements, this condition should return "Invalid Input". Add this check: if stock_level > max_capacity: return "Invalid Input" after the existing negative value check.

Suggested change
return "Invalid Input"
return "Invalid Input"
if stock_level > max_capacity:
return "Invalid Input"

Copilot uses AI. Check for mistakes.
Comment thread test_inventory.py
Comment on lines +6 to +10
def test_input_validity(self):
self.assertEqual(check_inventory_status(-5, 50, 100, 10), "Invalid Input")
self.assertEqual(check_inventory_status(55, -50, 100, 10), "Invalid Input")
self.assertEqual(check_inventory_status(55, 50, -100, 10), "Invalid Input")
self.assertEqual(check_inventory_status(55, 50, 100, -10), "Invalid Input")
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test case for the validation rule "If stock_level > max_capacity: return 'Invalid Input'". Add a test case such as: self.assertEqual(check_inventory_status(150, 50, 100, 10), "Invalid Input") to ensure this validation condition is covered.

Copilot uses AI. Check for mistakes.
Comment thread analytics.py
Comment on lines +20 to +23
for sale in sales:
if sale < threshold:
sales.remove(sale)
return sales
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation modifies the original list, which violates the requirement in the docstring: "Do NOT modify the original list". Using sales.remove(sale) modifies the input list and also causes incorrect behavior because modifying a list while iterating over it leads to skipped elements. Use list comprehension instead: return [sale for sale in sales if sale > threshold]

Suggested change
for sale in sales:
if sale < threshold:
sales.remove(sale)
return sales
return [sale for sale in sales if sale > threshold]

Copilot uses AI. Check for mistakes.
Comment thread analytics.py
if not sales_data:
return "No Data"
highest_sales = 0
for name, sales in sales_data:
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line iterates over dictionary keys only, not key-value pairs. When iterating over a dictionary directly with for name, sales in sales_data:, Python only yields keys, causing a ValueError: too many values to unpack. Use for name, sales in sales_data.items(): to correctly iterate over key-value pairs.

Copilot uses AI. Check for mistakes.
Comment thread analytics.py
Comment on lines +89 to +93
highest_sales = 0
for name, sales in sales_data:
if sales > highest_sales:
highest_sales = sales
top_seller = name
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function can return without top_seller being defined. If sales_data contains only items with sales values of 0 or negative, top_seller will never be assigned. Additionally, the logic doesn't handle ties alphabetically as specified in the docstring. Initialize top_seller = None before the loop and handle the tie-breaking requirement properly.

Suggested change
highest_sales = 0
for name, sales in sales_data:
if sales > highest_sales:
highest_sales = sales
top_seller = name
highest_sales = float('-inf')
top_seller = None
for name, sales in sales_data.items():
if sales > highest_sales:
highest_sales = sales
top_seller = name
elif sales == highest_sales:
if top_seller is None or name < top_seller:
top_seller = name

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants