ответвлено от main/python-labs
42 строки
1.3 KiB
Python
42 строки
1.3 KiB
Python
import os
|
|
from Mod1 import find_anomalies, correct_anomalies
|
|
|
|
|
|
def process_signal():
|
|
while True:
|
|
filename = input("Введите имя файла с данными: ")
|
|
if os.path.exists(filename):
|
|
break
|
|
print(f"Файл '{filename}' не найден.")
|
|
|
|
while True:
|
|
T1 = float(input("Введите значение T1: "))
|
|
T2 = float(input("Введите значение T2: "))
|
|
if T1 < T2:
|
|
break
|
|
print("T1 должно быть меньше T2.")
|
|
|
|
X = []
|
|
with open(filename, 'r') as f:
|
|
for line in f:
|
|
line = line.strip()
|
|
if line:
|
|
X.append(float(line))
|
|
|
|
X_tuple = tuple(X)
|
|
|
|
anomalies = find_anomalies(X_tuple, T1, T2)
|
|
print(f"Найдено аномальных отсчетов: {len(anomalies)}")
|
|
print(f"Индексы: {anomalies}")
|
|
|
|
if anomalies:
|
|
X1_tuple = correct_anomalies(X_tuple, anomalies)
|
|
|
|
with open('Res33.txt', 'w') as f:
|
|
f.write(f"X: {X_tuple}\nX1: {X1_tuple}\nИндексы: {anomalies}\nT1={T1}, T2={T2}")
|
|
|
|
return X_tuple, X1_tuple, anomalies
|
|
else:
|
|
print("Аномальные отсчеты отсутствуют.")
|
|
return X_tuple, None, anomalies
|