diff --git a/docs/source/design/index.rst b/docs/source/design/index.rst index 771c515..84e9b16 100644 --- a/docs/source/design/index.rst +++ b/docs/source/design/index.rst @@ -17,6 +17,7 @@ Contents instrument reduction_plan + reduction_plan_mvp oncat oncat_general oncat_mvp diff --git a/docs/source/design/instrument.rst b/docs/source/design/instrument.rst index cecc34f..5208f81 100644 --- a/docs/source/design/instrument.rst +++ b/docs/source/design/instrument.rst @@ -1,6 +1,6 @@ .. _instrument: -Instrument Schema +Instrument Model ======================= The Instrument model is described in `Data Dictionary Instrument Configuration `_. @@ -8,8 +8,8 @@ The Instrument model is described in `Data Dictionary Instrument Configuration < .. mermaid:: classDiagram - InstrumentModel "1" o--"3" InstrumentProjectionFieldModel: grouping_field,run_number_field, scale_field - InstrumentModel "1" o--"N<=3" InstrumentGoniometerAngleModel + InstrumentModel "1" *--"3" InstrumentProjectionFieldModel: grouping_field,run_number_field, scale_field + InstrumentModel "1" *--"N<=3" InstrumentGoniometerAngleModel class InstrumentModel{ +String facility @@ -19,6 +19,7 @@ The Instrument model is described in `Data Dictionary Instrument Configuration < +String raw_file_format +List~InstrumentGoniometerAngleModel~ goniometer_settings +List~InstrumentProjectionFieldModel~ run_schema + +create() } class InstrumentGoniometerAngleModel{ @@ -33,3 +34,5 @@ The Instrument model is described in `Data Dictionary Instrument Configuration < +String field_name +String oncat_meta_field } + +The Instrument is created from the InstrumentConfiguration Settings. diff --git a/docs/source/design/oncat.rst b/docs/source/design/oncat.rst index 79e3d26..1534cc9 100644 --- a/docs/source/design/oncat.rst +++ b/docs/source/design/oncat.rst @@ -1,6 +1,6 @@ .. _pyoncat: -PyOnCat Schema +PyOnCat Model =================== The PyOnCat is described in `Data Dictionary OnCat `_ . @@ -19,17 +19,20 @@ Related APIS: PyOnCatModel "1" o--"N" ExperimentModel ExperimentModel "1" o--"N" RunModel PyOnCatModel "1" -->"1" InstrumentModel - RunModel "1" o--"N<=3" GoniometerAngleKeyValueModel - RunModel "1" o--"3" ProjectionFieldKeyValueModel + RunModel "1" *--"N<=3" GoniometerAngleKeyValueModel + RunModel "1" *--"3" ProjectionFieldKeyValueModel class PyOnCatModel{ +InstrumentModel instrument -PyOnCat:ONCat oncat_agent +String data_source_filepath - +ExperimentModel selected_experiment + +Number selected_experiment_index +List~ExperimentModel~ experiment_list +get_experiments() - + +add_agent() + +add_instrument() + +select_experiment() + +add_datasource_filepath() } class InstrumentModel{ <> @@ -39,6 +42,7 @@ Related APIS: +String ipts_number +List~RunModel~ run_list +get_run_list() + +calculate_run_plot() } diff --git a/docs/source/design/oncat_general.rst b/docs/source/design/oncat_general.rst index 1cef2a3..a53e946 100644 --- a/docs/source/design/oncat_general.rst +++ b/docs/source/design/oncat_general.rst @@ -20,7 +20,7 @@ Related APIS: PyOnCatModel "1" o--"N" ExperimentModel ExperimentModel "1" o--"N" RunModel PyOnCatModel "1" -->"1" InstrumentModel - RunModel "1" o--"N<=170" ProjectionFieldKeyValueModel + RunModel "1" *--"N<=170" ProjectionFieldKeyValueModel class PyOnCatModel{ +InstrumentModel instrument diff --git a/docs/source/design/oncat_mvp.rst b/docs/source/design/oncat_mvp.rst index 3a73648..39090d0 100644 --- a/docs/source/design/oncat_mvp.rst +++ b/docs/source/design/oncat_mvp.rst @@ -1,21 +1,25 @@ -.. _pyocat_mvp: +.. _pyoncat_mvp: PyOnCat Model-View-Presenter -======================================== +============================== The data, graphical interface and functionality components related to OnCat are described here. The related code is organized in Model-View-Presenter pattern. -The Model is described in detail :ref:`PyOnCatSchema `. -The View is described below: +PyOnCat +-------- -(The ReductionPlanWidget contains only elements relevant to pyoncat data.) +The Model is described in detail :ref:`PyOnCatModel `. + +View related to PyOnCat +------------------------ + +The ReductionPlanWidget contains only elements relevant to pyoncat data. .. mermaid:: classDiagram ReductionPlanWidget "1" -->"1" RunsWidget - ReductionPlanWidget "1" -->"1" GoniometerWavelengthWidget ReductionPlanWidget "1" -->"1" DataSourceWidget class ReductionPlanWidget{ @@ -23,7 +27,6 @@ The View is described below: +QComboBox:instrument +DataSourceWidget:data_source +RunsWidget:runs - +GoniometerWavelengthWidget:goniometer } class DataSourceWidget{ @@ -33,6 +36,7 @@ The View is described below: +QButton-QFileDialog: file_browse_btn +get_user_credentials() +display_oncat_connection_status() + +validate_full_path_format() } class RunsWidget{ @@ -43,25 +47,18 @@ The View is described below: +QLabel:run_range_display +QLineEdit:run_range +Mantidqt:run_plot - +display_experiments() - +display_grouped_runs() + +display_experiments_for_instrument() + +display_grouped_runs_for_experiment() +display_plot_data() +get_selected_run_range() +get_selected_experiment() + +validate_run_ranges_format() } +Presenter related to PyOnCat +----------------------------- - class GoniometerWavelengthWidget{ - +QLabel:goniometer_table_display - +QTableWidget:goniometer_table - +QLabel:wavelength_display - +QLineEdit~1|2~:wavelength - } - - - - -The Presenter is described below. It is connected with one model and view. +The Presenter is described below. .. mermaid:: @@ -70,96 +67,185 @@ The Presenter is described below. It is connected with one model and view. -model -view +login(username,password) - +handle_connection_status() - +set_data_source_filepath(filepath) - +set_instrument(instrument) - +show_experiments(instrument) - +set_experiment(experiment) - +show_grouped_runs(instrument,experiments) - +set_run_range(run_range) - +show_plot() + +handle_oncat_connection(username,password) + +handle_datasource_filepath(filepath) + +handle_instrument_selection(instrument) + +handle_experiment_selection(experiment) + +update_grouped_runs(use_cached_runs=True) + +handle_run_selection(run_range) } +Through this component that can is part of the ReductionPlanTab, the users retrieve data about experiments and runs +by either connecting to OnCat or navigating to a directory in their local environment (directory format). The +following are supported and their interactions afre described in detail in the next section: -The M-V-P interactions are described and grouped by functionality: - -DataSource Initialization - Connect to OnCat + * OnCat connection/login dialog + * Access data with OnCat and by going through the files of a user-specified folder + * List of Experiments per instrument with and without OnCat connection + * List of Runs per experiment with and without OnCat connection + * Run meta data retrieval with and without OnCat connection + * Group run per specific field and display them + * Retrieve grouped run per user's trigger-button + * Plot creation based on the run meta data, when user is connected to OnCat -.. mermaid:: - - sequenceDiagram - participant View - participant Presenter - participant Model - - Note over View,Model: Login - View->>Presenter: User provides credentials - Presenter->>View: Get user credentials - Presenter->>Model: Send user credentials - Note right of Model: Store pyoncat agent - Model->>Presenter: Return pyoncat agent - - Note over View,Model: Handle oncat connection status - Presenter->>Model: Get pyoncat agent - Model->>Presenter: Return pyoncat agent - Presenter->>View: Display oncat connection status +The experiments and runs are retrieved and saved on User-requested base on the current instrument and experiment selection. +The danger here, would be that if the user, keeps selecting instrument and experiments, the data will be stored in the backed and thus increasing the application's memory usage. +.. _oncat_mvpi: -DataSource Initialization - Absolute Path -.. mermaid:: - - sequenceDiagram - participant View - participant Presenter - participant Model +M-V-P Interactions +-------------------- - Note over View,Model: Set Data Source FilePath - View->>Presenter: User selects file folder - Presenter->>View: Get filepath - Presenter->>Model: Send filepath - Note right of Model: Store filepath +The M-V-P interactions are described and grouped by major functionality: +#. DataSource Initialization - Connect to OnCat: handle_oncat_connection(username, password) -Data fetch and display - -.. mermaid:: + .. mermaid:: + + sequenceDiagram + participant View + participant Presenter + participant Model + + Note over View,Model: Handle OnCat Connection + Note over View,Model: Login + View->>Presenter: User provides credentials + Presenter->>View: Get user credentials + Presenter->>Model: Send user credentials + Note right of Model: Store pyoncat agent + Model->>Presenter: Return pyoncat agent + + Note over View,Model: Get connection status + Presenter->>Model: Get pyoncat agent + Model->>Presenter: Return pyoncat agent + Presenter->>View: Display oncat connection status - sequenceDiagram - participant View - participant Presenter - participant Model - - Note over View,Model: Set Instrument - View->>Presenter: User selects instrument - Presenter->>View: Get instrument - Presenter->>Model: Send instrument - Note right of Model: Store instrument - - Note over View,Model: Show experiments - Presenter->>Model: Get experiments for instrument - Presenter->>View: Display experiments - - Note over View,Model: Set experiment - View->>Presenter: User selects experiment - Presenter->>View: Get experiment - Presenter->>Model: Send experiment - Note right of Model: Store experiment - - Note over View,Model: Show grouped runs - Presenter->>Model: Get grouped runs for an experiment - Note right of Model: Get run data and group runs by group field - Model->>Presenter: Return grouped runs for an experiment - Presenter->>View: Display grouped runs - - Note over View,Model: Set run range - View->>Presenter: User sets run range - Presenter->>View: Get run range - Presenter->>Model: Send run range - Note right of Model: Store run range - - Note over View,Model: Show run-plot - Presenter->>Model: Get calculated plot data - Note right of Model: Calculate plot data - Model->>Presenter: Return calculated plot data - Presenter->>View: Display plot + +#. DataSource Initialization - Absolute Path: handle_datasource_filepath(filepath) + Note: The instrument should already be selected. + + #. FileBrowser + .. mermaid:: + + sequenceDiagram + participant View + participant Presenter + participant Model + + Note over View,Model: Handle Datasource Filepath + View->>Presenter: User selects file folder + Note left of View: Validate filepath format + Presenter->>View: Get filepath + Presenter->>Model: Send filepath + Note right of Model: Store filepath + Note right of Model: Generate and Store experiment + Model->>Presenter: Return experiment + Presenter->>View: Display experiment + Note over View,Model: Show grouped runs (see below) + + #. Filepath Type + .. mermaid:: + + sequenceDiagram + participant View + participant Presenter + participant Model + + Note over View,Model: Handle Datasource Filepath + View->>Presenter: User types file folder + Note left of View: Validate filepath format + Presenter->>View: Get filepath + Presenter->>Model: Send filepath + Note right of Model: Store filepath + Note right of Model: Generate and Store experiment + Model->>Presenter: Return experiment + Presenter->>View: Display experiment + Note over View,Model: Show grouped runs (see below) + + +#. Data fetch - Select Instrument: handle_instrument_selection(instrument) (partial flow). See :ref:`handle_instrument_selection ` for the full flow + + .. mermaid:: + + sequenceDiagram + participant View + participant Presenter + participant Model + + Note over View,Model: Handle Instrument Selection + View->>Presenter: User selects instrument + Presenter->>View: Get instrument + Presenter->>Model: Send instrument + Note right of Model: Store instrument + + Note over View,Model: Show experiments + Presenter->>Model: Get experiments for instrument + Note right of Model: Get experiment from OnCat, if it does not exist + Presenter->>View: Display experiments + + +#. Data fetch - Select Experiment: handle_experiment_selection(experiment) (partial flow). See :ref:`handle_experiment_selection ` for the full flow + + Users can retrieve runs either from OnCat or from a directory by reading each file separately. The later + might be memory and/or cpu intensive. We will have to include some TimeoutError exception or similar to avoid having the program hanging. + In that case the runs table will be empty. + + .. mermaid:: + + sequenceDiagram + participant View + participant Presenter + participant Model + Note over View,Model: Handle Experiment Selection + View->>Presenter: User selects experiment + Presenter->>View: Get experiment + Presenter->>Model: Send experiment + Note right of Model: Store experiment + Note right of Model: Generate and Store data source filepath + Model->>Presenter: Return data source filepath + Presenter->>View: Display data source filepath + + Note over View,Model: Update Grouped Runs (update_grouped_runs(use_cached_runs=True)) + Presenter->>Model: Get grouped runs for an experiment + Note right of Model: Get runs from OnCat/filepath folder, if they do not exist + Note right of Model: Store run data and group runs by group field + Model->>Presenter: Return grouped runs for an experiment + Presenter->>View: Display grouped runs + + +#. Data fetch - Select Run Range: handle_run_selection(run_range) + The plot is calculated and displayed only when the user is connected to OnCat, else it is left empty. + + .. mermaid:: + + sequenceDiagram + participant View + participant Presenter + participant Model + Note over View,Model: Handle Run Selection + View->>Presenter: User sets run range + Note left of View: Validate run range + Presenter->>View: Get run range + Presenter->>Model: Send run range + Note right of Model: Calculate plot data + Model->>Presenter: Return calculated plot data + Presenter->>View: Display plot + + +#. Data fetch - Refresh IPTS Runs: update_grouped_runs(use_cached_runs=False) + + .. mermaid:: + + sequenceDiagram + participant View + participant Presenter + participant Model + + Note over View,Model: Update Grouped Runs + View->>Presenter: User clicks the "Refresh IPTS Runs" button + Presenter->>Model: Get grouped runs for an experiment + Note right of Model: Get runs from OnCat/filepath folder + Note right of Model: Store run data and group runs by group field + Model->>Presenter: Return grouped runs for an experiment + Presenter->>View: Display grouped runs (see above) diff --git a/docs/source/design/reduction_plan.rst b/docs/source/design/reduction_plan.rst index fa2db11..67a3c95 100644 --- a/docs/source/design/reduction_plan.rst +++ b/docs/source/design/reduction_plan.rst @@ -1,6 +1,6 @@ .. _reduction_plan: -Reduction Plan Schema +Reduction Plan Model ======================= The Reduction Plan is described in `Data Dictionary Reduction Plan `_. @@ -11,15 +11,17 @@ The detailed Instrument model is found here :ref:`Intrument `. .. mermaid:: classDiagram - ReductionPlanModel "1" -->"1" InstrumentModel + ReductionPlanModel "N" -->"1" InstrumentModel ReductionPlanModel "1" *--"1" CalibrationModel ReductionPlanModel "1" *--"1" NormalizationModel class ReductionPlanModel{ + -String reduction_plan_id +String reduction_plan_name +InstrumentModel instrument +String experiment +String run_range + +List~Number~ wavelength +String mask_filepath +String background_filepath +String grouping @@ -28,6 +30,15 @@ The detailed Instrument model is found here :ref:`Intrument `. +CalibrationModel calibration +NormalizationModel vanadium +Mantid:OrientedLattice ub_matrix + +get() + +create() + +edit() + +delete() + //(backend validation rules) + +validate_mask() + +validate_background() + +validate_run_ranges() + +reduction_plan_filepath() } class InstrumentModel{ @@ -38,9 +49,64 @@ The detailed Instrument model is found here :ref:`Intrument `. class CalibrationModel{ +String detector_filepath +String tube_filepath + +get() + +create() + +edit() + +delete() + //(backend validation rules) + +validate_detector() + +validate_tube() } class NormalizationModel{ +String flux_filepath +String solid_angle_filepath + +get() + +create() + +edit() + +delete() + //(backend validation rules) + +validate_flux() + +validate_solid_angle() } + +The above validation functions check the following before the Reduction Plan creation: + + * whether the files exist and have the correct extension + * the run range files exist in the instrument/experiment filepath. + * the reduction plan filepath is unique. In case of a new reduction plan with an exisiting filepath warning message is sent to the user to ask whether they want to override the existing one. + +The reduction_plan_id is created and assigned during the Reduction Plan creation. It is a unique identifier that is passed along with the reduction plan name and any other necessary parameters between View and Model. + +In case any of the above do not pass, an error message is sent and displayed to the user. + +Below is the expected schema for the Reduction Plan saved in a file: + +.. mermaid:: + + classDiagram + class ReductionPlanFile{ + +String Instrument + +List~Number~ Wavelength + +Number Experiment + +String RunRange + +String Grouping + +String UBFile + +String VanadiumFile + +String BackgroundFile + +String FluxFile + +String MaskFile + +String DetectorCalibration + +String TubeCalibration + +String SolidAngle + } + +The datapath of the files are saved in the reduction plan file. The Instrument contains the name of the instrument. When the reduction plan file is loaded in Garnet, the instrument name is used to create the new Instrument (if it does not exist). + +Reduction pla file validation rules: + + * If the data fields and values are correct, a new reduction plan object is created and its values are send and displayed to the user. + + * If the data values are missing or invalid, a reduction plan object is not created. The parameters are sent and displayed to the user to fix them. A corresponding error message is displayed to promt the user to edit the parameters and then save the reduction plan. + + * If data keys (fields) are missing, the file is considered corrupted. No parameters are loaded andan error message is sent and displayed to the user. diff --git a/docs/source/design/reduction_plan_mvp.rst b/docs/source/design/reduction_plan_mvp.rst new file mode 100644 index 0000000..2675433 --- /dev/null +++ b/docs/source/design/reduction_plan_mvp.rst @@ -0,0 +1,649 @@ +.. _reduction_plan_mvp: + +Reduction Plan Model-View-Presenter +======================================== + +The data, graphical interface and functionality components related to the first step +-- Reduction Plan Screen -- are described here. The related code +is organized in the Model-View-Presenter pattern. + + +ReductionPlanListModel +------------------------------ + +The Model is described in detail: + +.. mermaid:: + + classDiagram + ReductionPlanTabModel "1" -->"1" ReductionPlanListModel + ReductionPlanTabModel "1" -->"1" PyOnCatModel + ReductionPlanTabModel "1" o--"N<=6" InstrumentModel + ReductionPlanListModel "1" o--"N" ReductionPlanModel + ReductionPlanModel "N" -->"1" InstrumentModel + PyOnCatModel "1" -->"1" InstrumentModel + + class ReductionPlanListModel{ + -String:selected_plan + -List~ReductionPlanModel~ reduction_plan_list + +add_reduction_plan() + +remove_reduction_plan() + +get_selected_plan() + +set_selected_plan() + +get_plans() + + } + + class ReductionPlanTabModel{ + +ReductionPlanListModel reduction_plan_list + +List~InstrumentModel~ instrument_list + +PyOnCatModel pyoncat_data + +add_instrument() + +get_instrument() + } + + class InstrumentModel{ + <> + } + + class ReductionPlanModel{ + <> + } + + class PyOnCatModel{ + <> + } + + +The ReductionPlanListModel model contains the user's reduction plans and the one selected for +data reduction in further steps (ReductionPlanModel). Additionally, it maintains the list +of the instruments (InstrumentModel) generated during the reduction plan creation process per user's selections. +Finally the runs of experiments with their fields based on the selected instrument and OnCat-related +information are stored (PyOnCatModel), too. +The selected plan (ReductionPlanModel) is passed for the next step. + +There are a lot of dependencies on the selected instrument. We might have to consider a way to enforce user to select instrument, +before they continue with any other parameter. + +ReductionPlanTab +-------------------- + +The View is described below: + +.. mermaid:: + + classDiagram + ReductionPlanTab "1" -->"1" ReductionPlanTasksWidget + ReductionPlanTab "1" -->"1" ReductionPlanWidget + ReductionPlanTasksWidget "1" -->"1" ReductionPlanListWidget + ReductionPlanWidget "1" -->"1" RunsWidget + ReductionPlanWidget "1" -->"1" GoniometerWavelengthWidget + ReductionPlanWidget "1" -->"1" DataSourceWidget + ReductionPlanWidget "1" -->"1" NormalizationWidget + ReductionPlanWidget "1" -->"1" CalibrationWidget + ReductionPlanWidget "1" -->"1" BaseButton + ReductionPlanWidget "1" -->"1" BtnFileWidget + ReductionPlanWidget "1" -->"1" SaveBtnFileWidget + DataSourceWidget"1" -->"1" PyOnCatBtnFileWidget + PyOnCatBtnFileWidget"1" --|>"1" BtnFileWidget + SaveBtnFileWidget"1" --|>"1" BtnFileWidget + CalibrationWidget "1" o--"2" BtnFileWidget + NormalizationWidget "1" o--"4" BtnFileWidget + + class ReductionPlanTab{ + -Signal~str~:error_message_signal + +ReductionPlanTasksWidget:reduction_plan_tasks + +ReductionPlanWidget:reduction_plan + +send_error_message() + -show_error_message() + +QStatusBar:status_bar + } + + class ReductionPlanTasksWidget{ + +ReductionPlanListWidget:reduction_plan_list + +QButton:load + +QButton:create + +QLabel:selected_reduction_plan + +display_selected_reduction_plan() + +load_reduction_plan() + +create_reduction_plan() + +clear_fields() + } + + class ReductionPlanListWidget{ + <> + +String:reduction_plan_name + -String:reduction_plan_id + -QMenu:menu + +QAction:copy + +QAction:edit + +QAction:delete + +copy_reduction_plan() + +edit_reduction_plan() + +delete_reduction_plan() + +get_plot_data() + } + + class ReductionPlanWidget{ + -String:reduction_plan_id + +QLabel:name_display + +QLineEdit:name + +QLabel:instrument_display + +QComboBox:instrument + +DataSourceWidget:data_source + +RunsWidget:runs + +GoniometerWavelengthWidget:goniometer + +CalibrationWidget:calibration + +BtnFileWidget: ub + +QLabel:grouping_display + +QComboBox:grouping + +VanadiumWidget:vanadium + +SaveBtnFileWidget:reduction_plan_save + +BaseButton:reduction_plan_btn + +create_reduction_plan() + +update_data_for_instrument() + +display_fields_for_instrument() + +display_grouping_choices_for_instrument() + + } + + class BaseButton{ + <> + -List~String~:invalid_fields + -activate_btn() + -deactivate_btn() + +add_invalid_field() + +remove_invalid_field() + } + + class DataSourceWidget{ + +QLabel:oncat_connection_status + +PyOnCatQButton: oncat_login_btn + +PyOnCatBtnFileWidget:oncat_filepath + +display_oncat_connection_status() + +validate_full_path_format() + } + + class RunsWidget{ + +QLabel:ipts_display + +QComboBox:ipts + +QButton:ipts_refresh + +QTableWidget:grouped_runs + +QLabel:run_range_display + +QLineEdit:run_range + +Mantidqt:run_plot + +display_experiments_for_instrument() + +display_grouped_runs_for_experiment() + +display_plot_data() + +get_selected_run_range() + +get_selected_experiment() + +validate_run_ranges_format() + } + + + class GoniometerWavelengthWidget{ + +QLabel:goniometer_table_display + +QTableWidget:goniometer_table + +QLabel:wavelength_display + +QLineEdit~1|2~:wavelength + +display_goniometer_table_for_instrument() + +display_wavelength_for_instrument() + } + + + class CalibrationWidget{ + +BtnFileWidget: detector + +BtnFileWidget: tube + } + + + class NormalizationWidget{ + +BtnFileWidget: flux + +BtnFileWidget: solid_angle + +BtnFileWidget: mask + +BtnFileWidget: background + } + + class PyOnCatBtnFileWidget{ + <> + +update_full_path() + } + + + class SaveBtnFileWidget{ + <> + +create_starting_folder() + } + + class BtnFileWidget{ + -String: starting_path + -String: starts_with + -String: extension + +QLabel: filename_display + +QLineEdit:full_path + +QButton-QFileDialog: file_browse_btn + +get_full_path() + +sync_full_path() + +validate_file_extension() + +set_starting_path() + +show() + +hide() + } + +The wireframe for the above class diagram is here: `Garnet Wireframe `_. + +All validation related to invalid and required fields for the reduction plan submit (Add/Edit) button +are added here: + + #. required parameters + #. run range format + #. wavelength format + #. file path format of every file in: datasource, calibration, vanadium and ub and reduction plan file sections + +In case the selected reduction plan is in an invalid state, the next steps buttons/tabs are deactivated. +A reduction plan is created only and only if it is in a valid state. +In any other case, the user has to fix the parameters. + +Tab Navigation: + + #. If the user has *not* provided a ub matrix filepath in the reduction plan, only the second Tab (UB Matrix/Peak) is activated. + #. If the user has provided a ub matrix filepath, all Tabs are activated. + +ReductionPlanTabPresenter +------------------------------ + +The Presenter is described below. It is connected with one model and view. + +.. mermaid:: + + classDiagram + class ReductionPlanTabPresenter{ + -ReductionPlanTabModel:model + -ReductionPlanTab:view + (reduction plan related) + +handle_new_reduction_plan() + +handle_submit_reduction_plan(reduction_plan_parameters) + +get_starting_path_for_reduction_plan(instrument,experiment) + +handle_load_reduction_plan(reduction_plan_file) + +handle_copy_reduction_plan_parameters(reduction_plan_id) + +handle_edit_reduction_plan(reduction_plan_id) + +handle_delete_reduction_plan(reduction_plan_id) + + (pyoncat related) + +handle_oncat_connection() + +handle_datasource_filepath(filepath) + +handle_instrument_selection(instrument) + +handle_experiment_selection(experiment) + +handle_run_selection(run_range) + +update_grouped_runs(experiment, use_cached_runs=True) + + } + +All the functions orchestrate the interaction between the view and the model. +First, the ReductionPlanModel and then the PyOnCat related functionality are defined. +Most of them are triggered by a User's action on the View, e.g. by clicking a button and then +the related function is called, where the majority of the flow between M-V is coordinated. +The details are presented in the next section. + +In the first screen various functionality and states are accomplished: + + * List of Reduction Plans + * Create a Reduction Plan + * Edit a Reduction Plan + * Copy the Parameters of a Reduction Plan + * Delete a Reduction Plan + * Show the selected Reduction Plan + +The selected_reduction_plan (name) label in the View should always be in sync with the selected_plan (id) in the Model side. +The selected_plan field stores the unique identifier (id) of the selected (current) valid ReductionPlan object that the User can see. + +To distinsguish between the states: Create and Edit, we check the selected_plan field in ReductionPlanListModel. + * If there is no selected plan, we are in Create state. Users need to provide a unique filepath in this state, else a Warning Message pop-up . + * If there is a selected plan, we are in Edit state. Users cannot update the filepath in this state. + +Additionally, the following functionality related to experimentdat data is accomplished through PyOnCat: + * OnCat connection + * Read the same metadata as OnCat, without connecting, by going through the files of a user-specified folder + * List of Experiments per Selected Instrument(s) + * List of Runs per Selected Experiment(s) + * Run meta data retrieval for every Run of the Selected Experiment(s) + * Group Runs per specific field and display them + * Retrieve grouped run per users trigger-button + * Plot creation based on the Runs' meta data + +Details are described here :ref:`PyOnCatModelMVP `. + +.. _reduction_mvpi: + +M-V-P Interactions +-------------------- + +The M-V-P interactions are described and grouped by functionality: + +#. Create a new reduction plan button: handle_new_reduction_plan() + + .. mermaid:: + + sequenceDiagram + participant View + participant Presenter + participant Model + Note over View,Model: New Reduction Plan + View->>Presenter: User clicks the "Create new Reduction Plan" button + Presenter->>View: Clear all parameters of the reduction plan screen + Presenter->>Model: Unselect current reduction plan + Note right of Model: Update selected plan id ("") + Model->>Presenter: Return status + Presenter->>View: Return status + Note left of View: Status Success Message (timeout=5sec) + + When the user first lands in the page, the Tab is in this mode, too. + The success message is displayed in the status bar to indicate that the user is in the "Create mode" state. + Success messages will disappear after 5 seconds. + +#. Create/Edit a reduction plan - Submit button: handle_submit_reduction_plan(reduction_plan_parameters) + + .. mermaid:: + + sequenceDiagram + participant View + participant Presenter + participant Model + + Note over View,Model: a. Save Reduction Plan - (Create) + View->>Presenter: User clicks the "Add/Edit" button + Presenter->>View: Gather the reduction plan parameters + Presenter->>Model: Send the reduction plan parameters + Note right of Model: Validate the parameters, unique filepath for new reduction plan + Note right of Model: Create new reduction plan + Note right of Model: Create new reduction plan file and store the reduction plan parameters + Note right of Model: Add the reduction plan in the reduction plan list + Note right of Model: Set curent plan as selected (selected_plan=) + Model->>Presenter: Return reduction plan + Presenter->>View: Update reduction plan list table with new item(id,name) + Note left of View: Display selected plan label + + Note over View,Model: b. Save Reduction Plan - (Edit) + View->>Presenter: User clicks the "Add/Edit" button + Presenter->>View: Gather the reduction plan parameters + Presenter->>Model: Send the reduction plan parameters + Note right of Model: Validate the parameters + Note right of Model: Edit selected reduction plan with parameters + Note right of Model: Edit the reduction plan file with the reduction plan parameters + Model->>Presenter: Return reduction plan + Presenter->>View: Update reduction plan list table item, if name changed + Note left of View: Display selected plan label, if name changed + +#. Get the starting folder path for the reduction plan: get_starting_path_for_reduction_plan(instrument,experiment) + + .. mermaid:: + + sequenceDiagram + participant View + participant Presenter + participant Model + + Note over View,Model: Create Recommended Reduction Plan Folder File + View->>Presenter: User clicks the "Reduction Plan FilePath Select" button + Presenter->>View: Gather instrument and experiment + Presenter->>Model: Send the instrument and experiment + Note right of Model: Create the filepath format //shared//garnet>, from parameters and instrument configurations + Note right of Model: Create the garnet folder in the filepath, if it does not exist + Model->>Presenter: Return the full filepath + Presenter->>View: Set the starting path of the FileBrowser dialog + Note left of View: Display the path in the filesystem to the user + + If the user has selected an instrument and experiment, then the recommended starting path for saving the reduction plan file is at: + ///shared//garnet. The garnet folder needs to be created, if it does not exist. + If the user has not selected an instrument yet, a default option should appear. + +#. Load a reduction plan from file: handle_load_reduction_plan(reduction_plan_file) + #. Valid case + + .. mermaid:: + + sequenceDiagram + participant View + participant Presenter + participant Model + + Note over View,Model: Load a reduction plan + View->>Presenter: User clicks the "Load Reduction Plan" button and selects a file + Presenter->>View: Get the filepath + Presenter->>Model: Send the filepath + Note right of Model: Read the parameters from the file + Note right of Model: Validate the parameters + Note right of Model: Create new reduction plan + Note right of Model: Add the reduction plan in the reduction plan list + Note right of Model: Set curent plan as selected + Model->>Presenter: Return reduction plan + Presenter->>View: Update reduction plan parameters and list table + Note left of View: Display parameters + Note left of View: Display selected plan label + Note over View,Model: Edit reduction plan flow + + #. Invalid case - Invalid parameter values + + .. mermaid:: + + sequenceDiagram + participant View + participant Presenter + participant Model + + Note over View,Model: Load a reduction plan + View->>Presenter: User clicks the "Load Reduction Plan" button and selects a file + Presenter->>View: Get the filepath + Presenter->>Model: Send the filepath + Note right of Model: Read the parameters from the file + Note right of Model: Validate the parameters + Note right of Model: Create Error Message + Note right of Model: Set curent plan as selected("") + Model->>Presenter: Return error message + Presenter->>View: Show error message + Note left of View: Information Message + Note left of View: Display parameter validation + Note over View,Model: Create reduction plan flow + + #. Invalid case - Missing parameter fields (keys) or file is already loaded + + .. mermaid:: + + sequenceDiagram + participant View + participant Presenter + participant Model + + Note over View,Model: Load a reduction plan + View->>Presenter: User clicks the "Load Reduction Plan" button and selects a file + Presenter->>View: Get the filepath + Presenter->>Model: Send the filepath + Note right of Model: Read the parameters from the file + Note right of Model: Validate the parameters + Note right of Model: Create Error Message + Model->>Presenter: Return error message + Presenter->>View: Show error message + Note left of View: Error Message + +#. Copy the parameters of a reduction plan: handle_copy_reduction_plan_parameters(reduction_plan_id) + + .. mermaid:: + + sequenceDiagram + participant View + participant Presenter + participant Model + + Note over View,Model: Copy reduction plan parameters + View->>Presenter: User right-clicks on a reduction plan the "Copy" button + Presenter->>View: Get the reduction plan name + Presenter->>Model: Send the reduction plan name + Note right of Model: Read the parameters of the reduction plan + Note right of Model: Update selected plan id (selected_plan="") + Model->>Presenter: Return the parameters + Presenter->>View: Update the parameters + Presenter->>View: Update the reduction name to Clone (unique) + Note left of View: Status Success Message (timeout=5sec) + Note over View,Model: Create reduction plan flow + + This is a "Create" state variation with initial parameters filled in from another Reduction Plan. + The reduction plan name and filepath need to be updated from the user to create the cloned reduction plan. + +#. Select/Edit a reduction plan - Button: handle_edit_reduction_plan(reduction_plan_id) + + .. mermaid:: + + sequenceDiagram + participant View + participant Presenter + participant Model + + Note over View,Model: Edit reduction plan parameters + View->>Presenter: User left-clicks on a reduction plan + Presenter->>View: Get the reduction plan id + Presenter->>Model: Send the reduction plan id + Note right of Model: Read the parameters of the reduction plan + Note right of Model: Update selected plan id to current (selected_plan=) + Model->>Presenter: Return the parameters + Presenter->>View: Update the parameters + Note left of View: Display selected plan label + Note over View,Model: Edit reduction plan flow + +#. Delete a reduction plan - Button: handle_delete_reduction_plan(reduction_plan_id) + + .. mermaid:: + + sequenceDiagram + participant View + participant Presenter + participant Model + + Note over View,Model: Delete a reduction plan + View->>Presenter: User right-clicks on a reduction plan the "Delete" button + Note left of View: Info Message + Presenter->>View: Get the reduction plan id + Presenter->>Model: Send the reduction plan id + Note right of Model: Remove the reduction plan from the list + Note right of Model: Remove the reduction plan file, if selected yes + Note right of Model: Update selected plan to "", if this is the current one + Model->> Presenter: Return status + Presenter->>View: Update reduction plan list table + Presenter->> View: Update selected plan label, if this is the current one + +#. Connect to OnCat: handle_oncat_connection(username, password). See :ref:`handle_oncat_connection ` . + +#. DataSource Absolute Path: handle_datasource_filepath(filepath). See :ref:`handle_datasource_filepath ` . + + +#. Select Instrument: handle_instrument_selection(instrument) + + .. mermaid:: + + sequenceDiagram + participant View + participant Presenter + participant Model + + Note over View,Model: Select instrument + View->>Presenter: User selects instrument + Presenter->>View: Get instrument + Presenter->>Model: Send instrument + Note right of Model: Create new instrument, if it does not exist + Note right of Model: Add new instrument in instrument_list, if it does not exist + Note right of Model: Store instrument in PyOnCat + Note right of Model: Get goniometer data from instrument's configuration + Note right of Model: Get wavelength data from instrument's configuration + Note right of Model: Get grouping choices from instrument's configuration + Note right of Model: Get calibration detector and tube data from instrument's configuration + Note right of Model: Get/Create starting directory paths for calibation, vanadium, background and mask from instrument's configuration + Note over View,Model: Show data + Model->>Presenter: Return experiments, goniometer, wavelength and calibration data for instrument + Presenter->>Model: Get experiments, goniometer, wavelength and calibration data for instrument + Presenter->>View: Display data for instrument + Note left of View: Show experiments + Note left of View: Show grouping + Note left of View: Update goniometer table and wavelength data + Note left of View: Display/Hide calibration detector and tube fields + Note left of View: Set starting directory paths for calibation, vanadium, background and mask + + + The starting directory paths of the filebrowser dialogs for the following are updated: + + * for calibration section: ///shared/calibration + * for vanadium and mask section: ///shared/Vanadium + * for background: ///shared/Background/ + + The starting paths for calibration, vanadium background and mask sections are retrieved from the Instrument Configuration Settings. No folder creation occurs in this case. + + +#. Select Experiment: handle_experiment_selection(experiment). + + .. mermaid:: + + sequenceDiagram + participant View + participant Presenter + participant Model + Note over View,Model: Handle Experiment Selection + View->>Presenter: User selects experiment + Presenter->>View: Get experiment + Presenter->>Model: Send experiment + Note right of Model: Store experiment + Note right of Model: Generate and Store data source filepath + Model->>Presenter: Return data source filepath + Presenter->>View: Display data source filepath + Note left of View: Create/Set starting directory paths for UB Matrix + + Note over View,Model: Update Grouped Runs (update_grouped_runs(use_cached_runs=True)) + Presenter->>Model: Get grouped runs for an experiment + Note right of Model: Get runs from OnCat/filepath folder, if they do not exist + Note right of Model: Store run data and group runs by group field + Model->>Presenter: Return grouped runs for an experiment + Presenter->>View: Display grouped runs + + The starting path format for UB matrix: ///IPTS-/shared + +#. Select Run Range: handle_run_selection(run_range) See :ref:`handle_run_selection ` . + +#. Refresh IPTS Runs: update_grouped_runs(use_cached_runs=False) See :ref:`update_grouped_runs ` . + + +#. Warning message flow from Model + + .. mermaid:: + + sequenceDiagram + participant View + participant Presenter + participant Model + + Note over View,Model: Error detected during data processing + Note right of Model: Create Warning message + Model->>Presenter: Send warning message + Presenter->>View: Send warning message + Note left of View: Show warning message + Presenter->>View: Get user input + Presenter->>Model: Send user input + Note right of Model: Continue or Interrupt flow + + A warning message pop-up appears during the normal workflow to ask the user whether they want to proceed with the worflow or interrup. + * If the user chooses to continue, then the warning is disregarded and the worflow continues. + * If the user chooses to stop, the workflow is interrupted and the users returns to the previous state. + + +#. Error message flow from Model + + .. mermaid:: + + sequenceDiagram + participant View + participant Presenter + participant Model + + Note over View,Model: Error detected during data processing + Note right of Model: Create error message + Model->>Presenter: Send error message + Presenter->>View: Send error message + Note left of View: Show error message + + Error and warning messages are pop-up messages.