Tuan Nguyen пре 1 година
родитељ
комит
a8e53ba9e8

+ 34 - 25
dune_weaver_flask/modules/core/pattern_manager.py

@@ -20,6 +20,8 @@ CLEAR_PATTERNS = {
     "clear_sideway":  "./patterns/clear_sideway.thr"
 }
 os.makedirs(THETA_RHO_DIR, exist_ok=True)
+current_playlist = []
+current_playing_index = None
 
 def list_theta_rho_files():
     files = []
@@ -159,7 +161,6 @@ def run_theta_rho_file(file_path, schedule_hours=None):
     state.execution_progress = (0, total_coordinates, None)
 
     stop_actions()
-    BATCH_SIZE = 15  # Max planner buffer size
 
     with serial_manager.serial_lock:
         state.current_playing_file = file_path
@@ -168,19 +169,25 @@ def run_theta_rho_file(file_path, schedule_hours=None):
         logger.info(f"Starting pattern execution: {file_path}")
         logger.info(f"t: {state.current_theta}, r: {state.current_rho}")
         reset_theta()
-        for coordinate in tqdm(coordinates):
-            theta, rho = coordinate
-            if state.stop_requested:
-                logger.info("Execution stopped by user after completing the current batch")
-                break
-
-            with state.pause_condition:
-                while state.pause_requested:
-                    logger.info("Execution paused...")
-                    state.pause_condition.wait()
-
-            schedule_checker(schedule_hours)
-            interpolate_path(theta, rho)
+        with tqdm(total=total_coordinates, unit="coords", desc=f"Executing Pattern {file_path}", dynamic_ncols=True, disable=None) as pbar:
+            for i, coordinate in enumerate(coordinates):
+                theta, rho = coordinate
+                if state.stop_requested:
+                    logger.info("Execution stopped by user after completing the current batch")
+                    break
+
+                with state.pause_condition:
+                    while state.pause_requested:
+                        logger.info("Execution paused...")
+                        state.pause_condition.wait()
+
+                schedule_checker(schedule_hours)
+                interpolate_path(theta, rho)
+                
+                if i != 0:
+                    pbar.update(1)
+                    estimated_remaining_time = pbar.format_dict['elapsed'] / i * total_coordinates
+                    state.execution_progress = (i, total_coordinates, estimated_remaining_time)
 
         serial_manager.check_idle()
 
@@ -190,18 +197,20 @@ def run_theta_rho_file(file_path, schedule_hours=None):
 
 def run_theta_rho_files(file_paths, pause_time=0, clear_pattern=None, run_mode="single", shuffle=False, schedule_hours=None):
     """Run multiple .thr files in sequence with options."""
+    global current_playing_index, current_playlist
     state.stop_requested = False
     
     if shuffle:
         random.shuffle(file_paths)
         logger.info("Playlist shuffled")
 
-    state.current_playlist = file_paths
+    current_playlist = file_paths
 
     while True:
         for idx, path in enumerate(file_paths):
             logger.info(f"Upcoming pattern: {path}")
-            state.current_playing_index = idx
+            logger.info(idx)
+            current_playing_index = idx
             schedule_checker(schedule_hours)
             if state.stop_requested:
                 logger.info("Execution stopped before starting next pattern")
@@ -247,8 +256,8 @@ def stop_actions():
     with state.pause_condition:
         state.pause_requested = False
         state.stop_requested = True
-        state.current_playing_index = None
-        state.current_playlist = None
+        current_playing_index = None
+        current_playlist = None
         state.is_clearing = False
         state.current_playing_file = None
         state.execution_progress = None
@@ -264,11 +273,11 @@ def get_status():
 
     return {
         "ser_port": serial_manager.get_port(),
-        "state.stop_requested": state.stop_requested,
-        "state.pause_requested": state.pause_requested,
-        "state.current_playing_file": state.current_playing_file,
-        "state.execution_progress": state.execution_progress,
-        "state.current_playing_index": state.current_playing_index,
-        "state.current_playlist": state.current_playlist,
-        "state.is_clearing": state.is_clearing
+        "stop_requested": state.stop_requested,
+        "pause_requested": state.pause_requested,
+        "current_playing_file": state.current_playing_file,
+        "execution_progress": state.execution_progress,
+        "current_playing_index": current_playing_index,
+        "current_playlist": current_playlist,
+        "is_clearing": state.is_clearing
     }

+ 0 - 6
dune_weaver_flask/modules/core/state.py

@@ -11,8 +11,6 @@ class AppState:
         self.pause_condition = threading.Condition()
         self.current_playing_file = None
         self.execution_progress = None
-        self.current_playing_index = None
-        self.current_playlist = None
         self.is_clearing = False
         self.current_theta = 0
         self.current_rho = 0
@@ -33,8 +31,6 @@ class AppState:
             "pause_requested": self.pause_requested,
             "current_playing_file": self.current_playing_file,
             "execution_progress": self.execution_progress,
-            "current_playing_index": self.current_playing_index,
-            "current_playlist": self.current_playlist,
             "is_clearing": self.is_clearing,
             "current_theta": self.current_theta,
             "current_rho": self.current_rho,
@@ -49,8 +45,6 @@ class AppState:
         self.pause_requested = data.get("pause_requested", False)
         self.current_playing_file = data.get("current_playing_file")
         self.execution_progress = data.get("execution_progress")
-        self.current_playing_index = data.get("current_playing_index")
-        self.current_playlist = data.get("current_playlist")
         self.is_clearing = data.get("is_clearing", False)
         self.current_theta = data.get("current_theta", 0)
         self.current_rho = data.get("current_rho", 0)

+ 2 - 0
dune_weaver_flask/static/js/main.js

@@ -257,6 +257,7 @@ async function runThetaRho() {
     const result = await response.json();
     if (result.success) {
         logMessage(`Pattern running: ${selectedFile}`, LOG_TYPE.SUCCESS);
+        updateCurrentlyPlaying();
     } else {
         logMessage(`Failed to run file: ${selectedFile}`,LOG_TYPE.ERROR);
     }
@@ -898,6 +899,7 @@ async function runPlaylist() {
 
         if (result.success) {
             logMessage(`Playlist "${playlistName}" is now running.`, LOG_TYPE.SUCCESS);
+            updateCurrentlyPlaying();
         } else {
             logMessage(`Failed to run playlist "${playlistName}": ${result.error}`, LOG_TYPE.ERROR);
         }