-
Notifications
You must be signed in to change notification settings - Fork 740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solution #685
base: master
Are you sure you want to change the base?
Solution #685
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your hard work on this project! While your code is mostly well-implemented and meets many of the task requirements, there are a few critical issues that need to be addressed before we can approve the pull request:
-
Shop
Class Initialization: Theproducts
parameter should be a dictionary, not a string. This is crucial for the functionality of theShop
class, as it affects how product prices are accessed and calculated. -
shop_trip
Function: The calculation ofdistance_to_home
is incorrect. It currently calculates the distance from the customer's location to itself, which will always be zero. This needs to be corrected to calculate the distance from the shop back to the customer's original location. -
String Formatting: There is a syntax error in the
print
statement due to incorrect usage of double quotes inside an f-string. Please use single quotes around the format string or escape the double quotes to fix this issue. -
Customer
Class: Thenew_location
parameter is expected to be a list, but it is being treated as a string. Ensure thatnew_location
is a list with the correct format to avoid potential errors.
Once these issues are resolved, your code will be in great shape! Keep up the great work, and don't hesitate to reach out if you have any questions or need further clarification. 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review
button in the Reviewers tab.
app/customer.py
Outdated
new_location: str) -> None: | ||
self.money -= total_cost | ||
self.location = new_location |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new_location
parameter is expected to be a list (similar to self.location
), but it is being treated as a string. Ensure that new_location
is a list with the correct format.
app/customer.py
Outdated
shop_name: str, | ||
purchased_products: dict, | ||
total_cost: float) -> None: | ||
print(f"\nDate: {datetime.now().strftime("%d/%m/%Y %H:%M:%S")}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a syntax error in the print
statement due to incorrect usage of double quotes inside an f-string. Use single quotes around the format string or escape the double quotes.
app/main.py
Outdated
|
||
for shop in shop_objects: | ||
distance_to_shop = customer.calculate_distance(shop.location) | ||
distance_to_home = customer.calculate_distance(customer.location) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The calculation of distance_to_home
is incorrect. It currently calculates the distance from the customer's location to itself, which will always be zero. You should calculate the distance from the shop back to the customer's original location.
app/main.py
Outdated
total_trip_cost \ | ||
= fuel_cost_to_shop + product_cost + fuel_cost_to_home |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The line continuation character \
is unnecessary here because the expression is already within parentheses. You can safely remove it.
app/shop.py
Outdated
@@ -0,0 +1,15 @@ | |||
class Shop: | |||
def __init__(self, name: str, location: str, products: str) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The products
parameter should be a dictionary, not a string. Update the type hint and ensure that the products
parameter is passed as a dictionary when creating a Shop
instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job on addressing the previous issues! 🎉 Your code now meets the task requirements and constraints. Here are some important points to consider for future improvements:
-
Customer
Class andmake_customer_list
Function: Ensure thatcustomer['product_cart']
is consistently a dictionary, as this is crucial for the functionality of theproduct_cart
attribute. -
Distance Calculation: Verify that the use of
math.dist
and the division by 100 in the road cost calculation align with your application's requirements, especially regarding the units of measurement. -
File Paths and Data: Double-check that the path to
app/config.json
is correct and that the file contains all necessary data for theshop_trip
function. -
Consistency in Data Structures: Ensure that the
products
parameter in theShop
class is consistently a dictionary throughout the code. -
Location Format: Confirm that the
location
attribute in theCustomer
class is a list in the correct format (e.g., [latitude, longitude]).
These improvements will help you avoid similar issues in the future. Keep up the good work, and continue learning from your experiences! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
class Customer: | ||
name: str | ||
product_cart: dict | ||
location: list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The location
attribute is expected to be a list, which is correct. However, ensure that the list contains the correct format (e.g., [latitude, longitude]) as per your application's requirements.
customers.append( | ||
Customer( | ||
customer["name"], | ||
customer["product_cart"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that customer['product_cart']
is a dictionary as expected by the Customer
class. This is crucial for the functionality of the product_cart
attribute.
|
||
|
||
def shop_trip() -> None: | ||
with open("app/config.json", "r") as f: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that the path to app/config.json
is correct and that the file contains all necessary data as expected by the shop_trip
function.
def __init__(self, | ||
name: str, | ||
location: list, | ||
products: dict, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The products
parameter in the Shop
class should be a dictionary, which is correct. Ensure that this is consistently a dictionary throughout the code.
def calculate_road_cost(customer: Customer, | ||
shop: Shop, fuel_price: float) -> float: | ||
return round( | ||
math.dist(customer.location, shop.location) / 100 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The calculation of the road cost is correct, but ensure that the distance calculation (math.dist
) is appropriate for your application's requirements. The division by 100 assumes the distance is in meters; adjust if necessary.
|
||
print(f"{customer.name}'s trip to the {shop.name} costs {trip_cost}") | ||
|
||
if trip_cost < customer.money and trip_cost <= cheapest_trip_cost: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition checks if the trip cost is less than the customer's money, which is correct. Ensure that the logic here aligns with the task requirements for determining if a customer can afford the trip.
|
||
|
||
def go_to_home(customer: Customer) -> None: | ||
customer.money -= customer.trip_cost |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that the subtraction of customer.trip_cost
from customer.money
is correct and that customer.trip_cost
includes all necessary costs (products and road).
No description provided.