Skip to content

yo#1

Open
Prashely wants to merge 2 commits into
micanipho:mainfrom
Prashely:main
Open

yo#1
Prashely wants to merge 2 commits into
micanipho:mainfrom
Prashely:main

Conversation

@Prashely
Copy link
Copy Markdown

@Prashely Prashely commented Dec 1, 2025

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 for multiple analytics functions and creates a test suite for inventory management. The changes include implementations of list processing functions, dictionary operations, and complex inventory status logic, along with comprehensive unit tests.

  • Implementation of filter_sales_above_threshold, count_product_codes, calculate_moving_average, and partial get_top_seller
  • Implementation of check_inventory_status with complete validation and business logic
  • Creation of test_inventory.py with comprehensive test cases for inventory status checking

Reviewed changes

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

File Description
analytics.py Implements multiple analytics functions including sales filtering, product code counting, moving average calculation, and inventory status checking. Contains several bugs in calculate_moving_average and get_top_seller.
test_inventory.py New test file with comprehensive unit tests for the check_inventory_status function, covering all edge cases and business logic paths.
test.py Simple demonstration file showing sorted iteration over sales data dictionary.
Comments suppressed due to low confidence (1)

test_inventory.py:2

  • Import of 'os' is not used.
import os

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

Comment thread analytics.py Outdated
Comment on lines +66 to +75
if window_size > len(numbers):
avg = sum(numbers) / window_size
return round(avg,2)

elif window_size <= len(numbers):
avg = sum(numbers[window_size - 1: ]) / window_size
return round(avg,2)

else:
return 0.0
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.

When the list has fewer elements than window_size, the function should divide by the number of available elements, not by window_size. According to the docstring logic "If the list has fewer elements than window_size, use all available elements", the average should be calculated as sum(numbers) / len(numbers). Currently dividing by window_size will produce an incorrect average.

Suggested change
if window_size > len(numbers):
avg = sum(numbers) / window_size
return round(avg,2)
elif window_size <= len(numbers):
avg = sum(numbers[window_size - 1: ]) / window_size
return round(avg,2)
else:
return 0.0
if not numbers:
return 0.0
if window_size > len(numbers):
avg = sum(numbers) / len(numbers)
return round(avg, 2)
else:
avg = sum(numbers[-window_size:]) / window_size
return round(avg, 2)

Copilot uses AI. Check for mistakes.
Comment thread analytics.py Outdated
return round(avg,2)

elif window_size <= len(numbers):
avg = sum(numbers[window_size - 1: ]) / window_size
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 slicing logic is incorrect. numbers[window_size - 1:] includes too many elements. To get the LAST window_size elements, use numbers[-window_size:] or numbers[len(numbers) - window_size:]. For example, with [10, 20, 30, 40, 50] and window_size=3, you want [30, 40, 50], but numbers[2:] gives [30, 40, 50] which happens to work, but conceptually the correct slice is numbers[-3:].

Suggested change
avg = sum(numbers[window_size - 1: ]) / window_size
avg = sum(numbers[-window_size:]) / window_size

Copilot uses AI. Check for mistakes.
Comment thread analytics.py Outdated
Comment on lines 97 to 100
for employee in range(len(sales_data)):
highest = sales_data[1]


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 implementation is incomplete and incorrect. This code attempts to iterate over range(len(sales_data)) which produces indices, but then tries to access sales_data[1] (a dictionary) using an integer key. Additionally, the function doesn't return anything. The function should: 1) handle empty dictionary by returning "No Data", 2) iterate through dictionary items to find the maximum value, and 3) handle ties by sorting names alphabetically.

Suggested change
for employee in range(len(sales_data)):
highest = sales_data[1]
if not sales_data:
return "No Data"
max_sales = max(sales_data.values())
top_sellers = [name for name, sales in sales_data.items() if sales == max_sales]
return sorted(top_sellers)[0]

Copilot uses AI. Check for mistakes.
Comment thread analytics.py
Comment on lines +68 to +72
return round(avg,2)

elif window_size <= len(numbers):
avg = sum(numbers[window_size - 1: ]) / window_size
return round(avg,2)
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 space after comma in function call. Should be round(avg, 2) instead of round(avg,2) per PEP 8 style guidelines.

Suggested change
return round(avg,2)
elif window_size <= len(numbers):
avg = sum(numbers[window_size - 1: ]) / window_size
return round(avg,2)
return round(avg, 2)
elif window_size <= len(numbers):
avg = sum(numbers[window_size - 1: ]) / window_size
return round(avg, 2)

Copilot uses AI. Check for mistakes.
Comment thread test_inventory.py
@@ -0,0 +1,44 @@
import unittest
import os
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 os module is imported but never used in this file. Consider removing unused imports to keep the code clean.

Suggested change
import os

Copilot uses AI. Check for mistakes.
Comment thread analytics.py
Comment on lines +68 to +72
return round(avg,2)

elif window_size <= len(numbers):
avg = sum(numbers[window_size - 1: ]) / window_size
return round(avg,2)
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 space after comma in function call. Should be round(avg, 2) instead of round(avg,2) per PEP 8 style guidelines.

Suggested change
return round(avg,2)
elif window_size <= len(numbers):
avg = sum(numbers[window_size - 1: ]) / window_size
return round(avg,2)
return round(avg, 2)
elif window_size <= len(numbers):
avg = sum(numbers[window_size - 1: ]) / window_size
return round(avg, 2)

Copilot uses AI. Check for mistakes.
Comment thread analytics.py Outdated
Comment on lines +66 to +75
if window_size > len(numbers):
avg = sum(numbers) / window_size
return round(avg,2)

elif window_size <= len(numbers):
avg = sum(numbers[window_size - 1: ]) / window_size
return round(avg,2)

else:
return 0.0
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 condition elif window_size <= len(numbers) is redundant because it's always true when line 66's condition is false. The else block on lines 74-75 will never be reached since all possible cases are already covered by lines 66 and 70. Consider simplifying to just else: on line 70.

Suggested change
if window_size > len(numbers):
avg = sum(numbers) / window_size
return round(avg,2)
elif window_size <= len(numbers):
avg = sum(numbers[window_size - 1: ]) / window_size
return round(avg,2)
else:
return 0.0
if not numbers:
return 0.0
if window_size > len(numbers):
avg = sum(numbers) / window_size
return round(avg,2)
else:
avg = sum(numbers[-window_size:]) / window_size
return round(avg,2)

Copilot uses AI. Check for mistakes.
Comment thread analytics.py
counter = 0
prefix_length = len(prefix)
for product in codes:
if product[0 : prefix_length] == prefix:
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 spacing around the slice operator. Per PEP 8, slicing should not have spaces: use product[0:prefix_length] instead of product[0 : prefix_length].

Suggested change
if product[0 : prefix_length] == prefix:
if product[0:prefix_length] == prefix:

Copilot uses AI. Check for mistakes.
Comment thread test.py
sales_data = {"Alice": 5000, "Bob": 7500, "Carol": 6000}

for employee, sale in sorted(sales_data.items()):

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.

Line 4 appears to be an empty line with only whitespace. Consider removing trailing whitespace to maintain clean code.

Suggested change

Copilot uses AI. Check for mistakes.
Comment thread analytics.py Outdated
Comment on lines 97 to 100
for employee in range(len(sales_data)):
highest = sales_data[1]


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.

Variable highest is not used.

Suggested change
for employee in range(len(sales_data)):
highest = sales_data[1]
if not sales_data:
return "No Data"
max_sales = max(sales_data.values())
top_employees = [name for name, sales in sales_data.items() if sales == max_sales]
return sorted(top_employees)[0]

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