Quellcode durchsuchen

third task done

denhan vor 2 Jahren
Ursprung
Commit
36cec5aab0
2 geänderte Dateien mit 29 neuen und 10 gelöschten Zeilen
  1. 1 1
      TODO.md
  2. 28 9
      source/frontend/front.py

+ 1 - 1
TODO.md

@@ -5,7 +5,7 @@
     * What is Q circle?
     * What data formats are supported?
 2. [x] Change startup file to main.py and remove os and sys calls from frontend. Pass calc function to frontend function as an argument.
-3. Add validation of separator + convertor to std backend input
+3. [x] Add validation of separator + convertor to std backend input 
 4. Should we apply corrections for coupling losses? - yes, please add this option.
 5. Draw continuous Q circle on a Smith chart using coefficients a[0..2]
 6. Add axes labels to a Smith chart

+ 28 - 9
source/frontend/front.py

@@ -1,6 +1,7 @@
 import streamlit as st
 import matplotlib.pyplot as plt
 import numpy as np
+import math
 
 def plot_data(r,i, g):
     # unit circle
@@ -24,7 +25,8 @@ def plot_data(r,i, g):
     # data
     ax.plot(r, i, 'b+')
     #
-
+    ax.xlabel("x")
+    ax.ylabel("y")
     #cirlce approximation
     t=np.linspace(0,1,100)
     z = (g[0]*t+g[1])/(g[2]+1)
@@ -50,17 +52,34 @@ def run(calc_function):
     select_data_format = col1.selectbox('Choose data format from a list',['Frequency, Re(S11), Im(S11)','Frequency, Re(Zin), Im(Zin)'])
 
     select_separator = col2.selectbox('Choose separator',['","' ,'" "','";"'])
-
-
+    select_coupling_losses = st.checkbox('I want to apply corrections for coupling losses (lossy coupling)')
+    def is_float(element) -> bool:
+        try:
+            float(element)
+            val = float(element)
+            if math.isnan(val) or math.isinf(val):
+                raise ValueError
+            return True
+        except ValueError:
+            return False
     def unpack_data(data):
-        f, r, i = [], [], []  
-        for x in data:
-            a, b, c = (float(y) for y in x.split())
-            f.append(a)  # frequency
-            r.append(b)  # Re of S11
-            i.append(c)  # Im of S11
+        f, r, i = [], [], []
+        if select_data_format == 'Frequency, Re(S11), Im(S11)':
+            for x in range(len(data)):
+                tru = data[x].split(select_separator)
+                if len(tru)!=3:
+                    return f, r, i, 'Bad line in your file. №:' + str(x)
+                a, b, c = (y for y in tru)
+                if not ((is_float(a)) or (is_float(b)) or (is_float(c))):
+                    return f, r, i, 'Bad data. Your data isnt numerical type. Number of bad line:' + str(x)
+                f.append(a)  # frequency
+                r.append(b)  # Re of S11
+                i.append(c)  # Im of S11
+        else:
+            return f, r, i, 'Bad data format'
         return f, r, i, 'very nice'
 
+
     validator_status = 'nice'
     # calculate
     circle_params=[]