Просмотр исходного кода

Allow setting storage endpoint uri

Arkadiusz Ryś 1 год назад
Родитель
Сommit
7d49a12f4f
4 измененных файлов с 18 добавлено и 66 удалено
  1. 3 0
      data/configuration.toml
  2. 0 61
      data/notchFilter.mo
  3. 5 0
      mocka/configuration.py
  4. 10 5
      mocka/routers/octiva.py

+ 3 - 0
data/configuration.toml

@@ -1,3 +1,6 @@
 [server]
 host = "0.0.0.0"
 port = 7999
+[octiva]
+storage_base_uri = "http://localhost:5000"
+#storage_base_uri = "https://dtb.rys.app"

+ 0 - 61
data/notchFilter.mo

@@ -1,61 +0,0 @@
-model notchFilter
-// Parameters
-  parameter Modelica.Units.SI.PotentialDifference Vt "testAmplitude";
-  parameter Modelica.Units.SI.Frequency Ft "testFrequency";
-// Components
-  Modelica.Electrical.Analog.Basic.Ground ground_in annotation(
-    Placement(visible = true, transformation(origin = {-80, -30}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
-  Modelica.Electrical.Analog.Basic.Ground ground annotation(
-    Placement(transformation(origin = {28, -18}, extent = {{-10, -10}, {10, 10}})));
-  Modelica.Electrical.Analog.Basic.Ground ground_out annotation(
-    Placement(visible = true, transformation(origin = {80, -30}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
-  Modelica.Electrical.Analog.Basic.Capacitor C1(C(displayUnit = "nF") = 1e-9, v(start = 0)) annotation(
-    Placement(visible = true, transformation(origin = {-20, -40}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
-  Modelica.Electrical.Analog.Basic.Capacitor C2(C(displayUnit = "pF") = 1e-9, v(start = 0)) annotation(
-    Placement(visible = true, transformation(origin = {20, -40}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
-  Modelica.Electrical.Analog.Basic.Capacitor C3(C(displayUnit = "pF") = 2e-9, v(start = 0)) annotation(
-    Placement(visible = true, transformation(origin = {0, 20}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
-  Modelica.Electrical.Analog.Basic.Resistor R1(R(displayUnit = "kOhm") = 1600) annotation(
-    Placement(visible = true, transformation(origin = {-20, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
-  Modelica.Electrical.Analog.Basic.Resistor R2(R(displayUnit = "kOhm") = 1600) annotation(
-    Placement(visible = true, transformation(origin = {20, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
-  Modelica.Electrical.Analog.Basic.Resistor R3a(R(displayUnit = "kOhm") = 1600) annotation(
-    Placement(transformation(origin = {12, -18}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
-  Modelica.Electrical.Analog.Basic.Resistor R3b(R(displayUnit = "kOhm") = 1600) annotation(
-    Placement(transformation(origin = {-12, -18}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
-  Modelica.Electrical.Analog.Sensors.VoltageSensor V_out annotation(
-    Placement(visible = true, transformation(origin = {60, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
-  Modelica.Electrical.Analog.Sources.SineVoltage V_in(V(displayUnit = "V") = Vt, f(displayUnit = "Hz") = Ft) annotation(
-    Placement(visible = true, transformation(origin = {-60, 0}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
-// Equations
-  equation
-  connect(C3.n, R3a.p) annotation(
-    Line(points = {{0, 10}, {0, -1}, {12, -1}, {12, -8}}, color = {0, 0, 255}));
-  connect(V_out.p, C2.n) annotation(
-    Line(points = {{50, 0}, {40, 0}, {40, -40}, {30, -40}}, color = {0, 0, 255}));
-  connect(R1.n, R2.p) annotation(
-    Line(points = {{-10, 40}, {10, 40}}, color = {0, 0, 255}));
-  connect(C3.p, R2.p) annotation(
-    Line(points = {{0, 30}, {0, 40}, {10, 40}}, color = {0, 0, 255}));
-  connect(V_out.n, ground_out.p) annotation(
-    Line(points = {{70, 0}, {80, 0}, {80, -20}}, color = {0, 0, 255}));
-  connect(V_in.p, C1.p) annotation(
-    Line(points = {{-50, 0}, {-40, 0}, {-40, -40}, {-30, -40}}, color = {0, 0, 255}));
-  connect(R2.n, C2.n) annotation(
-    Line(points = {{30, 40}, {40, 40}, {40, -40}, {30, -40}}, color = {0, 0, 255}));
-  connect(V_in.n, ground_in.p) annotation(
-    Line(points = {{-70, 0}, {-80, 0}, {-80, -20}}, color = {0, 0, 255}));
-  connect(R1.p, C1.p) annotation(
-    Line(points = {{-30, 40}, {-40, 40}, {-40, -40}, {-30, -40}}, color = {0, 0, 255}));
-  connect(R3b.p, C3.n) annotation(
-    Line(points = {{-12, -8}, {-12, -1}, {0, -1}, {0, 10}}, color = {0, 0, 255}));
-  connect(C1.n, C2.p) annotation(
-    Line(points = {{-10, -40}, {10, -40}}, color = {0, 0, 255}));
-  connect(R3a.n, C2.p) annotation(
-    Line(points = {{12, -28}, {12, -32}, {0, -32}, {0, -40}, {10, -40}}, color = {0, 0, 255}));
-  connect(R3b.n, C1.n) annotation(
-    Line(points = {{-12, -28}, {-12, -32}, {0, -32}, {0, -40}, {-10, -40}}, color = {0, 0, 255}));
-  connect(ground.p, C3.n) annotation(
-    Line(points = {{28, -8}, {28, -1}, {0, -1}, {0, 10}}, color = {0, 0, 255}));
-  annotation(uses(Modelica(version = "4.0.0")), Diagram);
-end notchFilter;

+ 5 - 0
mocka/configuration.py

@@ -1,4 +1,5 @@
 from dataclasses import dataclass
+from typing import Optional
 
 
 @dataclass(init=True, repr=True, order=False, frozen=True)
@@ -6,7 +7,11 @@ class Server:
     host: str
     port: int
 
+@dataclass(init=True, repr=True, order=False, frozen=True)
+class Octiva:
+    storage_base_uri: str
 
 @dataclass(init=True, repr=True, order=False, frozen=True)
 class Configuration:
     server: Server
+    octiva: Optional[Octiva] = None

+ 10 - 5
mocka/routers/octiva.py

@@ -23,7 +23,7 @@ def find_parallel(lines) -> []:
     return parallel_lines
 
 
-def rail_finder_algo_one(filename: Path) -> (Artefact, Artefact):
+def rail_finder_algo_one(filename: Path, storage_base_uri: str) -> (Artefact, Artefact):
     """Create image with the lines laid over."""
     source_color_image = cv.imread(cv.samples.findFile(str(filename)), cv.IMREAD_COLOR)
     source_greyscale_image = cv.cvtColor(source_color_image, cv.COLOR_BGR2GRAY)
@@ -38,12 +38,12 @@ def rail_finder_algo_one(filename: Path) -> (Artefact, Artefact):
     for parallel_line_index in parallel_line_indices:
         x1, y1, x2, y2 = detected_lines[parallel_line_index][0]
         cv.line(source_color_image, (x1, y1), (x2, y2), (0, 255, 0), 6, cv.LINE_AA)
-    # TODO Replace with in memory and correct return file which is referenced
+    # TODO Replace with in memory version
     temp_image_loc = Path(__file__).parent.parent.parent / Path("data") / Path("rail_image_annotated.jpg")
     cv.imwrite(str(temp_image_loc), source_color_image)
-    r = requests.put(f"http://localhost:5000/files/file/{temp_image_loc.name}", data=temp_image_loc.read_bytes())
+    r = requests.put(f"{storage_base_uri}/files/file/{temp_image_loc.name}", data=temp_image_loc.read_bytes())
     return (
-        Artefact("reference", f"http://localhost:5000/files/file/{temp_image_loc.name}",f"{filename.stem}_annotated{filename.suffix}" , "image/jpg"),
+        Artefact("reference", f"{storage_base_uri}/files/file/{temp_image_loc.name}",f"{filename.stem}_annotated{filename.suffix}" , "image/jpg"),
         Artefact("inline", f"D: {detected_lines}\nP: {parallel_line_indices}", f"{filename.stem}_annotated.txt", "text/plain")
     )
 
@@ -87,7 +87,12 @@ class OctivaRouter(APIRouter):
                 return JSONResponse(status_code=500, content={"ctrl": "error", "debug": f"File not found on storage backend."})
             temp_image_loc = Path(__file__).parent.parent.parent / Path("data") / Path("rail_image.jpg")
             temp_image_loc.write_bytes(image_response.content)
-            annotated_image_artefact, data_artefact = rail_finder_algo_one(temp_image_loc)
+            storage_base_uri = self.configuration.octiva.storage_base_uri
+            try:
+                annotated_image_artefact, data_artefact = rail_finder_algo_one(temp_image_loc, storage_base_uri)
+            except ConnectionError as e:
+                arklog.exception(e)
+                return JSONResponse(status_code=500, content={"ctrl": "error", "debug": f"Could not connect to endpoint ('{storage_base_uri}'). {e}"})
 
             response = {
                 "ctrl": "ok",