-
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
Open
ostboiko
wants to merge
30
commits into
mate-academy:master
Choose a base branch
from
ostboiko:develop
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Develop #404
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
66c1d22
py-shop-trip(1)
ostboiko 2845fba
py-shop-trip
ostboiko ee880d7
py-shop-trip(1)
ostboiko 58f736c
py-shop-trip(2)
ostboiko 799c93c
fixed_file
ostboiko 8286c63
fixed_file((car.py) and (customer.py))
ostboiko 397e1d3
fixed_file((car.py) and (customer.py))
ostboiko 66da35b
fixed_file((car.py) and (customer.py))
ostboiko c9fc16e
fixed_file((car.py) and (customer.py))
ostboiko 2f1a854
py-shop-trip
ostboiko 951193f
py-shop-trip(2)
ostboiko bdb77d1
py-shop-trip(3)
ostboiko 8a86975
py-shop-trip
ostboiko 780f88b
py-shop-trip
ostboiko 9137b69
py-shop-trip
ostboiko 4467b99
py-shop-trip(not fixed)
ostboiko 6eae346
py-shop-trip(Endlich)
ostboiko 8d421d0
py-shop-trip(Endlich)
ostboiko cefadac
py-shop-trip(1)
ostboiko a00f990
py-shop-trip(1 fixed)
ostboiko 04df98b
py-shop-trip(finish())
ostboiko a1c3144
py-shop-trip(finish(1))
ostboiko ce7d06f
py-shop-trip(finish(2))
ostboiko ae1ddc5
py-shop-trip(finish(2))
ostboiko e627836
py-shop-trip(finish(fixed))
ostboiko 606eb10
py-shop-trip(finish(fixed1))
ostboiko 51c5e44
py-shop-trip(finish(fixed 1))
ostboiko fb41d1f
py-shop-trip(finish(fixed 2))
ostboiko 573b1cf
py-shop-trip(finish(fixed 2))
ostboiko df6839a
py-shop-trip(finish(fixed 3))
ostboiko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class Car: | ||
def __init__( | ||
self, | ||
brand: str, | ||
fuel_consumption: float, | ||
) -> None: | ||
self.brand = brand | ||
self.fuel_consumption = fuel_consumption | ||
|
||
def calculate_trip_cost( | ||
self, | ||
distance: int, | ||
fuel_price: float | ||
) -> float: | ||
cost_trip = (distance * (self.fuel_consumption / 100)) * fuel_price | ||
return cost_trip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from typing import Dict, List | ||
from app.car import Car | ||
from app.shop import Shop | ||
|
||
|
||
class Customer: | ||
def __init__( | ||
self, | ||
name: str, | ||
product_cart: List, | ||
location: List, | ||
car: Car, | ||
money: int, | ||
) -> None: | ||
self.name = name | ||
self.product_cart = product_cart | ||
self.location = location | ||
self.car = car | ||
self.money = money | ||
self.total_cost = None | ||
|
||
def calculate_trip_cost(self, shop: Dict, fuel_price: float) -> float: | ||
distance_to_shop = self.calculate_distance(shop.location) | ||
fuel_cost = self.car.calculate_trip_cost(distance_to_shop, fuel_price) | ||
shopping_cost = shop.shopping_cost(self.product_cart) | ||
total_cost = fuel_cost + shopping_cost + fuel_cost | ||
return round(total_cost, 2) | ||
|
||
def calculate_distance(self, shop_location: List) -> float: | ||
x1, y1 = self.location | ||
x2, y2 = shop_location | ||
distance = ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5 | ||
return distance | ||
|
||
def calculate_money(self, shop: Shop) -> bool: | ||
shopping_cost = shop.shopping_cost(self.product_cart) | ||
return self.money >= shopping_cost |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,67 @@ | ||
def shop_trip(): | ||
# write your code here | ||
pass | ||
import json | ||
import datetime | ||
from app.customer import Customer | ||
from app.car import Car | ||
from app.shop import Shop | ||
|
||
|
||
def shop_trip() -> str: | ||
with open("app/config.json", "r") as config_file: | ||
config_data = json.load(config_file) | ||
|
||
fuel_price = config_data["FUEL_PRICE"] | ||
customers_data = config_data["customers"] | ||
shops_data = config_data["shops"] | ||
|
||
customers = [] | ||
shops = [] | ||
|
||
for customer_data in customers_data: | ||
car_data = customer_data["car"] | ||
car = Car(car_data["brand"], car_data["fuel_consumption"]) | ||
|
||
customer = Customer( | ||
customer_data["name"], | ||
customer_data["product_cart"], | ||
customer_data["location"], | ||
car, | ||
customer_data["money"], | ||
) | ||
customers.append(customer) | ||
|
||
for shop_data in shops_data: | ||
shop = Shop( | ||
shop_data["name"], | ||
shop_data["location"], | ||
shop_data["products"], | ||
fuel_price | ||
) | ||
shops.append(shop) | ||
|
||
for customer in customers: | ||
print(f"{customer.name} has {customer.money} dollars") | ||
cheapest_shop = None | ||
cheapest_cost = float("inf") | ||
|
||
for shop in shops: | ||
trip_cost = customer.calculate_trip_cost(shop, fuel_price) | ||
print(f"{customer.name}'s trip to the {shop.name}" | ||
f" costs {trip_cost}") | ||
if customer.calculate_money(shop): | ||
if trip_cost < cheapest_cost: | ||
cheapest_cost = trip_cost | ||
cheapest_shop = shop | ||
|
||
if cheapest_shop is not None: | ||
print(f"{customer.name} rides to " | ||
f"{cheapest_shop.name}\n") | ||
current_time = datetime.datetime.\ | ||
now().strftime("%d/%m/%Y %H:%M:%S") | ||
receipt = cheapest_shop.generate_receipt( | ||
customer, current_time, fuel_price) | ||
print(receipt) | ||
last_money = customer.money - cheapest_cost | ||
print(f"{customer.name} now has {last_money} dollars\n") | ||
else: | ||
print(f"{customer.name} doesn't have enough money " | ||
f"to make a purchase in any shop") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from typing import Dict, List | ||
|
||
|
||
class Shop: | ||
def __init__( | ||
self, | ||
name: str, | ||
location: Dict, | ||
product_cart: List, | ||
fuel_price: float | ||
) -> None: | ||
self.name = name | ||
self.location = location | ||
self.product_cart = product_cart | ||
self.fuel_price = fuel_price | ||
|
||
def shopping_cost(self, product_cart: List) -> float: | ||
total_cost = sum(self.product_cart[product] * product_cart[product] | ||
for product in product_cart.keys()) | ||
return round(total_cost, 2) | ||
|
||
def generate_receipt( | ||
self, | ||
customer: str, | ||
current_time: str, | ||
fuel_price: float | ||
) -> str: | ||
receipt = f"Date: {current_time}\nThanks, {customer.name}," \ | ||
f" for your purchase!\nYou have bought:" | ||
total_cost = 0 | ||
for product, quantity in customer.product_cart.items(): | ||
if product in self.product_cart: | ||
product_cost = self.product_cart[product] | ||
product_total_cost = float(product_cost * quantity) | ||
if product_total_cost.is_integer(): | ||
product_total_cost = int(product_total_cost) | ||
receipt += ( | ||
f"\n{quantity} {product}s for " | ||
f"{product_total_cost} dollars" | ||
) | ||
total_cost += product_total_cost | ||
receipt += f"\nTotal cost is {total_cost} dollars\nSee " \ | ||
f"you again!\n\n{customer.name} rides home" | ||
return receipt |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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