-
Notifications
You must be signed in to change notification settings - Fork 725
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
Develop #404
base: master
Are you sure you want to change the base?
Develop #404
Changes from 9 commits
66c1d22
2845fba
ee880d7
58f736c
799c93c
8286c63
397e1d3
66da35b
c9fc16e
2f1a854
951193f
bdb77d1
8a86975
780f88b
9137b69
4467b99
6eae346
8d421d0
cefadac
a00f990
04df98b
a1c3144
ce7d06f
ae1ddc5
e627836
606eb10
51c5e44
fb41d1f
573b1cf
df6839a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please restore this file! |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,9 @@ | |
|
||
- Read [the guideline](https://github.com/mate-academy/py-task-guideline/blob/main/README.md) before starting. | ||
|
||
You want to create an application that helps customers to choose the cheapest | ||
|
||
|
||
#You want to create an application that helps customers to choose the cheapest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you change this? |
||
trip for the products. | ||
|
||
There is `config.json` file that contains: | ||
|
@@ -141,6 +143,3 @@ You design application architecture by yourself, but there are some rules: | |
|
||
Distance between customer and shop is a distance between their locations in km. | ||
Round printed value to two decimal places. | ||
|
||
|
||
### Note: Check your code using this [checklist](checklist.md) before pushing your solution. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Restore this code |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The file is still not fixed. Try to recreate the file and rewrite the code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. File not fixed |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The file is still not fixed. Try to recreate the file and rewrite the code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. File not fixed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this file BTW There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this file. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,41 @@ | ||
def shop_trip(): | ||
# write your code here | ||
pass | ||
import json | ||
from app.customer import Customer | ||
from app.shop import Shop | ||
|
||
|
||
def shop_trip() -> int: | ||
with open("app/config.json") as file: | ||
data = json.load(file) | ||
|
||
fuel_price = data["FUEL_PRICE"] | ||
customers = [Customer(customer, fuel_price) | ||
for customer in data["customers"]] | ||
shops = [Shop(shop) for shop in data["shops"]] | ||
|
||
for customer in customers: | ||
print(f"{customer.name} has {customer.money} dollars") | ||
|
||
cheapest_shop = None | ||
cheapest_trip_cost = 0 | ||
|
||
for shop in shops: | ||
cost = customer.calculate_trip_cost(fuel_price, shop) | ||
|
||
print(f"{customer.name}'s trip to the {shop.name} costs {cost}") | ||
if not cheapest_shop or cost < cheapest_trip_cost: | ||
cheapest_shop = shop | ||
cheapest_trip_cost = cost | ||
|
||
if customer.money < cheapest_trip_cost: | ||
print(f"{customer.name} doesn't have enough money" | ||
f" to make a purchase in any shop") | ||
continue | ||
|
||
print(f"{customer.name} rides to {cheapest_shop.name}\n") | ||
cheapest_shop.check_printing(customer) | ||
|
||
print(f"{customer.name} rides home") | ||
customer.location = customer.home_location | ||
|
||
customer.money -= cheapest_trip_cost | ||
print(f"{customer.name} now has {customer.money} dollars\n") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from typing import Dict, Any | ||
import datetime | ||
|
||
|
||
class Shop: | ||
def __init__( | ||
self, | ||
info: Dict[str, Any], | ||
) -> None: | ||
self.name = info["name"] | ||
self.location = info["location"] | ||
self.products = info["products"] | ||
|
||
def check_printing( | ||
self, | ||
customer: Any, | ||
) -> None: | ||
current = datetime.datetime.now() | ||
timestamp = f"Date: {current.strftime('%d/%m/%Y %H:%M:%S')}" | ||
|
||
print(f"{timestamp.strip()}") | ||
customer.location = self.location | ||
print(f"Thanks, {customer.name}, for your purchase!") | ||
print("You have bought: ") | ||
|
||
spent_money = 0 | ||
for product, amount in customer.product_cart.items(): | ||
if product in self.products: | ||
cost = self.products[product] * amount | ||
spent_money += cost | ||
if cost % 1 == 0: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use cost.is_integer() There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not fixed |
||
cost = int(cost) | ||
print(f"{amount} {product}s for {cost} dollars") | ||
print(f"Total cost is {spent_money} dollars\nSee you again!\n") |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why you also need duplicate of file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this file. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from typing import Dict, Any | ||
|
||
|
||
class Car: | ||
def __init__( | ||
self, | ||
info: Dict[str, Any], | ||
fuel_price: float, | ||
) -> None: | ||
self.brand = info["brand"] | ||
self.fuel_consumption = info["fuel_consumption"] | ||
self.fuel_price = float(fuel_price) |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why you also need duplicate of file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Delete this file, please |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from typing import Dict, Any | ||
from app.shop import Shop | ||
from app.car import Car | ||
|
||
|
||
class Customer: | ||
def __init__( | ||
self, | ||
info: Dict[str, Any], | ||
fuel_price: float | ||
) -> None: | ||
self.name = info["name"] | ||
self.product_cart = info["product_cart"] | ||
self.location = info["location"] | ||
self.home_location = info["location"] | ||
self.money = info["money"] | ||
self.car = Car(info.get("car", {}), fuel_price) | ||
|
||
def calculate_trip_cost( | ||
self, | ||
fuel_price: float, | ||
shop: Shop | ||
) -> int: | ||
x1, y1 = self.location | ||
x2, y2 = shop.location | ||
distance = ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5 | ||
fuel_cost = (distance / 100) * \ | ||
self.car.fuel_consumption * fuel_price * 2 | ||
products_cost = self.calculate_products_cost(shop) | ||
total = round(products_cost + fuel_cost, 2) | ||
return total | ||
|
||
def calculate_products_cost( | ||
self, | ||
shop: Shop, | ||
) -> float | int: | ||
products_cost = sum(amount * shop.products[product] for | ||
product, amount in self.product_cart.items() | ||
if product in shop.products) | ||
return round(products_cost, 2) |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Delete this file, pleaase |
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.
This file was not fixed
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.
Restore changes on it