Update configuration and directory handling

- Increased time_window in plot_definitions.json from 10 to 60.
- Added external_path function in config_manager.py to handle paths for records and logs, ensuring compatibility with both development and PyInstaller executable environments.
- Updated PLCDataStreamer to use the new get_csv_directory_path method for retrieving the records directory.
- Refactored main.py to include get_records_directory function for consistent records directory path retrieval.
- Modified system_state.json to set should_connect to false and updated last_update timestamp.
This commit is contained in:
Miguel 2025-08-18 18:51:18 +02:00
parent bd5b70f044
commit a1c004f11b
6 changed files with 22842 additions and 20709 deletions

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,7 @@
"point_radius": 2.5,
"stacked": true,
"stepped": true,
"time_window": 10,
"time_window": 60,
"trigger_enabled": false,
"trigger_on_true": true,
"trigger_variable": null,

View File

@ -22,6 +22,17 @@ def resource_path(relative_path):
return os.path.join(base_path, relative_path)
def external_path(relative_path):
"""Get path external to PyInstaller bundle (for records, logs, etc.)"""
if getattr(sys, "frozen", False):
# Running as PyInstaller executable - use directory next to exe
executable_dir = os.path.dirname(sys.executable)
return os.path.join(executable_dir, relative_path)
else:
# Running as script - use current directory
return os.path.join(os.path.abspath("."), relative_path)
class ConfigManager:
"""Manages all configuration persistence and validation"""
@ -421,7 +432,7 @@ class ConfigManager:
base = self.csv_config.get("records_directory", "records")
except Exception:
base = "records"
return resource_path(base)
return external_path(base)
# PLC Configuration Methods
def update_plc_config(self, ip: str, rack: int, slot: int):

View File

@ -548,7 +548,7 @@ class PLCDataStreamer:
"""Get information about disk space usage and recording time estimates"""
try:
# Get the records directory path
records_path = "records"
records_path = self.config_manager.get_csv_directory_path()
if not os.path.exists(records_path):
os.makedirs(records_path)
@ -597,7 +597,7 @@ class PLCDataStreamer:
return 0
# Get CSV directory to check existing files
records_dir = "records"
records_dir = self.config_manager.get_csv_directory_path()
if not os.path.exists(records_dir):
# If no records directory exists yet, make a rough estimate
return self._rough_size_estimate()

17
main.py
View File

@ -77,6 +77,17 @@ def project_path(*parts: str) -> str:
return os.path.join(base_dir, *parts)
def get_records_directory():
"""Get the correct records directory path for both development and PyInstaller exe"""
if getattr(sys, "frozen", False):
# Running as PyInstaller executable - records should be next to the exe
executable_dir = os.path.dirname(sys.executable)
return os.path.join(executable_dir, "records")
else:
# Running as script - use current directory
return os.path.join(os.path.dirname(__file__), "records")
# React build directory (for Vite production build)
# Use resource_path to handle both development and PyInstaller scenarios
REACT_DIST_DIR = resource_path(os.path.join("frontend", "dist"))
@ -2001,7 +2012,7 @@ def get_historical_data():
return jsonify({"error": f"Time calculation failed: {str(e)}"}), 500
# Get relevant CSV files for cache checking
records_dir = os.path.join(os.path.dirname(__file__), "records")
records_dir = get_records_directory()
csv_files = []
if os.path.exists(records_dir):
@ -2343,7 +2354,7 @@ def get_historical_date_range():
import glob
# Get records directory
records_dir = os.path.join(os.path.dirname(__file__), "records")
records_dir = get_records_directory()
if not os.path.exists(records_dir):
return (
@ -2478,7 +2489,7 @@ def get_historical_data_segments():
try:
import glob
records_dir = os.path.join(os.path.dirname(__file__), "records")
records_dir = get_records_directory()
if not os.path.exists(records_dir):
return (

View File

@ -1,13 +1,13 @@
{
"last_state": {
"should_connect": true,
"should_connect": false,
"should_stream": false,
"active_datasets": [
"Test",
"Fast",
"DAR"
]
},
"auto_recovery_enabled": true,
"last_update": "2025-08-17T12:13:12.849060",
"plotjuggler_path": "C:\\Program Files\\PlotJuggler\\plotjuggler.exe"
"last_update": "2025-08-18T18:51:02.665774"
}