From 914e5b4e50cb253134bbdb6f871c61d3a4e15758 Mon Sep 17 00:00:00 2001 From: Albert Date: Sat, 29 Mar 2025 22:31:55 +0100 Subject: [PATCH 1/5] fjerner __pyachce__, fra repo tracking --- .gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 641a18d..362aeb3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ result result-* - +**/__pycache__ dist test.db -.ruff_cache \ No newline at end of file +.ruff_cache From 4f89765070256dbfd79577c3f774290d8b53f337 Mon Sep 17 00:00:00 2001 From: Albert Date: Sat, 29 Mar 2025 22:42:36 +0100 Subject: [PATCH 2/5] ignorer bifiler fra hatchling --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 362aeb3..26bf605 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ result result-* **/__pycache__ +dibbler.egg-info dist test.db From b2a6384f31ed2a740f75fff28db3a6b65f9f19cf Mon Sep 17 00:00:00 2001 From: Albert Date: Sat, 29 Mar 2025 22:46:30 +0100 Subject: [PATCH 3/5] la tilbake uv, en project manager --- nix/shell.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nix/shell.nix b/nix/shell.nix index fadb097..7c93f0f 100644 --- a/nix/shell.nix +++ b/nix/shell.nix @@ -2,11 +2,13 @@ mkShell, python, ruff, + uv, }: mkShell { packages = [ ruff + uv (python.withPackages (ps: with ps; [ brother-ql matplotlib From e69d04dcd03276115461b0c59c8813ea9ddca65c Mon Sep 17 00:00:00 2001 From: Albert Date: Sat, 29 Mar 2025 22:48:30 +0100 Subject: [PATCH 4/5] mock script, og mock data. --- dibbler/main.py | 7 +++ dibbler/subcommands/seed_test_data.py | 38 ++++++++++++++ mock_data.json | 76 +++++++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 dibbler/subcommands/seed_test_data.py create mode 100644 mock_data.json diff --git a/dibbler/main.py b/dibbler/main.py index bd0c424..c9af841 100644 --- a/dibbler/main.py +++ b/dibbler/main.py @@ -20,6 +20,7 @@ subparsers = parser.add_subparsers( subparsers.add_parser("loop", help="Run the dibbler loop") subparsers.add_parser("create-db", help="Create the database") subparsers.add_parser("slabbedasker", help="Find out who is slabbedasker") +subparsers.add_parser("seed-data",help="Fill with mock data") def main(): @@ -40,6 +41,12 @@ def main(): import dibbler.subcommands.slabbedasker as slabbedasker slabbedasker.main() + + elif args.subcommand == "seed-data": + import dibbler.subcommands.seed_test_data as seed_test_data + + seed_test_data.main() + if __name__ == "__main__": diff --git a/dibbler/subcommands/seed_test_data.py b/dibbler/subcommands/seed_test_data.py new file mode 100644 index 0000000..8c1b2f3 --- /dev/null +++ b/dibbler/subcommands/seed_test_data.py @@ -0,0 +1,38 @@ +import json +from dibbler.db import Session + +from pathlib import Path + +from dibbler.models.Product import Product + +from dibbler.models.User import User + +JSON_FILE = Path(__file__).parent.parent.parent/"mock_data.json" + + +def clear_db(session): + session.query(Product).delete() + session.query(User).delete() + session.commit() + + +def main() : + session = Session() + clear_db(session) + product_items = [] + user_items = [] + + with open(JSON_FILE) as f: + json_obj = json.load(f) + + for product in json_obj["products"]: + product_item = Product(bar_code=product["bar_code"], name=product["name"], price=product["price"], stock=product["stock"]) + product_items.append(product_item) + + for user in json_obj["users"]: + user_item = User(name=user ["name"], card=user [ "card" ], rfid=user [ "rfid" ], credit=user ["credit"]) + user_items.append(user_item) + + session.add_all(product_items) + session.add_all(user_items) + session.commit() diff --git a/mock_data.json b/mock_data.json new file mode 100644 index 0000000..7e36703 --- /dev/null +++ b/mock_data.json @@ -0,0 +1,76 @@ +{ + "products": [ + { + "product_id": 1, + "bar_code": "1234567890123", + "name": "Wireless Mouse", + "price": 2999, + "stock": 150, + "hidden": false + }, + { + "product_id": 2, + "bar_code": "9876543210987", + "name": "Mechanical Keyboard", + "price": 5999, + "stock": 75, + "hidden": false + }, + { + "product_id": 3, + "bar_code": "1112223334445", + "name": "Gaming Monitor", + "price": 19999, + "stock": 20, + "hidden": false + }, + { + "product_id": 4, + "bar_code": "5556667778889", + "name": "USB-C Docking Station", + "price": 8999, + "stock": 50, + "hidden": true + }, + { + "product_id": 5, + "bar_code": "4445556667771", + "name": "Noise Cancelling Headphones", + "price": 12999, + "stock": 30, + "hidden": true + } + ], + "users": [ + { + "name": "Albert", + "credit": 42069, + "card": "NTU12345678", + "rfid": "a1b2c3d4e5" + }, + { + "name": "lorem", + "credit": 2000, + "card": "9876543210", + "rfid": "f6e7d8c9b0" + }, + { + "name": "ibsum", + "credit": 1000, + "card": "11122233", + "rfid": "" + }, + { + "name": "dave", + "credit": 7500, + "card": "NTU56789012", + "rfid": "1234abcd5678" + }, + { + "name": "eve", + "credit": 3000, + "card": null, + "rfid": "deadbeef1234" + } + ] +} From a654baba115dada7e5bc1f9d98de3cd604ae71ba Mon Sep 17 00:00:00 2001 From: h7x4 Date: Sun, 30 Mar 2025 21:44:37 +0200 Subject: [PATCH 5/5] ruff format --- dibbler/lib/statistikkHelpers.py | 8 ++------ dibbler/main.py | 5 ++--- dibbler/menus/buymenu.py | 2 +- dibbler/models/__init__.py | 14 +++++++------- dibbler/subcommands/seed_test_data.py | 20 +++++++++++++++----- 5 files changed, 27 insertions(+), 22 deletions(-) diff --git a/dibbler/lib/statistikkHelpers.py b/dibbler/lib/statistikkHelpers.py index 80ea886..0441aec 100644 --- a/dibbler/lib/statistikkHelpers.py +++ b/dibbler/lib/statistikkHelpers.py @@ -76,12 +76,8 @@ class Database: personDatoVerdi = defaultdict(list) # dict->array personUkedagVerdi = defaultdict(list) # for global - personPosTransactions = ( - {} - ) # personPosTransactions[trygvrad] == 100 #trygvrad har lagt 100kr i boksen - personNegTransactions = ( - {} - ) # personNegTransactions[trygvrad» == 70 #trygvrad har tatt 70kr fra boksen + personPosTransactions = {} # personPosTransactions[trygvrad] == 100 #trygvrad har lagt 100kr i boksen + personNegTransactions = {} # personNegTransactions[trygvrad» == 70 #trygvrad har tatt 70kr fra boksen globalVareAntall = {} # globalVareAntall[Oreo] == 3 globalVareVerdi = {} # globalVareVerdi[Oreo] == 30 #[kr] globalPersonAntall = {} # globalPersonAntall[trygvrad] == 3 diff --git a/dibbler/main.py b/dibbler/main.py index c9af841..f7c459f 100644 --- a/dibbler/main.py +++ b/dibbler/main.py @@ -20,7 +20,7 @@ subparsers = parser.add_subparsers( subparsers.add_parser("loop", help="Run the dibbler loop") subparsers.add_parser("create-db", help="Create the database") subparsers.add_parser("slabbedasker", help="Find out who is slabbedasker") -subparsers.add_parser("seed-data",help="Fill with mock data") +subparsers.add_parser("seed-data", help="Fill with mock data") def main(): @@ -41,13 +41,12 @@ def main(): import dibbler.subcommands.slabbedasker as slabbedasker slabbedasker.main() - + elif args.subcommand == "seed-data": import dibbler.subcommands.seed_test_data as seed_test_data seed_test_data.main() - if __name__ == "__main__": main() diff --git a/dibbler/menus/buymenu.py b/dibbler/menus/buymenu.py index acb534e..05be7f9 100644 --- a/dibbler/menus/buymenu.py +++ b/dibbler/menus/buymenu.py @@ -180,7 +180,7 @@ When finished, write an empty line to confirm the purchase.\n""" print(f"User {t.user.name}'s credit is now {t.user.credit:d} kr") if t.user.credit < config.getint("limits", "low_credit_warning_limit"): print( - f'USER {t.user.name} HAS LOWER CREDIT THAN {config.getint("limits", "low_credit_warning_limit"):d},', + f"USER {t.user.name} HAS LOWER CREDIT THAN {config.getint('limits', 'low_credit_warning_limit'):d},", "AND SHOULD CONSIDER PUTTING SOME MONEY IN THE BOX.", ) diff --git a/dibbler/models/__init__.py b/dibbler/models/__init__.py index 20999e9..9cd0325 100644 --- a/dibbler/models/__init__.py +++ b/dibbler/models/__init__.py @@ -1,11 +1,11 @@ __all__ = [ - 'Base', - 'Product', - 'Purchase', - 'PurchaseEntry', - 'Transaction', - 'User', - 'UserProducts', + "Base", + "Product", + "Purchase", + "PurchaseEntry", + "Transaction", + "User", + "UserProducts", ] from .Base import Base diff --git a/dibbler/subcommands/seed_test_data.py b/dibbler/subcommands/seed_test_data.py index 8c1b2f3..07454ea 100644 --- a/dibbler/subcommands/seed_test_data.py +++ b/dibbler/subcommands/seed_test_data.py @@ -5,9 +5,9 @@ from pathlib import Path from dibbler.models.Product import Product -from dibbler.models.User import User +from dibbler.models.User import User -JSON_FILE = Path(__file__).parent.parent.parent/"mock_data.json" +JSON_FILE = Path(__file__).parent.parent.parent / "mock_data.json" def clear_db(session): @@ -16,7 +16,7 @@ def clear_db(session): session.commit() -def main() : +def main(): session = Session() clear_db(session) product_items = [] @@ -26,11 +26,21 @@ def main() : json_obj = json.load(f) for product in json_obj["products"]: - product_item = Product(bar_code=product["bar_code"], name=product["name"], price=product["price"], stock=product["stock"]) + product_item = Product( + bar_code=product["bar_code"], + name=product["name"], + price=product["price"], + stock=product["stock"], + ) product_items.append(product_item) for user in json_obj["users"]: - user_item = User(name=user ["name"], card=user [ "card" ], rfid=user [ "rfid" ], credit=user ["credit"]) + user_item = User( + name=user["name"], + card=user["card"], + rfid=user["rfid"], + credit=user["credit"], + ) user_items.append(user_item) session.add_all(product_items)