Kaynağa Gözat

Fix notch filter file referencing

Arkadiusz Ryś 3 yıl önce
ebeveyn
işleme
798664ed7f
4 değiştirilmiş dosya ile 23 ekleme ve 7 silme
  1. 16 2
      README.md
  2. 5 3
      mocka/routers/notch.py
  3. 1 1
      requirements.txt
  4. 1 1
      tests/test_notch.py

+ 16 - 2
README.md

@@ -18,11 +18,12 @@ This endpoint expects this context in the form of a json body following a highly
     }
     }
 
 
 Anything between `<` and `>` is to be filled in by the requester.
 Anything between `<` and `>` is to be filled in by the requester.
-Only `inline` type artefacts are supported at the moment.
+Only `inline` and `reference` type artefacts are supported at the moment.
+Which one you should use depends on the activity.
+A good rule to follow is: "If the filetype is text-like, use inline.".
 
 
 Barring any errors, mocka will retaliate with a json response in the same gist.
 Barring any errors, mocka will retaliate with a json response in the same gist.
 
 
-
     {
     {
         "ctrl": "<the name of the control port which should be taken out of the activity>",
         "ctrl": "<the name of the control port which should be taken out of the activity>",
         "output": {
         "output": {
@@ -49,7 +50,20 @@ Drop into a shell and sing the magic incantation `python3 -m mocka`.
 This will leave you haunted with an endpoint lingering on port `7999` by default.
 This will leave you haunted with an endpoint lingering on port `7999` by default.
 From this point onward you're on your own and can perform any request you want.
 From this point onward you're on your own and can perform any request you want.
 
 
+### Extra dependencies
+
+There are multiple mock routers.
+The `notch` and `octiva` routers require external software to be installed.
+OpenCV in the case `octiva` and open-modelica in the case of `notch`.
+Installing the Python `opencv-python` package will the trick for the first one.
+Good luck on the modelica one.
+
 ## Wishful thinking
 ## Wishful thinking
 
 
 It would be nice if this endpoint would support gradual progress updates.
 It would be nice if this endpoint would support gradual progress updates.
 This would also require the Workflow Enactment Engine to do the same.
 This would also require the Workflow Enactment Engine to do the same.
+
+The storage backend location is hardcoded. It might be useful not to do this.
+
+Not all the possible options are available when sending data.
+An example of this is an image. It should always be sent as a reference.

+ 5 - 3
mocka/routers/notch.py

@@ -4,6 +4,7 @@ from pathlib import Path
 from typing import Any
 from typing import Any
 import arklog
 import arklog
 import magic
 import magic
+import requests
 from fastapi import APIRouter, Query, Request, Response
 from fastapi import APIRouter, Query, Request, Response
 from fastapi.responses import JSONResponse
 from fastapi.responses import JSONResponse
 from OMPython import OMCSessionZMQ, ModelicaSystem
 from OMPython import OMCSessionZMQ, ModelicaSystem
@@ -23,7 +24,8 @@ def single_simulation_om_python(model_file_path, test_frequency, test_amplitude,
     sampling_frequency = test_frequency * sampling_ratio
     sampling_frequency = test_frequency * sampling_ratio
     omc = OMCSessionZMQ()
     omc = OMCSessionZMQ()
     model = ModelicaSystem(str(model_file_path),model_file_path.stem)
     model = ModelicaSystem(str(model_file_path),model_file_path.stem)
-    model.buildModel("(V_in.v)|(V_out.v)")
+    # model.buildModel("(V_in.v)|(V_out.v)")
+    model.buildModel()
     model.setSimulationOptions([
     model.setSimulationOptions([
         f"stepSize={1/sampling_frequency}",
         f"stepSize={1/sampling_frequency}",
         f"tolerance={tolerance}",
         f"tolerance={tolerance}",
@@ -109,9 +111,9 @@ class NotchRouter(APIRouter):
             arklog.debug(f"{output_stabilisation_time=}")
             arklog.debug(f"{output_stabilisation_time=}")
             arklog.debug(f"{output=}")
             arklog.debug(f"{output=}")
             artefact_file_path = single_simulation_om_python(model_file_path, frequency, amplitude, sampling_ratio, tolerance,data_cycles,output_stabilisation_time, output)
             artefact_file_path = single_simulation_om_python(model_file_path, frequency, amplitude, sampling_ratio, tolerance,data_cycles,output_stabilisation_time, output)
-            data = base64.b64encode(artefact_file_path.read_bytes()).decode()
+            requests.put(f"http://localhost:5000/files/file/{artefact_file_path.name}", data=artefact_file_path.read_bytes())
             mime = magic.Magic(mime=True).from_file(artefact_file_path)
             mime = magic.Magic(mime=True).from_file(artefact_file_path)
-            simulation_artefact = Artefact("inline", data, artefact_file_path.name, mime)
+            simulation_artefact = Artefact("reference", f"http://localhost:5000/files/file/{artefact_file_path.name}", artefact_file_path.name, mime)
             return JSONResponse(status_code=200, content={"ctrl": "ok", "output": {"experiment": simulation_artefact.as_dict()}})
             return JSONResponse(status_code=200, content={"ctrl": "ok", "output": {"experiment": simulation_artefact.as_dict()}})
 
 
         @self.put("/simulation/")
         @self.put("/simulation/")

+ 1 - 1
requirements.txt

@@ -7,7 +7,7 @@ pyarrow           ~= 13.0.0
 requests          ~= 2.31.0
 requests          ~= 2.31.0
 starlette         ~= 0.27.0
 starlette         ~= 0.27.0
 python-magic      ~= 0.4.27
 python-magic      ~= 0.4.27
-opencv-python     ~= 4.8.0.76
+opencv-python     ~= 4.8.0.76 # Octiva
 uvicorn[standard] ~= 0.23.2
 uvicorn[standard] ~= 0.23.2
 #pydelica ~= 0.4.5 # VaFL Notch
 #pydelica ~= 0.4.5 # VaFL Notch
 ompython ~= 3.4.0 # VaFL Notch
 ompython ~= 3.4.0 # VaFL Notch

+ 1 - 1
tests/test_notch.py

@@ -10,7 +10,7 @@ from mocka.artefact import Artefact
 client = TestClient(get_application(Configuration(Server("localhost", 8585))))
 client = TestClient(get_application(Configuration(Server("localhost", 8585))))
 
 
 
 
-def test_post_octiva():
+def test_post_notch():
     notch_model_file_path = Path(__file__).parent / Path("notch/notchFilter.mo")
     notch_model_file_path = Path(__file__).parent / Path("notch/notchFilter.mo")
     mime = magic.Magic(mime=True).from_file(notch_model_file_path)
     mime = magic.Magic(mime=True).from_file(notch_model_file_path)
     model_artefact = Artefact("inline", notch_model_file_path.read_text(), notch_model_file_path.name, mime)
     model_artefact = Artefact("inline", notch_model_file_path.read_text(), notch_model_file_path.name, mime)