generated from neutrons/python_project_template
-
Notifications
You must be signed in to change notification settings - Fork 4
frontend focused load raw scan from a folder #57
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c7ca32f
frontend focused load raw scan from a folder
KyleQianliMa b6db046
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 3993b1a
unit test for load view
KyleQianliMa 4529422
ruff fix
KyleQianliMa 37906f7
add comment
KyleQianliMa 8bffc0d
update read the doc general description.
KyleQianliMa 3e19d8f
tavi_classes
KyleQianliMa 6444b05
more clean ups
KyleQianliMa f0a8ff2
update names and docs
KyleQianliMa 0f62620
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a4860b0
fix unit tests
KyleQianliMa a78ddc2
comment event broker
KyleQianliMa cc99a9d
renaming taviproject to taviprojectmodel
KyleQianliMa ebdbdba
small adjustments for naming consistency
KyleQianliMa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -79,6 +79,7 @@ ignore = [ | |
| "ARG002", | ||
| "ARG004", | ||
| "F821", | ||
| "D401", | ||
| "N801", | ||
| "N802", | ||
| "N806", | ||
|
|
||
This file contains hidden or 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 was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
src/tavi/backend/model/interface/tavi_project_interface.py
This file contains hidden or 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,17 @@ | ||
| """Tavi project interface.""" | ||
|
|
||
| import abc | ||
|
|
||
| from tavi.meta.multithreading.proxy import Proxy | ||
|
|
||
|
|
||
| class TaviProjectInterface(metaclass=abc.ABCMeta): | ||
| """Tavi project interface.""" | ||
|
|
||
| @abc.abstractmethod | ||
| def load_raw_scan_from_folder(self) -> None: | ||
| """Abstract method to get tavi data.""" | ||
| pass | ||
|
|
||
|
|
||
| TaviProjectProxy = Proxy(TaviProjectInterface) |
This file contains hidden or 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 @@ | ||
| """Tavi Project.""" | ||
|
|
||
| from tavi.backend.model.interface.tavi_project_interface import TaviProjectInterface | ||
| from tavi.event_broker.event_broker import EventBroker | ||
| from tavi.event_broker.event_type import Event | ||
| from tavi.library.data.model_response import ModelResponse, ResponseCode | ||
| from tavi.meta.decorators.singleton import Singleton | ||
|
|
||
|
|
||
| @Singleton | ||
| class TaviProjectModel(TaviProjectInterface): | ||
| """Tavi project class.""" | ||
|
|
||
| def __init__(self) -> None: | ||
| """Init tavi data.""" | ||
| self._event_broker = EventBroker() | ||
|
|
||
| def send(self, event: Event) -> None: | ||
| """Send pre-register event to event broker.""" | ||
| self._event_broker.publish(event) | ||
|
|
||
| def load_raw_scan_from_folder(self, folder: str) -> None: | ||
| """Load a folder containing raw scans.""" | ||
| print("folder director received by model:", folder) | ||
| # TO DO | ||
| # Implement load raw scan from folder logic | ||
| # raw_scan_loading_event = RawScanLoadingEvent(raw_scan_uuid = ...) | ||
| # self.send(raw_scan_loading_event) | ||
| return ModelResponse(code=ResponseCode.OK, message="TODO: implement loading backend") |
This file contains hidden or 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,32 @@ | ||
| """ | ||
| Event broker class. | ||
|
|
||
| Stub implementation, will be updated. | ||
|
|
||
| """ | ||
|
|
||
| from collections import defaultdict | ||
| from typing import Any, Literal | ||
|
|
||
| from tavi.meta.decorators.singleton import Singleton | ||
|
|
||
|
|
||
| @Singleton | ||
| class EventBroker: | ||
| """Event broker class.""" | ||
|
|
||
| def __init__(self) -> None: | ||
| """Initialize event broker.""" | ||
| if not hasattr(self, "registry"): | ||
| self.registry = defaultdict(list) | ||
|
|
||
| def register(self, event_type: Any, callable: Literal["event_type"]) -> None: | ||
| """Register event with the broker.""" | ||
| self.registry[event_type].append(callable) | ||
|
|
||
| def publish(self, event: Any) -> None: | ||
| """Publish event to the broker.""" | ||
| event_type = type(event) | ||
| if callable_list := self.registry.get(event_type): | ||
| for callable in callable_list: | ||
| callable(event) | ||
This file contains hidden or 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,16 @@ | ||
| """Define event type here.""" | ||
|
|
||
| from attr import dataclass | ||
|
|
||
|
|
||
| class Event: | ||
| """Docstring for Event.""" | ||
|
|
||
| pass | ||
|
|
||
|
|
||
| @dataclass | ||
| class RawScanLoadingEvent(Event): | ||
| """loading raw data event.""" | ||
|
|
||
| raw_scan_uuid: list[str] |
This file contains hidden or 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 hidden or 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,44 @@ | ||
| """Load raw scan presenter.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING | ||
|
|
||
| from tavi.event_broker.event_broker import EventBroker | ||
| from tavi.event_broker.event_type import RawScanLoadingEvent | ||
|
|
||
| if TYPE_CHECKING: | ||
| from tavi.backend.model.interface.tavi_project_interface import TaviProjectInterface | ||
| from tavi.frontend.view.load_raw_scan_view import LoadView | ||
|
|
||
|
|
||
| class LoadRawScanPresenter: | ||
| """ | ||
| Presenter responsible for data loading. | ||
|
|
||
| Mediating dataloading-related updates between the | ||
| model (`TaviProjectInterface`) and the load_raw_scan_view (`LoadView`). | ||
|
|
||
| Attributes | ||
| ---------- | ||
| _view : LoadView | ||
| The load view associated with this presenter. | ||
| _model : TaviProjectInterface | ||
| The model providing metadata updates. | ||
| event_broker : EventBroker | ||
| The event system used to subscribe to different loading data update events. | ||
|
|
||
| """ | ||
|
|
||
| def __init__(self, view: LoadView, model: TaviProjectInterface) -> None: | ||
| """Initialize the metadata presenter and register for `meta_data` events.""" | ||
| super().__init__() | ||
| self._view = view | ||
| self._model = model | ||
| self.event_broker = EventBroker() | ||
| self.event_broker.register(RawScanLoadingEvent, self.update_treeview_data) | ||
|
|
||
| def update_treeview_data(self, event: RawScanLoadingEvent) -> None: | ||
| """Update the treeview GUI after loading complete.""" | ||
| # TODO: implement rules to display tavi data after backend story | ||
| print("TODO: Implement rules to display loaded data after backend story.") |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like I was saying at status, there are a couple more features outlined in the EventBroker ticket that the prototype did not implement. You can view my additions here. I still need to write tests for it.
Seeing as the event broker is to be implemented in a different ticket, could you mark this as a stub implementation? I dont see any unit tests written for this explicitly, which is fine, that will be added as part of the event broker ticket.