-
Notifications
You must be signed in to change notification settings - Fork 738
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
48d4a4b
commit 636b6f2
Showing
5 changed files
with
44 additions
and
33 deletions.
There are no files selected for viewing
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
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
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
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
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,20 +1,28 @@ | ||
import json | ||
import math | ||
|
||
from app.classes.customer import Customer | ||
from app.classes.shop import Shop | ||
|
||
|
||
def parse_json(json_file: str) -> dict: | ||
with open(json_file) as file: | ||
return json.load(file) | ||
|
||
|
||
def get_shopping_cost(customer: Customer, shop: Shop) -> float: | ||
cost = 0 | ||
for item in customer.product_cart: | ||
cost += customer.product_cart[item] * shop.products[item] | ||
return cost | ||
|
||
|
||
def calculate_trip_cost(fuel_price: float, | ||
fuel_consumption: float, | ||
location_a: list, | ||
location_b: list) -> float: | ||
customer: Customer, | ||
shop: Shop) -> float: | ||
distance = ((customer.location[0] - shop.location[0]) ** 2 | ||
+ (customer.location[1] - shop.location[1]) ** 2) ** 0.5 | ||
|
||
distance = math.sqrt((location_b[0] - location_a[0]) ** 2 | ||
+ (location_b[1] - location_a[1]) ** 2) | ||
ride_cost = (customer.car.fuel_consumption / 100) * distance * fuel_price | ||
shopping_cost = get_shopping_cost(customer, shop) | ||
|
||
print(fuel_price, distance, fuel_consumption) | ||
print(fuel_consumption * distance * fuel_price) | ||
return fuel_consumption * distance * fuel_price | ||
return ride_cost * 2 + shopping_cost |