Skip to content
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

Ensure favourites are added #76

Merged
merged 5 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ packages =
popups
gui
storage
db
python_requires = >=3.10
package_dir =
=src
Expand All @@ -32,4 +33,5 @@ design = py.typed
pages = py.typed
popups = py.typed
gui = py.typed
storage = py.typed
storage = py.typed
db = py.typed
2 changes: 2 additions & 0 deletions src/App.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from pages.TestPage import TestPage
from pages.TutorialPage import TutorialPage
from storage.Storage import Storage
from db.set_favourites import set_favourites

_APPLICATION_PATH = os.path.dirname(sys.executable)

Expand Down Expand Up @@ -62,6 +63,7 @@ def change_page(self, page: TPAGES) -> None:


def main() -> None:
set_favourites()
App().mainloop()


Expand Down
Empty file added src/db/__init__.py
Empty file.
14 changes: 14 additions & 0 deletions src/db/get_connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os
from contextlib import contextmanager
from typing import Generator
import sqlite3


_BASE_FILE = rf"C:\Users\{os.getenv('USERNAME')}\AppData\Local\SMXMobile"


@contextmanager
def get_connection(filename: str) -> Generator[sqlite3.Connection, None, None]:
connection = sqlite3.connect(rf"{_BASE_FILE}\{filename}.sdb")
yield connection
connection.close()
19 changes: 3 additions & 16 deletions src/gui/db_functions.py → src/db/get_items_jobs.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
import os
import sqlite3
from contextlib import contextmanager
from typing import Generator

from design.Item import Item
from design.Job import Job

_BASE_FILE = rf"C:\Users\{os.getenv('USERNAME')}\AppData\Local\SMXMobile"


@contextmanager
def _get_connection(filename: str) -> Generator[sqlite3.Connection, None, None]:
connection = sqlite3.connect(rf"{_BASE_FILE}\{filename}.sdb")
yield connection
connection.close()
from db.get_connection import get_connection


def get_items(item_number: str) -> list[Item]:
with _get_connection("SCMTests") as connection:
with get_connection("SCMTests") as connection:
item_fields = connection.execute(
"""
SELECT logical_name, description, model, manufacturer, serial_no_, room, last_update
Expand All @@ -31,7 +18,7 @@ def get_items(item_number: str) -> list[Item]:


def get_jobs(job_number: str) -> list[Job]:
with _get_connection("SCMLookup") as connection:
with get_connection("SCMLookup") as connection:
job_fields = connection.execute(
"""
SELECT company, location, dept, number
Expand Down
18 changes: 18 additions & 0 deletions src/db/set_favourites.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from db.get_connection import get_connection
from design.data import SCRIPTS


def set_favourites() -> None:
script_numbers = [(script.number,) for script in SCRIPTS.values()]
with get_connection("Settings") as connection:
with connection:
connection.execute("DELETE FROM ScriptFavourites")

with connection:
connection.executemany(
"""
INSERT INTO ScriptFavourites
VALUES (?)
""",
script_numbers,
)
1 change: 1 addition & 0 deletions src/design/Script.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def __init__(self, name: str, *options: str):
class Script:
nickname: str = field(hash=False, eq=False)
name: str
number: int = field(hash=False, eq=False)
tests: tuple[ScriptTest, ...] = field(factory=tuple, hash=False, eq=False)
exact_matches: list[str] = field(factory=list, kw_only=True, hash=False, eq=False)
search_terms: list[str] = field(factory=list, kw_only=True, hash=False, eq=False)
Expand Down
19 changes: 17 additions & 2 deletions src/design/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,27 @@
"CHANGE TILT TABLE": Script(
"CHANGE TILT TABLE",
"AT - CHANGE / TILT TABLE",
1278,
(_CASTORS_P, _FRAME_P, _PAINT_P, _LABELLING_P, _CHARGER_N, _BATTERY_N, _CONTROL_P, _CONDITION_1, _FURTHER_ATTENTION_N),
),
"SLING": Script(
"SLING",
"AT - SLING",
1261,
(_DETAILS_P, _GENERAL_WEAR_P, _STITCHING_P, _FITTINGS_P, _VELCRO_N, _LABELLING_P, _CONDITION_1),
exact_matches=["SLING", "PATIENT TRANSFER SLING, MECHANICAL LIFT"],
),
"WALKER": Script(
"WALKER",
"AT - WALKER / STANDER",
1279,
(_CASTORS_P, _CASTORS_P, _CASTORS_P, _FRAME_P, _HARDWARE_P, _PAINT_P, _OPERATION_P, _ATTACHMENTS_N, _LABELLING_P, _CONDITION_1, _FURTHER_ATTENTION_N),
search_terms=["WALK", "STAND", "STEDY"],
),
"CEILING HOIST": Script(
"CEILING",
"AT - CEILING HOIST",
1227,
(
_OPERATION_P,
_CONTROL_P,
Expand Down Expand Up @@ -124,22 +128,26 @@
"TRACK": Script(
"TRACK",
"AT - TRACK",
1287,
(_FEATURES_P, _TRACK_DUST_P, _CHARGER_N, _TRACK_LOAD_KG, _LOAD_TEST_P, _ELECTRIC_TEST_N),
exact_matches=["TRACK", "TRACK, CEILING HOIST", "CEILING TRACK"],
),
"COMMODE": Script(
"COMMODE",
"AT - COMMODE",
1228,
(_CASTORS_P, _FRAME_P, _PAINT_P, _OPERATION_P, _LABELLING_P, _CHARGER_N, _BATTERY_N, _CONTROL_P, _CONDITION_1),
),
"BED": Script(
"BED",
"AT - ELECTRIC BED",
1222,
(_CASTORS_P, _FRAME_P, _HARDWARE_P, _CONTROL_P, _PAINT_P, _OPERATION_P, _LABELLING_P, _CHARGER_N, _HELP_POLE_N, _CONDITION_1),
),
"FLOOR HOIST": Script(
"FLOOR",
"AT - FLOOR HOIST",
1226,
(
_CASTORS_P,
_VISUAL_P,
Expand Down Expand Up @@ -167,24 +175,28 @@
"RECLINER": Script(
"RECLINER",
"AT - LIFT RECLINER",
1223,
(_HARDWARE_P, _ACTUATOR_P, _CONTROL_P, _FRAME_P, _PAINT_P, _OPERATION_P, _LABELLING_P, _BATTERY_N, _POWER_P, _CONDITION_1),
),
"TUB": Script(
"TUB",
"AT - TUB / BATH CHAIRS",
1230,
(_CASTORS_P, _FRAME_P, _PAINT_P, _OPERATION_P, _LABELLING_P, _CHARGER_N, _BATTERY_N, _CONTROL_P, _CONDITION_1),
search_terms=["BATH"],
exact_matches=["BATH BED"],
),
"SCALE": Script(
"SCALE",
"AT - WEIGH CHAIR / SCALE",
1229,
(_CASTORS_P, _FRAME_P, _PAINT_P, _OPERATION_P, _LABELLING_P, _CHARGER_N, _BATTERY_P, _ACCURACY_P, _CONDITION_1),
search_terms=["WEIGH"],
),
"WHEELCHAIR": Script(
"WHEELCHAIR",
"AT - WHEELCHAIR",
1113,
(
_CASTORS_P,
_CASTORS_P,
Expand Down Expand Up @@ -212,21 +224,24 @@
"CHARGER": Script(
"CHARGER",
"BATTERY OPERATED / VISUAL TEST",
859,
(_BATTERY_N, _CONTROL_P, _VISUAL_P, _ATTACHMENTS_N),
),
"BATTERY": Script("BATTERY", "BATTERY PACK", (_VISUAL_P, _CAPACITY_P, _DATE_P)),
"BATTERY": Script("BATTERY", "BATTERY PACK", 1065, (_VISUAL_P, _CAPACITY_P, _DATE_P)),
"CLASS II": Script(
"CLASS II",
"CLASS II NO APPLIED PARTS",
606,
(_MAINS_P, _FUSES_P, _CONTROL_P, _BATTERY_N, _VISUAL_P, _ATTACHMENTS_N, _EARTH_RESISTANCE, _INSULATION_RESISTANCE, _INSULATION_RESISTANCE_ENCLOSURE, _TOUCH_CURRENT, _IEC_MAINS_LEAD),
),
"FURNITURE": Script(
"FURNITURE",
"FURNITURE GENERIC",
799,
(_CHASIS_P, _CASTORS_P, _CASTORS_P, _PAINT_P, _CASTORS_P, _MISSING_COMPONENTS_N, _POLES_P, _CLEAN_P, _ELECTRIC_N, _PERFORMANCE_P),
search_terms=["OVERBED"],
),
"VISUAL": Script("VISUAL", "VISUAL INSPECTION ONLY", (_INTEGRITY_P, _ACCESSORIES_P)),
"VISUAL": Script("VISUAL", "VISUAL INSPECTION ONLY", 1190, (_INTEGRITY_P, _ACCESSORIES_P)),
}

SCRIPT_DOWNS: dict[str, int] = {script.nickname: i for i, script in enumerate(SCRIPTS.values())}
1 change: 0 additions & 1 deletion src/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@
get_click_position,
get_selected_text,
)
from gui.db_functions import get_items, get_jobs
2 changes: 1 addition & 1 deletion src/pages/TestPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from design.Test import TEST_RESULTS, ScriptError, Test
from design.TestJob import TestJob
from gui.actions import complete_test, turn_off_capslock
from gui.db_functions import get_items
from db.get_items_jobs import get_items
from pages.Page import Page
from popups.ScriptSelectionPopup import ScriptSelectionPopup
from popups.TestJobPopup import TestJobPopup
Expand Down
2 changes: 1 addition & 1 deletion src/popups/JobEntryPopup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from tkinter import Misc, StringVar, ttk
from typing import Callable
from design.Job import Job
from gui.db_functions import get_jobs
from db.get_items_jobs import get_jobs
from popups.Popup import Popup
from popups.OptionSelectPopup import OptionSelectPopup

Expand Down
4 changes: 2 additions & 2 deletions src/storage/Storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def keys(cls) -> KeysView[Any]:
return cls.__annotations__.keys()

@classmethod
def from_dict(cls, data: Mapping[str, tuple[int, int]]) -> 'Positions':
def from_dict(cls, data: Mapping[str, tuple[int, int]]) -> "Positions":
return cls(**data)


Expand Down Expand Up @@ -61,7 +61,7 @@ def _save(self) -> None:
json.dump(data, file, indent=4)

@contextmanager
def edit(self) -> Generator['Storage', None, None]:
def edit(self) -> Generator["Storage", None, None]:
try:
yield self
finally:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from gui.db_functions import get_items, get_jobs
from db.get_items_jobs import get_items, get_jobs


class JobMock:
Expand Down
6 changes: 3 additions & 3 deletions testing/design/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ def test_job_add_test() -> None:
test1 = Test(Item("001", "Test Item 1", "ModelX", "ManufacturerX", "XYZ001", "RM1", "2019"))
test2 = Test(Item("002", "Test Item 2", "ModelY", "ManufacturerY", "XYZ002", "RM1", "2019"))

custom1 = Script("Custom1", "Custom Script", (), exact_matches=["Test Item 1"])
custom1 = Script("Custom1", "Custom Script", 1, (), exact_matches=["Test Item 1"])
SCRIPTS["Custom1"] = custom1
test1.script = test1.determine_script()
custom2 = Script("Custom2", "Custom Script", (), exact_matches=["Test Item 2"])
custom2 = Script("Custom2", "Custom Script", 1, (), exact_matches=["Test Item 2"])
SCRIPTS["Custom2"] = custom2
test2.script = test2.determine_script()

Expand All @@ -40,7 +40,7 @@ def test_job_add_test() -> None:


def test_job_remove_test() -> None:
custom1 = Script("Custom1", "Custom Script", (), exact_matches=["Test Item 1"])
custom1 = Script("Custom1", "Custom Script", 1, (), exact_matches=["Test Item 1"])
SCRIPTS["Custom1"] = custom1
test1 = Test(Item("001", "Test Item 1", "ModelX", "ManufacturerX", "XYZ001", "RM1", "2019"))
test1.script = test1.determine_script()
Expand Down
17 changes: 9 additions & 8 deletions testing/design/test_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,26 @@


def test_script_creation() -> None:
script = Script("Nick", "Script Name")
script = Script("Nick", "Script Name", 1)
assert script.nickname == "Nick"
assert script.name == "Script Name"
assert script.number == 1
assert len(script.tests) == 0
assert script.search_terms == ["Nick"]


def test_script_creation_with_tests() -> None:
test1 = ScriptTest("Test 1", "Pass", "Fail")
test2 = ScriptTest("Test 2", "N/A", "Yes", "No")
script = Script("Nickname", "Test Script", (test1, test2))
script = Script("Nickname", "Test Script", 1, (test1, test2))
assert script.nickname == "Nickname"
assert script.name == "Test Script"
assert len(script.tests) == 2
assert script.search_terms == ["Nickname"]


def test_script_creation_with_extra_terms() -> None:
script = Script("UniqueNick", "Unique Script", search_terms=["tag1", "tag2"])
script = Script("UniqueNick", "Unique Script", 1, search_terms=["tag1", "tag2"])
assert script.nickname == "UniqueNick"
assert script.name == "Unique Script"
assert len(script.tests) == 0
Expand All @@ -41,19 +42,19 @@ def test_script_creation_with_extra_terms() -> None:
],
)
def test_script_matches(match_description: str, expected: bool) -> None:
script = Script("Tester", "Matching Script", search_terms=["tag3"])
script = Script("Tester", "Matching Script", 1, search_terms=["tag3"])
assert script.is_for(match_description) == expected


def test_script_to_string() -> None:
script = Script("MyNick", "Awesome Script")
script = Script("MyNick", "Awesome Script", 1)
assert str(script) == "Awesome Script"


def test_hash_and_eq() -> None:
script1 = Script("Nick1", "Script 1")
script2 = Script("Nick2", "Script 2")
script3 = Script("Nick3", "Script 1")
script1 = Script("Nick1", "Script 1", 1)
script2 = Script("Nick2", "Script 2", 1)
script3 = Script("Nick3", "Script 1", 1)
assert len({script1, script2}) == 2
assert len({script1, script3}) == 1
assert hash(script1) != hash(script2)
Expand Down
6 changes: 3 additions & 3 deletions testing/design/test_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_test_determine_script() -> None:
test = Test(item)

# Adding a custom script for testing
custom_script = Script("CustomScript", "Custom Script")
custom_script = Script("CustomScript", "Custom Script", 1)
SCRIPTS["CustomScript"] = custom_script

test.script = custom_script
Expand Down Expand Up @@ -57,7 +57,7 @@ def test_test_complete_and_full_info() -> None:
item = Item("001", "Test Item", "ModelX", "ManufacturerX", "XYZ001", "RM1", "2019")
test = Test(item)

custom = Script("CustomScript", "Custom Script", (), exact_matches=["Test Item"])
custom = Script("CustomScript", "Custom Script", 1, (), exact_matches=["Test Item"])
SCRIPTS["CustomScript"] = custom
test.script = test.determine_script()
assert test.script.nickname == "CustomScript"
Expand All @@ -76,6 +76,6 @@ def test_test_complete_and_full_info() -> None:
def test_test_item_model_property() -> None:
item = Item("001", "Test Item", "ModelX", "ManufacturerX", "XYZ001", "RM1", "2019")
test = Test(item)
test.script = Script("CustomScript", "Custom Script")
test.script = Script("CustomScript", "Custom Script", 1)

assert test.item_model == "Custom Script -> ModelX"