From ef01d6e0d3db6d72b510ed04ff571aadb9ffcb5b Mon Sep 17 00:00:00 2001 From: siued Date: Sat, 17 Feb 2024 11:28:51 +0100 Subject: [PATCH 01/27] get_location_for_new_order --- assignment/warehouse.py | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 assignment/warehouse.py diff --git a/assignment/warehouse.py b/assignment/warehouse.py new file mode 100644 index 0000000..fc95e14 --- /dev/null +++ b/assignment/warehouse.py @@ -0,0 +1,4 @@ +def get_location_for_new_order(order): + id = order["id"] + return str(id) + '-location'; + From cc07270e1b0d5ed5e7d010b963b77c809ee53c6e Mon Sep 17 00:00:00 2001 From: siued Date: Sat, 17 Feb 2024 11:35:36 +0100 Subject: [PATCH 02/27] get_human_readable_location --- assignment/warehouse.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/assignment/warehouse.py b/assignment/warehouse.py index fc95e14..2d00548 100644 --- a/assignment/warehouse.py +++ b/assignment/warehouse.py @@ -1,4 +1,23 @@ -def get_location_for_new_order(order): - id = order["id"] +def get_location_for_new_order(item): + # create a new unique location for the order + + id = item["id"] return str(id) + '-location'; + +def get_human_readable_location(location, item): + # convert the location to a human readable format + + id = location.replace('-location', '') + + return 'Item ' + item['description'] + 'with id ' + id + ' is located at ' + location + + +item = { + "id": "3526", + "description": "Google Pixel 8 128GB Black", + "IMEI": "331065863440734", + "EAN": "840244706692", + "price": "450.00" + } +print(get_human_readable_location(get_location_for_new_order(item), item)) \ No newline at end of file From f898c452b896251edaec841b0bc26620bfe00fb0 Mon Sep 17 00:00:00 2001 From: siued Date: Sat, 17 Feb 2024 11:49:47 +0100 Subject: [PATCH 03/27] location_manager --- assignment/location_manager.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 assignment/location_manager.py diff --git a/assignment/location_manager.py b/assignment/location_manager.py new file mode 100644 index 0000000..e7de2ba --- /dev/null +++ b/assignment/location_manager.py @@ -0,0 +1,15 @@ +import warehouse + +# in the future, this extends to multiple warehouses + +def get_new_item_location(item, warehouse): + if warehouse == 'warehouse1': + db_location = warehouse.get_location_for_new_item(item) + user_location = warehouse.get_human_readable_location(db_location, item) + return db_location, user_location + + +def convert_db_location_to_human_readable(db_location, item): + if warehouse == 'warehouse1': + user_location = warehouse.get_human_readable_location(db_location, item) + return user_location \ No newline at end of file From 2aebff051220fbbabba64a4a049bf7f361440c21 Mon Sep 17 00:00:00 2001 From: siued Date: Sat, 17 Feb 2024 12:41:05 +0100 Subject: [PATCH 04/27] get_order function --- assignment/get_order.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/assignment/get_order.py b/assignment/get_order.py index eb196a0..588510e 100644 --- a/assignment/get_order.py +++ b/assignment/get_order.py @@ -1,17 +1,19 @@ import json import random -input_file = open ('full_set.json') -products = json.load(input_file) +def get_order(): + input_file = open ('full_set.json') + products = json.load(input_file) -number_of_products = random.randint(1,10) + number_of_products = random.randint(1,10) -customer_number = random.randint(1,1000000) -customer = 'Customer ' + str(customer_number) + customer_number = random.randint(1,1000000) + customer = 'Customer ' + str(customer_number) -order = { - 'customer': customer, - 'order_items': random.sample(products, number_of_products) -} + order = { + 'customer': customer, + 'order_items': random.sample(products, number_of_products) + } -print(order) +if __name__ == "__main__": + print(get_order()) From 03faeefd595bc8de203242d34f716a1ded265564 Mon Sep 17 00:00:00 2001 From: siued Date: Sat, 17 Feb 2024 12:43:37 +0100 Subject: [PATCH 05/27] wms --- assignment/wms.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 assignment/wms.py diff --git a/assignment/wms.py b/assignment/wms.py new file mode 100644 index 0000000..72e8444 --- /dev/null +++ b/assignment/wms.py @@ -0,0 +1,26 @@ +import json +import get_order + +def add_items(items): + pass + +def wms(): + print("Welcome to the Warehouse Management System") + print("Your warehosue is now managed!") + command = input("Enter a command: ") + + if command == "add": + print("Adding new items") + with open("items.json", "w") as file: + items = json.read(file) + add_items(items) + elif command == "order": + print("Placing a new order") + order = get_order() + process_order(order) + elif command == "exit": + exit() + + +if __name__ == "__main__": + wms() \ No newline at end of file From 4a9916765a84db7204a81bd9fa82c41ed92f6d86 Mon Sep 17 00:00:00 2001 From: siued Date: Sat, 17 Feb 2024 12:48:48 +0100 Subject: [PATCH 06/27] add_items --- assignment/add_items.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 assignment/add_items.py diff --git a/assignment/add_items.py b/assignment/add_items.py new file mode 100644 index 0000000..c871ddb --- /dev/null +++ b/assignment/add_items.py @@ -0,0 +1,5 @@ +import stock_manager + +def add_items(items): + for item in items: + stock_manager.add_item(item) From e8608ab849ec1781428de9b96cf168900f17ed68 Mon Sep 17 00:00:00 2001 From: siued Date: Sat, 17 Feb 2024 12:52:09 +0100 Subject: [PATCH 07/27] small changes --- assignment/location_manager.py | 2 +- assignment/warehouse.py | 13 +++---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/assignment/location_manager.py b/assignment/location_manager.py index e7de2ba..926f050 100644 --- a/assignment/location_manager.py +++ b/assignment/location_manager.py @@ -2,7 +2,7 @@ # in the future, this extends to multiple warehouses -def get_new_item_location(item, warehouse): +def create_new_item_location(item, warehouse): if warehouse == 'warehouse1': db_location = warehouse.get_location_for_new_item(item) user_location = warehouse.get_human_readable_location(db_location, item) diff --git a/assignment/warehouse.py b/assignment/warehouse.py index 2d00548..0968dc5 100644 --- a/assignment/warehouse.py +++ b/assignment/warehouse.py @@ -1,4 +1,6 @@ -def get_location_for_new_order(item): +# this applies to one specific warehouse + +def get_location_for_new_item(item): # create a new unique location for the order id = item["id"] @@ -12,12 +14,3 @@ def get_human_readable_location(location, item): return 'Item ' + item['description'] + 'with id ' + id + ' is located at ' + location - -item = { - "id": "3526", - "description": "Google Pixel 8 128GB Black", - "IMEI": "331065863440734", - "EAN": "840244706692", - "price": "450.00" - } -print(get_human_readable_location(get_location_for_new_order(item), item)) \ No newline at end of file From afa0475949b2ac8cc44f86bdf7b323b9c208c3fa Mon Sep 17 00:00:00 2001 From: siued Date: Sat, 17 Feb 2024 12:56:08 +0100 Subject: [PATCH 08/27] gitignore --- .gitignore | 348 ++++++++++++++++++++++++++++++++++++++++++++++ assignment/wms.py | 8 +- 2 files changed, 351 insertions(+), 5 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6b72d16 --- /dev/null +++ b/.gitignore @@ -0,0 +1,348 @@ +# Created by https://www.toptal.com/developers/gitignore/api/python,macos,windows,pycharm +# Edit at https://www.toptal.com/developers/gitignore?templates=python,macos,windows,pycharm + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud + +### PyCharm ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### PyCharm Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +# https://plugins.jetbrains.com/plugin/7973-sonarlint +.idea/**/sonarlint/ + +# SonarQube Plugin +# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin +.idea/**/sonarIssues.xml + +# Markdown Navigator plugin +# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced +.idea/**/markdown-navigator.xml +.idea/**/markdown-navigator-enh.xml +.idea/**/markdown-navigator/ + +# Cache file creation bug +# See https://youtrack.jetbrains.com/issue/JBR-2257 +.idea/$CACHE_FILE$ + +# CodeStream plugin +# https://plugins.jetbrains.com/plugin/12206-codestream +.idea/codestream.xml + +# Azure Toolkit for IntelliJ plugin +# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij +.idea/**/azureSettings.xml + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + +### Python Patch ### +# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration +poetry.toml + +# ruff +.ruff_cache/ + +# LSP config files +pyrightconfig.json + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.toptal.com/developers/gitignore/api/python,macos,windows,pycharm \ No newline at end of file diff --git a/assignment/wms.py b/assignment/wms.py index 72e8444..e0a880b 100644 --- a/assignment/wms.py +++ b/assignment/wms.py @@ -1,8 +1,6 @@ import json import get_order - -def add_items(items): - pass +import add_items def wms(): print("Welcome to the Warehouse Management System") @@ -13,11 +11,11 @@ def wms(): print("Adding new items") with open("items.json", "w") as file: items = json.read(file) - add_items(items) + add_items.add_items(items) elif command == "order": print("Placing a new order") order = get_order() - process_order(order) + process_order.process_order(order) elif command == "exit": exit() From 49e8b0078e04195e3c0f4fa9d4ac62eed355a567 Mon Sep 17 00:00:00 2001 From: akselj Date: Sat, 17 Feb 2024 13:00:54 +0100 Subject: [PATCH 09/27] intermediate commit to pull other branches --- .env | 4 ++-- assignment/stock-manager.py | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 assignment/stock-manager.py diff --git a/.env b/.env index b401615..f742df7 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ MYSQL_ROOT_PASSWORD=admin123 MYSQL_DATABASE=belsimpel_hackathon -MYSQL_USER=my_username -MYSQL_PASSWORD=my_password +MYSQL_USER=admin +MYSQL_PASSWORD=admin diff --git a/assignment/stock-manager.py b/assignment/stock-manager.py new file mode 100644 index 0000000..9b39a73 --- /dev/null +++ b/assignment/stock-manager.py @@ -0,0 +1,40 @@ +import database_controller as database +import location_manager +import numpy as np + +# import order retrieval +# import new item retreival + + +class Stock_Manager: + def __init__(self) -> None: + self.incoming_order = None # A cron job? + self.new_item = None + self.database = None # Database Controller class that implements getters and setters + self.warehouses = tuple( + "warehouse1", "warehouse2", "warehouse3", "warehouse4" + ) + self.location_manager = ( + None # Location manager that generates the location for the item + ) + + self.items_in_warehouse = None # database.get_all_items() + self.n_items_in_warehouse = len(self.items_in_warehouse) + self.location_of_item = str(None) + + def add_new_item_to_database(self, item): + location = location_manager.create_new_item_location(item, warehouse) + database.add_location(item, location) + + def add_order_to_database(self, order): + database.add_order(order) + + pass + + def get_item_from_database(self): + pass + + def get_item_location_from_database(self, item): + item_location = database.get_location(item) + + return item_location From 932a8a6c9f05b0f4259285f46fe7f90fde4cde8d Mon Sep 17 00:00:00 2001 From: siued Date: Sat, 17 Feb 2024 13:44:47 +0100 Subject: [PATCH 10/27] get_order fix --- assignment/get_order.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/assignment/get_order.py b/assignment/get_order.py index 588510e..30eb9d6 100644 --- a/assignment/get_order.py +++ b/assignment/get_order.py @@ -15,5 +15,8 @@ def get_order(): 'order_items': random.sample(products, number_of_products) } + return order + + if __name__ == "__main__": print(get_order()) From d3f3bbf10f7e3c1061c14b22deeeccb6c466b10d Mon Sep 17 00:00:00 2001 From: Marcus Persson Date: Sat, 17 Feb 2024 14:00:43 +0100 Subject: [PATCH 11/27] process order basic --- assignment/process_order.py | 30 ++++++++++++++++++++++++++++++ assignment/verify_ean.py | 4 ++++ assignment/wms.py | 1 + 3 files changed, 35 insertions(+) create mode 100644 assignment/process_order.py create mode 100644 assignment/verify_ean.py diff --git a/assignment/process_order.py b/assignment/process_order.py new file mode 100644 index 0000000..bdb49ab --- /dev/null +++ b/assignment/process_order.py @@ -0,0 +1,30 @@ +import stock_manager +import verify_ean + +EAN = "EAN" + +def process_order(order): + eans = [] + for i in order[1]: + eans.append[i[EAN]] + + print(eans) + + items = 0 + while items < len(order): + item = input("Scan the item (EAN tag): ") + if item == "exit": + print("Stopped processing order") + return + if verify_ean.ean_verified(item, eans): + print("Item scanned.") + items += 1 + else: + print("Invalid EAN tag. Please scan again.") + print("All correct items scanned. Processing the order.") + + stock_manager.remove_from_stock() + return + + + \ No newline at end of file diff --git a/assignment/verify_ean.py b/assignment/verify_ean.py new file mode 100644 index 0000000..c3557bc --- /dev/null +++ b/assignment/verify_ean.py @@ -0,0 +1,4 @@ +def ean_verified(ean: str, eans: list) -> bool: + if ean in eans: + return True + return False \ No newline at end of file diff --git a/assignment/wms.py b/assignment/wms.py index e0a880b..a7dcb44 100644 --- a/assignment/wms.py +++ b/assignment/wms.py @@ -1,6 +1,7 @@ import json import get_order import add_items +import process_order def wms(): print("Welcome to the Warehouse Management System") From 1d162b36a2157111514c7502adce6f0a22632216 Mon Sep 17 00:00:00 2001 From: HermanD9722 <30570921+HermanD9722@users.noreply.github.com> Date: Sat, 17 Feb 2024 14:01:46 +0100 Subject: [PATCH 12/27] db_connection added --- assignment/db_connection.py | 52 +++++++++++++++++++++++++++++++++++++ docker-compose.yml | 2 +- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 assignment/db_connection.py diff --git a/assignment/db_connection.py b/assignment/db_connection.py new file mode 100644 index 0000000..b3511a1 --- /dev/null +++ b/assignment/db_connection.py @@ -0,0 +1,52 @@ +import mysql.connector +from dotenv import load_dotenv +import os +import json + +# Load environment variables from .env file +load_dotenv() + +# Retrieve database connection details from environment variables +host = "localhost" # Docker is running on the same machine +user = os.getenv("MYSQL_USER") +password = os.getenv("MYSQL_PASSWORD") +database = os.getenv("MYSQL_DATABASE") + +# Create a connection to the MySQL server +connection = mysql.connector.connect( + host=host, + user=user, + password=password, + database=database +) + +# Create a cursor object to interact with the database +cursor = connection.cursor() + +# Read data from the JSON file +json_file_path = "assignment\\sample_set.json" +with open(json_file_path, "r") as json_file: + data = json.load(json_file) + +# Read the SQL file (file.sql) containing the CREATE TABLE statement +sql_file_path = "assignment\\product.sql" # Adjusted path +with open(sql_file_path, "r") as sql_file: + create_table_query = sql_file.read() + +# Execute the CREATE TABLE statement +cursor.execute(create_table_query, multi=True) + +# Insert data into the table +columns_placeholder = ", ".join(['%s'] * len(data[0])) +insert_data_query = f"INSERT INTO product ({', '.join(data[0].keys())}) VALUES ({columns_placeholder})" + +for record in data: + data_to_insert = tuple(record.get(key, None) for key in data[0].keys()) + cursor.execute(insert_data_query, data_to_insert) + +# Commit the changes to the database +connection.commit() + +# Close the cursor and connection +cursor.close() +connection.close() diff --git a/docker-compose.yml b/docker-compose.yml index f984dd3..efcf08e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,7 +9,7 @@ services: mysql: image: mysql:latest container_name: mysql - command: --default-authentication-plugin=caching_sha2_password + command: --default-authentication-plugin=mysql_native_password restart: always environment: MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} From 5239e6b0ea3e2406b64fb8b0638f4fa7de027330 Mon Sep 17 00:00:00 2001 From: Marcus Persson Date: Sat, 17 Feb 2024 14:04:20 +0100 Subject: [PATCH 13/27] fix syntax --- assignment/process_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assignment/process_order.py b/assignment/process_order.py index bdb49ab..d24522a 100644 --- a/assignment/process_order.py +++ b/assignment/process_order.py @@ -6,7 +6,7 @@ def process_order(order): eans = [] for i in order[1]: - eans.append[i[EAN]] + eans.append[i][EAN] print(eans) From adcdb4747b666552a86b609cdb2f1640a48fdd2d Mon Sep 17 00:00:00 2001 From: Ash920323 Date: Sat, 17 Feb 2024 14:05:53 +0100 Subject: [PATCH 14/27] sql --- assignment/prduct.sql | 67 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 assignment/prduct.sql diff --git a/assignment/prduct.sql b/assignment/prduct.sql new file mode 100644 index 0000000..79f2454 --- /dev/null +++ b/assignment/prduct.sql @@ -0,0 +1,67 @@ +-- phpMyAdmin SQL Dump +-- version 5.2.1 +-- https://www.phpmyadmin.net/ +-- +-- Host: mysql:3306 +-- Generation Time: Feb 17, 2024 at 11:50 AM +-- Server version: 8.3.0 +-- PHP Version: 8.2.16 + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +START TRANSACTION; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; + +-- +-- Database: `belsimpel_hackathon` +-- + +-- -------------------------------------------------------- + +-- +-- Table structure for table `prduct` +-- + +CREATE TABLE `prduct` ( + `Description` text NOT NULL, + `EAN` text NOT NULL, + `Price` float NOT NULL, + `Stock` int NOT NULL, + `IMEI` text NOT NULL, + `Prepaid_sim` text NOT NULL, + `Prepaid_tel` text NOT NULL, + `ID` int NOT NULL, + `identifier` text NOT NULL, + `location` text NOT NULL, + `warehouse` text NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +-- +-- Indexes for dumped tables +-- + +-- +-- Indexes for table `prduct` +-- +ALTER TABLE `prduct` + ADD PRIMARY KEY (`ID`); + +-- +-- AUTO_INCREMENT for dumped tables +-- + +-- +-- AUTO_INCREMENT for table `prduct` +-- +ALTER TABLE `prduct` + MODIFY `ID` int NOT NULL AUTO_INCREMENT; +COMMIT; + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; From fd042b85831c2014827784d69e4b22f91499431a Mon Sep 17 00:00:00 2001 From: siued Date: Sat, 17 Feb 2024 14:09:34 +0100 Subject: [PATCH 15/27] change prints in process order --- assignment/process_order.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/assignment/process_order.py b/assignment/process_order.py index bdb49ab..4114124 100644 --- a/assignment/process_order.py +++ b/assignment/process_order.py @@ -8,11 +8,12 @@ def process_order(order): for i in order[1]: eans.append[i[EAN]] + print("Customer: " + order[0] + " ordered the following items:") print(eans) items = 0 while items < len(order): - item = input("Scan the item (EAN tag): ") + item = input("Scan the item (EAN tag), type exit to exit: ") if item == "exit": print("Stopped processing order") return @@ -26,5 +27,3 @@ def process_order(order): stock_manager.remove_from_stock() return - - \ No newline at end of file From dc67dd680802f5aef3531a12f9b3776525eef35f Mon Sep 17 00:00:00 2001 From: Marcus Persson Date: Sat, 17 Feb 2024 14:13:46 +0100 Subject: [PATCH 16/27] fixes --- assignment/process_order.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/assignment/process_order.py b/assignment/process_order.py index 5e51528..2184a3a 100644 --- a/assignment/process_order.py +++ b/assignment/process_order.py @@ -11,8 +11,8 @@ def process_order(order): print("Customer: " + order[0] + " ordered the following items:") print(eans) - items = 0 - while items < len(order): + items = 1 + while items < len(eans): item = input("Scan the item (EAN tag), type exit to exit: ") if item == "exit": print("Stopped processing order") @@ -24,6 +24,6 @@ def process_order(order): print("Invalid EAN tag. Please scan again.") print("All correct items scanned. Processing the order.") - stock_manager.remove_from_stock() + stock_manager.remove_from_stock(order[1]) return From 9e8db8d5f4fe5dec75a547c5dd49abfdd4558b38 Mon Sep 17 00:00:00 2001 From: akselj Date: Sat, 17 Feb 2024 14:17:11 +0100 Subject: [PATCH 17/27] update stock manager --- assignment/stock-manager.py | 43 ++++++++++++++----------------------- assignment/warehouse.py | 2 +- 2 files changed, 17 insertions(+), 28 deletions(-) diff --git a/assignment/stock-manager.py b/assignment/stock-manager.py index 9b39a73..69e65da 100644 --- a/assignment/stock-manager.py +++ b/assignment/stock-manager.py @@ -1,40 +1,29 @@ -import database_controller as database +import database_controller as database # Database Controller class that implements getters and setters import location_manager -import numpy as np # import order retrieval # import new item retreival -class Stock_Manager: - def __init__(self) -> None: - self.incoming_order = None # A cron job? - self.new_item = None - self.database = None # Database Controller class that implements getters and setters - self.warehouses = tuple( - "warehouse1", "warehouse2", "warehouse3", "warehouse4" - ) - self.location_manager = ( - None # Location manager that generates the location for the item - ) +def add_new_item_to_database(item, warehouse): + db_location, _ = location_manager.create_new_item_location(item, warehouse) - self.items_in_warehouse = None # database.get_all_items() - self.n_items_in_warehouse = len(self.items_in_warehouse) - self.location_of_item = str(None) + database.add_item(item) + database.add_location_to_item(item, db_location) - def add_new_item_to_database(self, item): - location = location_manager.create_new_item_location(item, warehouse) - database.add_location(item, location) - def add_order_to_database(self, order): - database.add_order(order) +def add_order_to_database(order): + database.add_order(order) - pass - def get_item_from_database(self): - pass +def get_item_from_database(item): + return database.get_item(item) - def get_item_location_from_database(self, item): - item_location = database.get_location(item) - return item_location +def get_item_location_from_database(item): + return database.get_location(item) + + +def remove_item_from_database(items_to_remove): + for item in items_to_remove: + database.remove_item(item) diff --git a/assignment/warehouse.py b/assignment/warehouse.py index 0968dc5..12a9c61 100644 --- a/assignment/warehouse.py +++ b/assignment/warehouse.py @@ -4,7 +4,7 @@ def get_location_for_new_item(item): # create a new unique location for the order id = item["id"] - return str(id) + '-location'; + return str(id) + '-location' def get_human_readable_location(location, item): From 7329ea5e335ac1682a3e684766fd60aff4c5b8bd Mon Sep 17 00:00:00 2001 From: Marcus Persson Date: Sat, 17 Feb 2024 14:28:52 +0100 Subject: [PATCH 18/27] tweaks --- assignment/wms.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/assignment/wms.py b/assignment/wms.py index a7dcb44..fd12a2c 100644 --- a/assignment/wms.py +++ b/assignment/wms.py @@ -3,22 +3,25 @@ import add_items import process_order +COMMANDS = "add/order/exit" + def wms(): print("Welcome to the Warehouse Management System") print("Your warehosue is now managed!") - command = input("Enter a command: ") - - if command == "add": - print("Adding new items") - with open("items.json", "w") as file: - items = json.read(file) - add_items.add_items(items) - elif command == "order": - print("Placing a new order") - order = get_order() - process_order.process_order(order) - elif command == "exit": - exit() + while True: + command = input("Enter a command:" + COMMANDS + "\n") + match command: + case "add": + print("Adding new items") + with open("items.json", "w") as file: + items = json.read(file) + add_items.add_items(items) + case "order": + print("Placing a new order") + order = get_order() + process_order.process_order(order) + case "exit": + exit() if __name__ == "__main__": From 3ff69809d19d62e57cf9bf644c6fb775dd98cd43 Mon Sep 17 00:00:00 2001 From: Ash920323 Date: Sat, 17 Feb 2024 14:29:45 +0100 Subject: [PATCH 19/27] fix name --- assignment/{prduct.sql => product.sql} | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) rename assignment/{prduct.sql => product.sql} (88%) diff --git a/assignment/prduct.sql b/assignment/product.sql similarity index 88% rename from assignment/prduct.sql rename to assignment/product.sql index 79f2454..55be96f 100644 --- a/assignment/prduct.sql +++ b/assignment/product.sql @@ -24,10 +24,10 @@ SET time_zone = "+00:00"; -- -------------------------------------------------------- -- --- Table structure for table `prduct` +-- Table structure for table `product` -- -CREATE TABLE `prduct` ( +CREATE TABLE `product` ( `Description` text NOT NULL, `EAN` text NOT NULL, `Price` float NOT NULL, @@ -46,9 +46,9 @@ CREATE TABLE `prduct` ( -- -- --- Indexes for table `prduct` +-- Indexes for table `product` -- -ALTER TABLE `prduct` +ALTER TABLE `product` ADD PRIMARY KEY (`ID`); -- @@ -56,9 +56,9 @@ ALTER TABLE `prduct` -- -- --- AUTO_INCREMENT for table `prduct` +-- AUTO_INCREMENT for table `product` -- -ALTER TABLE `prduct` +ALTER TABLE `product` MODIFY `ID` int NOT NULL AUTO_INCREMENT; COMMIT; From f778c188e45afd34fa808701d9200a632b14da70 Mon Sep 17 00:00:00 2001 From: Ash920323 Date: Sat, 17 Feb 2024 14:39:46 +0100 Subject: [PATCH 20/27] fix not null --- assignment/product.sql | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/assignment/product.sql b/assignment/product.sql index 55be96f..d955ab4 100644 --- a/assignment/product.sql +++ b/assignment/product.sql @@ -3,7 +3,7 @@ -- https://www.phpmyadmin.net/ -- -- Host: mysql:3306 --- Generation Time: Feb 17, 2024 at 11:50 AM +-- Generation Time: Feb 17, 2024 at 01:37 PM -- Server version: 8.3.0 -- PHP Version: 8.2.16 @@ -28,17 +28,17 @@ SET time_zone = "+00:00"; -- CREATE TABLE `product` ( - `Description` text NOT NULL, - `EAN` text NOT NULL, - `Price` float NOT NULL, - `Stock` int NOT NULL, - `IMEI` text NOT NULL, - `Prepaid_sim` text NOT NULL, - `Prepaid_tel` text NOT NULL, + `Description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci, + `EAN` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci, + `Price` float DEFAULT NULL, + `Stock` int DEFAULT NULL, + `IMEI` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci, + `Prepaid_sim` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci, + `Prepaid_tel` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci, `ID` int NOT NULL, - `identifier` text NOT NULL, - `location` text NOT NULL, - `warehouse` text NOT NULL + `identifier` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci, + `location` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci, + `warehouse` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- From 735e8a4c276fc19c969a0ea3b42341e850d1d1bb Mon Sep 17 00:00:00 2001 From: akselj Date: Sat, 17 Feb 2024 14:47:16 +0100 Subject: [PATCH 21/27] fixes to add_items location_manager stock_manager and wms --- assignment/add_items.py | 2 +- assignment/location_manager.py | 4 ++-- assignment/{stock-manager.py => stock_manager.py} | 4 ++-- assignment/wms.py | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) rename assignment/{stock-manager.py => stock_manager.py} (77%) diff --git a/assignment/add_items.py b/assignment/add_items.py index c871ddb..adad4a8 100644 --- a/assignment/add_items.py +++ b/assignment/add_items.py @@ -2,4 +2,4 @@ def add_items(items): for item in items: - stock_manager.add_item(item) + stock_manager.add_new_item_to_database(item) diff --git a/assignment/location_manager.py b/assignment/location_manager.py index 926f050..07a55be 100644 --- a/assignment/location_manager.py +++ b/assignment/location_manager.py @@ -2,8 +2,8 @@ # in the future, this extends to multiple warehouses -def create_new_item_location(item, warehouse): - if warehouse == 'warehouse1': +def create_new_item_location(item, warehouse_name): + if warehouse_name == 'warehouse1': db_location = warehouse.get_location_for_new_item(item) user_location = warehouse.get_human_readable_location(db_location, item) return db_location, user_location diff --git a/assignment/stock-manager.py b/assignment/stock_manager.py similarity index 77% rename from assignment/stock-manager.py rename to assignment/stock_manager.py index 69e65da..7885143 100644 --- a/assignment/stock-manager.py +++ b/assignment/stock_manager.py @@ -1,11 +1,11 @@ -import database_controller as database # Database Controller class that implements getters and setters +#import database_controller as database # Database Controller class that implements getters and setters import location_manager # import order retrieval # import new item retreival -def add_new_item_to_database(item, warehouse): +def add_new_item_to_database(item, warehouse="warehouse1"): db_location, _ = location_manager.create_new_item_location(item, warehouse) database.add_item(item) diff --git a/assignment/wms.py b/assignment/wms.py index a7dcb44..c07bec4 100644 --- a/assignment/wms.py +++ b/assignment/wms.py @@ -10,8 +10,8 @@ def wms(): if command == "add": print("Adding new items") - with open("items.json", "w") as file: - items = json.read(file) + with open("./assignment/sample_set.json", "r") as file: + items = json.load(file) add_items.add_items(items) elif command == "order": print("Placing a new order") From 4c6725d415d2a9f9b343cc8c7857c74fe40d9be8 Mon Sep 17 00:00:00 2001 From: akselj Date: Sat, 17 Feb 2024 15:08:37 +0100 Subject: [PATCH 22/27] fixed until database controller --- assignment/get_order.py | 2 +- assignment/process_order.py | 20 ++++++++++++++------ assignment/stock_manager.py | 1 + assignment/wms.py | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/assignment/get_order.py b/assignment/get_order.py index 30eb9d6..de75c48 100644 --- a/assignment/get_order.py +++ b/assignment/get_order.py @@ -2,7 +2,7 @@ import random def get_order(): - input_file = open ('full_set.json') + input_file = open('./assignment/full_set.json') products = json.load(input_file) number_of_products = random.randint(1,10) diff --git a/assignment/process_order.py b/assignment/process_order.py index 2184a3a..077586f 100644 --- a/assignment/process_order.py +++ b/assignment/process_order.py @@ -2,28 +2,36 @@ import verify_ean EAN = "EAN" +CUSTOMER = "customer" +ORDER_ITEMS = "order_items" + def process_order(order): eans = [] - for i in order[1]: - eans.append[i][EAN] - - print("Customer: " + order[0] + " ordered the following items:") + order_items = order[ORDER_ITEMS] + for item in order_items: + eans.append(item[EAN]) + + print("Customer: " + order[CUSTOMER] + " ordered the following items:") print(eans) items = 1 while items < len(eans): item = input("Scan the item (EAN tag), type exit to exit: ") + if item == "bypass": + break + if item == "exit": print("Stopped processing order") return + if verify_ean.ean_verified(item, eans): print("Item scanned.") items += 1 else: print("Invalid EAN tag. Please scan again.") + print("All correct items scanned. Processing the order.") - stock_manager.remove_from_stock(order[1]) + stock_manager.remove_item_from_database(order[ORDER_ITEMS]) return - diff --git a/assignment/stock_manager.py b/assignment/stock_manager.py index 7885143..51adbc3 100644 --- a/assignment/stock_manager.py +++ b/assignment/stock_manager.py @@ -8,6 +8,7 @@ def add_new_item_to_database(item, warehouse="warehouse1"): db_location, _ = location_manager.create_new_item_location(item, warehouse) + print(item, db_location) database.add_item(item) database.add_location_to_item(item, db_location) diff --git a/assignment/wms.py b/assignment/wms.py index b45ca3c..56270c1 100644 --- a/assignment/wms.py +++ b/assignment/wms.py @@ -19,7 +19,7 @@ def wms(): add_items.add_items(items) case "order": print("Placing a new order") - order = get_order() + order = get_order.get_order() process_order.process_order(order) case "exit": exit() From a69f8aad85292da5211fc60eba97a913844e133c Mon Sep 17 00:00:00 2001 From: akselj Date: Sat, 17 Feb 2024 15:09:32 +0100 Subject: [PATCH 23/27] stylistic changes --- assignment/add_items.py | 1 + assignment/get_order.py | 13 +++++++------ assignment/location_manager.py | 15 ++++++++++----- assignment/stock_manager.py | 2 +- assignment/verify_ean.py | 2 +- assignment/wms.py | 9 +++++---- 6 files changed, 25 insertions(+), 17 deletions(-) diff --git a/assignment/add_items.py b/assignment/add_items.py index adad4a8..a802753 100644 --- a/assignment/add_items.py +++ b/assignment/add_items.py @@ -1,5 +1,6 @@ import stock_manager + def add_items(items): for item in items: stock_manager.add_new_item_to_database(item) diff --git a/assignment/get_order.py b/assignment/get_order.py index de75c48..5ef89ee 100644 --- a/assignment/get_order.py +++ b/assignment/get_order.py @@ -1,18 +1,19 @@ import json import random + def get_order(): - input_file = open('./assignment/full_set.json') + input_file = open("./assignment/full_set.json") products = json.load(input_file) - number_of_products = random.randint(1,10) + number_of_products = random.randint(1, 10) - customer_number = random.randint(1,1000000) - customer = 'Customer ' + str(customer_number) + customer_number = random.randint(1, 1000000) + customer = "Customer " + str(customer_number) order = { - 'customer': customer, - 'order_items': random.sample(products, number_of_products) + "customer": customer, + "order_items": random.sample(products, number_of_products), } return order diff --git a/assignment/location_manager.py b/assignment/location_manager.py index 07a55be..be10457 100644 --- a/assignment/location_manager.py +++ b/assignment/location_manager.py @@ -2,14 +2,19 @@ # in the future, this extends to multiple warehouses + def create_new_item_location(item, warehouse_name): - if warehouse_name == 'warehouse1': + if warehouse_name == "warehouse1": db_location = warehouse.get_location_for_new_item(item) - user_location = warehouse.get_human_readable_location(db_location, item) + user_location = warehouse.get_human_readable_location( + db_location, item + ) return db_location, user_location def convert_db_location_to_human_readable(db_location, item): - if warehouse == 'warehouse1': - user_location = warehouse.get_human_readable_location(db_location, item) - return user_location \ No newline at end of file + if warehouse == "warehouse1": + user_location = warehouse.get_human_readable_location( + db_location, item + ) + return user_location diff --git a/assignment/stock_manager.py b/assignment/stock_manager.py index 51adbc3..7d49df8 100644 --- a/assignment/stock_manager.py +++ b/assignment/stock_manager.py @@ -1,4 +1,4 @@ -#import database_controller as database # Database Controller class that implements getters and setters +# import database_controller as database # Database Controller class that implements getters and setters import location_manager # import order retrieval diff --git a/assignment/verify_ean.py b/assignment/verify_ean.py index c3557bc..45a52a0 100644 --- a/assignment/verify_ean.py +++ b/assignment/verify_ean.py @@ -1,4 +1,4 @@ def ean_verified(ean: str, eans: list) -> bool: if ean in eans: return True - return False \ No newline at end of file + return False diff --git a/assignment/wms.py b/assignment/wms.py index 56270c1..89fc31f 100644 --- a/assignment/wms.py +++ b/assignment/wms.py @@ -1,10 +1,12 @@ import json -import get_order + import add_items +import get_order import process_order COMMANDS = "add/order/exit" + def wms(): print("Welcome to the Warehouse Management System") print("Your warehosue is now managed!") @@ -13,7 +15,7 @@ def wms(): command = input("Enter a command:" + COMMANDS + "\n") match command: case "add": - print("Adding new items") + print("Adding new items") with open("./assignment/sample_set.json", "r") as file: items = json.load(file) add_items.add_items(items) @@ -25,6 +27,5 @@ def wms(): exit() - if __name__ == "__main__": - wms() \ No newline at end of file + wms() From 6827921b5df47f5200ed17ec4b76cc344cc65dc1 Mon Sep 17 00:00:00 2001 From: siued Date: Sat, 17 Feb 2024 15:21:15 +0100 Subject: [PATCH 24/27] db controller functions --- assignment/db_connection.py | 116 +++++++++++++++++++++--------------- 1 file changed, 69 insertions(+), 47 deletions(-) diff --git a/assignment/db_connection.py b/assignment/db_connection.py index b3511a1..069a463 100644 --- a/assignment/db_connection.py +++ b/assignment/db_connection.py @@ -3,50 +3,72 @@ import os import json -# Load environment variables from .env file -load_dotenv() - -# Retrieve database connection details from environment variables -host = "localhost" # Docker is running on the same machine -user = os.getenv("MYSQL_USER") -password = os.getenv("MYSQL_PASSWORD") -database = os.getenv("MYSQL_DATABASE") - -# Create a connection to the MySQL server -connection = mysql.connector.connect( - host=host, - user=user, - password=password, - database=database -) - -# Create a cursor object to interact with the database -cursor = connection.cursor() - -# Read data from the JSON file -json_file_path = "assignment\\sample_set.json" -with open(json_file_path, "r") as json_file: - data = json.load(json_file) - -# Read the SQL file (file.sql) containing the CREATE TABLE statement -sql_file_path = "assignment\\product.sql" # Adjusted path -with open(sql_file_path, "r") as sql_file: - create_table_query = sql_file.read() - -# Execute the CREATE TABLE statement -cursor.execute(create_table_query, multi=True) - -# Insert data into the table -columns_placeholder = ", ".join(['%s'] * len(data[0])) -insert_data_query = f"INSERT INTO product ({', '.join(data[0].keys())}) VALUES ({columns_placeholder})" - -for record in data: - data_to_insert = tuple(record.get(key, None) for key in data[0].keys()) - cursor.execute(insert_data_query, data_to_insert) - -# Commit the changes to the database -connection.commit() - -# Close the cursor and connection -cursor.close() -connection.close() + +def get_connection(): + load_dotenv() + + # Retrieve database connection details from environment variables + host = "localhost" # Docker is running on the same machine + user = os.getenv("MYSQL_USER") + password = os.getenv("MYSQL_PASSWORD") + database = os.getenv("MYSQL_DATABASE") + + # Create a connection to the MySQL server + connection = mysql.connector.connect( + host=host, + user=user, + password=password, + database=database + ) + + # Create a cursor object to interact with the database + cursor = connection.cursor() + return connection + + +def create_table(): + connection = get_connection() + cursor = connection.cursor() + + # Read the SQL file (file.sql) containing the CREATE TABLE statement + sql_file_path = "assignment\\product.sql" # Adjusted path + with open(sql_file_path, "r") as sql_file: + create_table_query = sql_file.read() + + # Execute the CREATE TABLE statement + cursor.execute(create_table_query, multi=True) + + # Commit the changes to the database + connection.commit() + + # Close the cursor and connection + cursor.close() + connection.close() + + +def add_items(data): + connection = get_connection() + cursor = connection.cursor() + + # Insert data into the table + columns_placeholder = ", ".join(['%s'] * len(data[0])) + insert_data_query = f"INSERT INTO product ({', '.join(data[0].keys())}) VALUES ({columns_placeholder})" + + for record in data: + data_to_insert = tuple(record.get(key, None) for key in data[0].keys()) + cursor.execute(insert_data_query, data_to_insert) + + # Commit the changes to the database + connection.commit() + + # Close the cursor and connection + cursor.close() + connection.close() + + +create_table() + + +with open("assignment\\sample_set.json", "r") as file: + items = json.load(file) + add_items(items) \ No newline at end of file From 79361d9a0eb2e538db822715656e5e503ecaaa29 Mon Sep 17 00:00:00 2001 From: siued Date: Sat, 17 Feb 2024 15:40:41 +0100 Subject: [PATCH 25/27] db controller, stock controller --- assignment/db_connection.py | 34 +++++++++++++++++++++++++++++----- assignment/stock_manager.py | 24 ++++++++++++++++-------- 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/assignment/db_connection.py b/assignment/db_connection.py index 069a463..d6cc4df 100644 --- a/assignment/db_connection.py +++ b/assignment/db_connection.py @@ -31,7 +31,7 @@ def create_table(): cursor = connection.cursor() # Read the SQL file (file.sql) containing the CREATE TABLE statement - sql_file_path = "assignment\\product.sql" # Adjusted path + sql_file_path = "/Users/matejkucera/Desktop/belsimpel-hackathon-2024/assignment/product.sql" # Adjusted path with open(sql_file_path, "r") as sql_file: create_table_query = sql_file.read() @@ -66,9 +66,33 @@ def add_items(data): connection.close() -create_table() +def get_item(id): + connection = get_connection() + cursor = connection.cursor() + + # Retrieve the item from the database + select_item_query = f"SELECT * FROM product WHERE id = {id}" + cursor.execute(select_item_query) + item = cursor.fetchone() + + # Close the cursor and connection + cursor.close() + connection.close() + + return item -with open("assignment\\sample_set.json", "r") as file: - items = json.load(file) - add_items(items) \ No newline at end of file +def get_location(id): + connection = get_connection() + cursor = connection.cursor() + + # Retrieve the item from the database + select_item_query = f"SELECT location FROM product WHERE id = {id}" + cursor.execute(select_item_query) + item = cursor.fetchone() + + # Close the cursor and connection + cursor.close() + connection.close() + + return item['location'] \ No newline at end of file diff --git a/assignment/stock_manager.py b/assignment/stock_manager.py index 7885143..1e5f9b5 100644 --- a/assignment/stock_manager.py +++ b/assignment/stock_manager.py @@ -1,5 +1,6 @@ #import database_controller as database # Database Controller class that implements getters and setters import location_manager +import db_connection as database # import order retrieval # import new item retreival @@ -7,23 +8,30 @@ def add_new_item_to_database(item, warehouse="warehouse1"): db_location, _ = location_manager.create_new_item_location(item, warehouse) + item['location'] = db_location + item['stock'] = 1 + # here check for stock and either add new item or increase stock database.add_item(item) - database.add_location_to_item(item, db_location) -def add_order_to_database(order): - database.add_order(order) +# def add_order_to_database(order): +# database.add_order(order) -def get_item_from_database(item): - return database.get_item(item) +# def get_item_from_database(item): +# return database.get_item(item) -def get_item_location_from_database(item): - return database.get_location(item) +def get_item_location_from_database(id): + return database.get_location(id) def remove_item_from_database(items_to_remove): for item in items_to_remove: - database.remove_item(item) + pass + + +def get_stock(id): + item = database.get_item(id) + return item['stock'] From 49915b96a72edf593be638612fb3a77eabb8569d Mon Sep 17 00:00:00 2001 From: Ash920323 Date: Sat, 17 Feb 2024 15:40:51 +0100 Subject: [PATCH 26/27] update table --- assignment/product.sql | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/assignment/product.sql b/assignment/product.sql index d955ab4..7aab43c 100644 --- a/assignment/product.sql +++ b/assignment/product.sql @@ -3,7 +3,7 @@ -- https://www.phpmyadmin.net/ -- -- Host: mysql:3306 --- Generation Time: Feb 17, 2024 at 01:37 PM +-- Generation Time: Feb 17, 2024 at 02:38 PM -- Server version: 8.3.0 -- PHP Version: 8.2.16 @@ -30,15 +30,17 @@ SET time_zone = "+00:00"; CREATE TABLE `product` ( `Description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci, `EAN` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci, - `Price` float DEFAULT NULL, + `Price` int DEFAULT NULL, `Stock` int DEFAULT NULL, - `IMEI` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci, - `Prepaid_sim` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci, - `Prepaid_tel` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci, + `IMEI` text, + `Prepaid_sim` text, + `Prepaid_tel` text, `ID` int NOT NULL, - `identifier` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci, - `location` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci, - `warehouse` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci + `identifier` text, + `location` text, + `warehouse` text, + `CustomerID` int DEFAULT NULL, + `Fullfill` tinyint(1) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- From 14d00124d278bbf109c16c10928c34e8f60366df Mon Sep 17 00:00:00 2001 From: Marcus Persson Date: Sat, 17 Feb 2024 16:02:56 +0100 Subject: [PATCH 27/27] assignment-2 --- assignment/check_order.py | 18 ++++++++++++++++++ assignment/db_connection.py | 17 ++++++++++++++++- assignment/wms.py | 6 +++++- 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 assignment/check_order.py diff --git a/assignment/check_order.py b/assignment/check_order.py new file mode 100644 index 0000000..b8d6315 --- /dev/null +++ b/assignment/check_order.py @@ -0,0 +1,18 @@ +import db_connection as database + +def check_order(): + while True: + order_id = input("Input the order ID, type exit to exit: ") + match order_id: + case "exit": + print("Stopped searching for order") + break + case "": + print("Must have a correct order ID") + case _: + items = database.get_order() + if items is None: + print("There is no order attached to that ID.") + else: + print(items) + return \ No newline at end of file diff --git a/assignment/db_connection.py b/assignment/db_connection.py index d6cc4df..47cdf11 100644 --- a/assignment/db_connection.py +++ b/assignment/db_connection.py @@ -95,4 +95,19 @@ def get_location(id): cursor.close() connection.close() - return item['location'] \ No newline at end of file + return item['location'] + +def get_order(id): + connection = get_connection() + cursor = connection.cursor() + + # Retrieve the item from the database + select_item_query = f"SELECT * FROM product WHERE CustomerID = {id}" + cursor.execute(select_item_query) + item = cursor.fetchall() + + # Close the cursor and connection + cursor.close() + connection.close() + + return item \ No newline at end of file diff --git a/assignment/wms.py b/assignment/wms.py index 89fc31f..9f10e5b 100644 --- a/assignment/wms.py +++ b/assignment/wms.py @@ -3,8 +3,9 @@ import add_items import get_order import process_order +import check_order -COMMANDS = "add/order/exit" +COMMANDS = "add/order/exit/customer_order" def wms(): @@ -23,6 +24,9 @@ def wms(): print("Placing a new order") order = get_order.get_order() process_order.process_order(order) + case "customer_order": + print("Checking a customer's order") + check_order.check_order() case "exit": exit()