From dc4ec36ca70e6b44864463825580f954c3c0404f Mon Sep 17 00:00:00 2001
From: Timothe Jost <timothe.jost@wanadoo.fr>
Date: Sat, 16 Mar 2024 04:31:05 +0100
Subject: [PATCH] format and set preprocessing files to "adaptation" instead of
 preproc_data

---
 app.py | 100 ++++++++++++++++++---------------------------------------
 1 file changed, 32 insertions(+), 68 deletions(-)

diff --git a/app.py b/app.py
index 6c20d4e..217c58a 100644
--- a/app.py
+++ b/app.py
@@ -44,9 +44,7 @@ pages = {
 
 app.layout = html.Div(
     [
-        html.Div(
-            className="ribbon", id="ribbon_container", style={"margin-bottom": 75}
-        ),
+        html.Div(className="ribbon", id="ribbon_container", style={"margin-bottom": 75}),
         html.Div(
             children=[
                 dcc.Location(id="url", refresh=False),
@@ -69,22 +67,18 @@ def create_menu(session_uuid, session_alias):
         dropdown = []
     else:
         alyx_label = "Open in Alyx"
-        alyx_adress = (
-            f"http://haiss-alyx.local/admin/actions/session/{session_uuid}/change/"
-        )
+        alyx_adress = f"http://haiss-alyx.local/admin/actions/session/{session_uuid}/change/"
         dropdown = [
             html.Div(
                 [
                     f"Session {session_alias}",
                     html.Div(
-                        [
-                            html.A(name, href=link.format(session_uuid=session_uuid))
-                            for name, link in pages.items()
-                        ],
+                        [html.A(name, href=link.format(session_uuid=session_uuid)) for name, link in pages.items()],
                         className="dropdown-content",
                     ),
                 ],
-                className="dropdown-link-menu", id = "session-name-title",
+                className="dropdown-link-menu",
+                id="session-name-title",
             )
         ]
     print("Session id is : ", session_uuid, "alias is : ", session_alias)
@@ -152,28 +146,15 @@ def dash_container_router(pathname):
         return dash.no_update
     for route, route_item in func_routes.items():
         if route_item["route_pattern"].match(pathname):
-            print(
-                pathname
-                + " match : "
-                + route
-                + "with pattern : "
-                + route_item["route_pattern"].pattern
-            )
+            print(pathname + " match : " + route + "with pattern : " + route_item["route_pattern"].pattern)
             kwargs = {}
             kwags_matches = route_item["route_pattern"].findall(pathname)
             if kwags_matches:
                 if len(route_item["kwargs_names"]) > 1:
                     kwags_matches = kwags_matches[0]
-                kwargs = {
-                    name: match
-                    for name, match in zip(route_item["kwargs_names"], kwags_matches)
-                }
-            return route_item["func"](
-                **kwargs
-            )  # call the appropriate routed function here, with **kwargs
-    return html.Div(
-        "404 Not Found: The resource could not be found.", className="error_message"
-    )
+                kwargs = {name: match for name, match in zip(route_item["kwargs_names"], kwags_matches)}
+            return route_item["func"](**kwargs)  # call the appropriate routed function here, with **kwargs
+    return html.Div("404 Not Found: The resource could not be found.", className="error_message")
 
 
 def perform_data_registration(uuid, dry_run=True):
@@ -182,12 +163,8 @@ def perform_data_registration(uuid, dry_run=True):
     selected_session_folder = session_details["path"]
     selected_session_folder = convert_mount(selected_session_folder)
 
-    results = auto_rename_session_files_to_alf(
-        selected_session_folder, dry_run=dry_run, return_tables=True
-    )
-    results["names_after_renaming"] = [
-        convert_mount(path, reverse=True) for path in results["names_after_renaming"]
-    ]
+    results = auto_rename_session_files_to_alf(selected_session_folder, dry_run=dry_run, return_tables=True)
+    results["names_after_renaming"] = [convert_mount(path, reverse=True) for path in results["names_after_renaming"]]
     try:
         register_files(results["names_after_renaming"], uuid, dry_run=dry_run)
     except:
@@ -197,14 +174,12 @@ def perform_data_registration(uuid, dry_run=True):
 
 @dash_route("/dashboard/data-registration/<uuid>/check", strict_slashes=False)
 def display_data_registration_check(uuid):
-    with temporary_logger('stdout') as logger:
+    with temporary_logger("stdout") as logger:
         tables = perform_data_registration(uuid, dry_run=True)
         log = logger.getvalue()
-    log_text = html.Pre(log, style={'whiteSpace': 'pre-wrap', 'wordBreak': 'break-all'})
+    log_text = html.Pre(log, style={"whiteSpace": "pre-wrap", "wordBreak": "break-all"})
     conflict_table = display_table(tables["conflicts_df"], "Conflicts Table")
-    comparison_table = display_table(
-        tables["comparison_df"], "File Renaming Comparisons Table"
-    )
+    comparison_table = display_table(tables["comparison_df"], "File Renaming Comparisons Table")
 
     redirect_button = html.Div(
         dcc.Link(
@@ -228,6 +203,7 @@ def display_data_registration_check(uuid):
         ]
     )
 
+
 def display_table(df, title=None):
     def drop_multiliners(cell):
         try:
@@ -261,12 +237,12 @@ def display_table(df, title=None):
     if title is None:
         title = ""
 
-    style_header = {'font-family': 'Roboto, sans-serif', 'font-weight': 'bold', 'font-size': '16px'}
-    style_table= {"width": "100vw", "overflow-x": "auto"}
-    style_cell = {'font-family': 'Roboto, sans-serif', 'font-size': '14px','text-align': 'center'}
+    style_header = {"font-family": "Roboto, sans-serif", "font-weight": "bold", "font-size": "16px"}
+    style_table = {"width": "100vw", "overflow-x": "auto"}
+    style_cell = {"font-family": "Roboto, sans-serif", "font-size": "14px", "text-align": "center"}
     if len(df):
-        style_cell.update({'width': '{}%'.format(100/len(df.columns))})
-        
+        style_cell.update({"width": "{}%".format(100 / len(df.columns))})
+
     return html.Div(
         [
             html.Div(title, className="table_title"),
@@ -280,8 +256,8 @@ def display_table(df, title=None):
                 page_size=25,
                 style_header=style_header,
                 style_table=style_table,
-                style_cell = style_cell,
-                id = "pandas_table"
+                style_cell=style_cell,
+                id="pandas_table",
             ),
         ]
     )
@@ -392,14 +368,12 @@ def get_trials_df(uuid):
             "404 Not Found: The supplied session doesn't exist",
             className="error_message",
         )
-    session = connector.to_session_details(
-        connector.alyx.rest("sessions", "read", id=uuid)
-    )
+    session = connector.to_session_details(connector.alyx.rest("sessions", "read", id=uuid))
 
     df_path = os.path.join(
         convert_mount(session.path),
         "preprocessing_saves",
-        "preproc_data.trials_df.pickle",
+        "adaptation.trials_df.pickle",
     )
     df = pd.read_pickle(df_path)
     df.loc[:, "trial_nb"] = df.index
@@ -413,7 +387,7 @@ def display_trials_df_table(uuid):
         return display_table(get_trials_df(uuid), "Trials Table")
     except FileNotFoundError:
         return html.Div(
-            "404 Not Found: preproc_data.trials_df was not found for this session",
+            "404 Not Found: adaptation.trials_df was not found for this session",
             className="error_message",
         )
 
@@ -424,7 +398,7 @@ def display_trials_df_plot(uuid):
         return display_2d_plot(get_trials_df(uuid))
     except FileNotFoundError:
         return html.Div(
-            "404 Not Found: preproc_data.trials_df was not found for this session",
+            "404 Not Found: adaptation.trials_df was not found for this session",
             className="error_message",
         )
 
@@ -451,7 +425,7 @@ def display_data_management_plot(uuid):
 
 @dash_route("/dashboard/")
 def dashboard_home():
-    return dcc.Location(pathname='/', id='url_redirecting', refresh=True)
+    return dcc.Location(pathname="/", id="url_redirecting", refresh=True)
 
 
 @server.route("/images/<uuid_key>", strict_slashes=False)
@@ -461,7 +435,7 @@ def serve_images(uuid_key):
         return render_template(
             "images_gallery.html",
             image_groups=images,
-            dropdown_links = {key : link.format(session_uuid=uuid_key) for key, link in pages.items()},
+            dropdown_links={key: link.format(session_uuid=uuid_key) for key, link in pages.items()},
             session_alias=session_object.alias,
             session_uuid=uuid_key,
         )
@@ -470,28 +444,21 @@ def serve_images(uuid_key):
     uuid_key = connector.to_eid(uuid_key)  # uuid key is provided by the page url
     if uuid_key is None:
         return "Error: Invalid UUID key provided", 400
-    session_object = connector.to_session_details(
-        connector.alyx.rest("sessions", "read", id=uuid_key, no_cache=True)
-    )
+    session_object = connector.to_session_details(connector.alyx.rest("sessions", "read", id=uuid_key, no_cache=True))
     folder_path = os.path.join(session_object.path, "figures")
     try:
         folder_path = convert_mount(folder_path)
     except IOError:
         return render()
     try:
-        image_files = [
-            file for file in os.listdir(folder_path) if file.endswith((".png", ".jpg"))
-        ]
+        image_files = [file for file in os.listdir(folder_path) if file.endswith((".png", ".jpg"))]
     except (
         FileNotFoundError
     ) as e:  # FileNotFoundError if toplevel figures listed folder does not exist for this session.
         return render()
 
     image_files.sort()
-    image_groups = [
-        natsorted(list(group))
-        for _, group in groupby(image_files, lambda x: x.split(".")[1])
-    ]
+    image_groups = [natsorted(list(group)) for _, group in groupby(image_files, lambda x: x.split(".")[1])]
     images = [
         [
             {
@@ -537,10 +504,7 @@ def convert_mount(path, reverse=False):
 @server.route("/image-directory/<path:path>")
 def send_image(path):
     folder, filename = os.path.split(path)
-    if (
-        not (folder[0] == "/" or folder[0] == "\\")
-        and "ubuntu" in platform.version().lower()
-    ):
+    if not (folder[0] == "/" or folder[0] == "\\") and "ubuntu" in platform.version().lower():
         folder = (
             "/" + folder
         )  # we make sure to have / in front of folder path to make sure the path is absolut, if we run on ubuntu
-- 
GitLab