diff --git a/MockCAN.py b/MockCAN.py index 615d6c3..8011dc0 100644 --- a/MockCAN.py +++ b/MockCAN.py @@ -29,26 +29,51 @@ class CANBackend: def get_latest_data(self, pu_number=1, data={}): # Simulate getting the latest data with random values - return { - "FM2": round(1000 * np.random.random(), 1), - "FM3": round(1000 * np.random.random(), 1), - "FM4": round(1000 * np.random.random(), 1), - "FM5": round(1000 * np.random.random(), 1), - "PS1": round(10 * np.random.random(), 2), - "PS2": round(10 * np.random.random(), 2), - "PS3": round(10 * np.random.random(), 2), - "PS4": round(10 * np.random.random(), 2), - "Cond": 1* np.random.random(), - "MV02": round(100 * np.random.random(), 2), - "MV02_sp": round(100 * np.random.random(), 2), - "MV03": round(100 * np.random.random(), 2), - "MV03_sp": round(100 * np.random.random(), 2), - "MV05": round(100 * np.random.random(), 2), - "MV05_sp": round(100 * np.random.random(), 2), - "MV06": round(100 * np.random.random(), 2), - "MV06_sp": round(100 * np.random.random(), 2), - "MV07": round(100 * np.random.random(), 2), - "MV07_sp": round(100 * np.random.random(), 2), - "MV08": round(100 * np.random.random(), 2), - "MV08_sp": round(100 * np.random.random(), 2), - } \ No newline at end of file + if pu_number ==1: + return { + "FM2": 1080, + "FM3": 1080, + "FM4": 1080, + "FM5": 1080, + "PS1": 6.2, + "PS2": 6.2, + "PS3": 6.2, + "PS4": 6.2, + "Cond": 1* np.random.random(), + "MV02": round(100 * np.random.random(), 2), + "MV02_sp": round(100 * np.random.random(), 2), + "MV03": round(100 * np.random.random(), 2), + "MV03_sp": round(100 * np.random.random(), 2), + "MV05": round(100 * np.random.random(), 2), + "MV05_sp": round(100 * np.random.random(), 2), + "MV06": round(100 * np.random.random(), 2), + "MV06_sp": round(100 * np.random.random(), 2), + "MV07": round(100 * np.random.random(), 2), + "MV07_sp": round(100 * np.random.random(), 2), + "MV08": round(100 * np.random.random(), 2), + "MV08_sp": round(100 * np.random.random(), 2), + } + else : + return { + "FM2": round(1000 * np.random.random(), 1), + "FM3": round(1000 * np.random.random(), 1), + "FM4": round(1000 * np.random.random(), 1), + "FM5": round(1000 * np.random.random(), 1), + "PS1": round(10 * np.random.random(), 2), + "PS2": round(10 * np.random.random(), 2), + "PS3": round(10 * np.random.random(), 2), + "PS4": round(10 * np.random.random(), 2), + "Cond": 1* np.random.random(), + "MV02": round(100 * np.random.random(), 2), + "MV02_sp": round(100 * np.random.random(), 2), + "MV03": round(100 * np.random.random(), 2), + "MV03_sp": round(100 * np.random.random(), 2), + "MV05": round(100 * np.random.random(), 2), + "MV05_sp": round(100 * np.random.random(), 2), + "MV06": round(100 * np.random.random(), 2), + "MV06_sp": round(100 * np.random.random(), 2), + "MV07": round(100 * np.random.random(), 2), + "MV07_sp": round(100 * np.random.random(), 2), + "MV08": round(100 * np.random.random(), 2), + "MV08_sp": round(100 * np.random.random(), 2), + } \ No newline at end of file diff --git a/main.py b/main.py index 31f9bde..598e931 100644 --- a/main.py +++ b/main.py @@ -26,19 +26,9 @@ app.add_middleware(SessionMiddleware, secret_key="your_super_secret_key") router = APIRouter() templates = Jinja2Templates(directory="templates") logging.basicConfig(level=logging.INFO) - can_backend = CANBackend() - -# Mount static files -app.mount("/static", StaticFiles(directory="static"), name="static") - - -can_backend = CANBackend() - # Serve static files (HTML, JS, CSS) app.mount("/static", StaticFiles(directory="static"), name="static") -# Jinja2 templates -templates = Jinja2Templates(directory="templates") # CREDENTIALS @@ -164,6 +154,7 @@ def get_pu_status(): @app.get("/monitor") def get_monitor_data(pu_number: Optional[int] = Query(None)): + logging.info(f"[MONITOR DATA] {pu_number}") def format_data(data): return { "Qperm": data.get("FM2", 0.0), @@ -192,8 +183,8 @@ def get_monitor_data(pu_number: Optional[int] = Query(None)): } all_data = {} for pu in [1, 2, 3]: - data = can_backend.get_latest_data(pu) - print(f"[MONITOR] PU{pu}: {data}") + data = can_backend.get_latest_data(pu_number=pu) + logging.info(f"[MONITOR] PU{pu}: {data}") all_data[f"PU_{pu}"] = format_data(data) return all_data diff --git a/static/monitor.html b/static/monitor.html index 48b763a..9871650 100644 --- a/static/monitor.html +++ b/static/monitor.html @@ -28,12 +28,6 @@ h1 { text-align: center; } - #puSelector { - display: block; - margin: 10px auto 20px auto; - font-size: 16px; - padding: 5px 10px; - } #recordButton { background-color: #ff4444; color: white; @@ -47,13 +41,7 @@
-