-
Notifications
You must be signed in to change notification settings - Fork 725
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
a3f12af
commit b947658
Showing
6 changed files
with
60 additions
and
61 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,29 @@ | ||
import json | ||
import os | ||
from app.customer import Customer | ||
from app.shop import Shop | ||
|
||
|
||
def get_data(file_name: str) -> tuple | None: | ||
current_dir = os.path.dirname(__file__) | ||
file_path = os.path.join(current_dir, file_name) | ||
try: | ||
with open(file_path, "r") as file: | ||
content = json.load(file) | ||
except FileNotFoundError: | ||
print(current_dir) | ||
print("File not found!") | ||
return | ||
|
||
if all(key in content for key in ("FUEL_PRICE", "customers", "shops")): | ||
customer_list = [] | ||
shop_list = [] | ||
fuel_price = content["FUEL_PRICE"] | ||
|
||
for client in content["customers"]: | ||
if len(client) != 0: | ||
customer_list.append(Customer(**client)) | ||
for store in content["shops"]: | ||
if len(store) != 0: | ||
shop_list.append(Shop(**store)) | ||
return customer_list, shop_list, fuel_price, |
File renamed without changes.
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,13 +1,10 @@ | ||
import Classes | ||
from Classes import CUSTOMER_LIST, SHOP_LIST, FUEL_PRICE | ||
from app import get_data | ||
|
||
|
||
def shop_trip() -> None: | ||
Classes.get_data("config.json") | ||
for customer in CUSTOMER_LIST: | ||
cheapest_shop, cost = customer.calculate_trip_cost(SHOP_LIST, | ||
FUEL_PRICE) | ||
customer_list, shop_list, fuel_price = get_data("config.json") | ||
for customer in customer_list: | ||
cheapest_shop, cost = customer.calculate_trip_cost(shop_list, | ||
fuel_price) | ||
customer.trip_to_cheapest(cheapest_shop, cost) | ||
|
||
|
||
shop_trip() | ||
shop_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