import os from M1 import find_anomalous, correct_signal def get_file(): while True: name = input("Имя файла: ") if (os.getcwd() + "/TEMA9/" + name): return (os.getcwd() + "/TEMA9/" + name) print("Файл не найден") def get_M(): while True: try: M1 = float(input("M1: ")) M2 = float(input("M2: ")) if M1 < M2: return M1, M2 print("M1 должно быть < M2") except: print("Введите числа") def read_file(filename): X = [] with open(filename, 'r') as f: for line in f: for num in line.split(): X.append(float(num)) return X def save_binary(X1): with open(os.getcwd() + "/TEMA9/Res44.bin", 'wb') as f: for val in X1: f.write(str(val).encode() + b' ') def main(): filename = get_file() X = read_file(filename) print(f"Прочитано {len(X)} значений") M1, M2 = get_M() K = find_anomalous(X, M1, M2) print(f"Аномалии: {K}") if K: X1 = correct_signal(X, K) print(f"Исправлено: {X1[:10]}...") save_binary(X1) else: print("Аномалий нет") return X, X1 if K else None