def tolerance_handler(time_more, time_less, value_more, value_less): """Принимает четыре значения допусков и записывает их в базу данных""" session = Session() # ищем такой допуск в бд tolerance_from_bd = MainappTolerance.get_tolerance_by_data( session, time_more, time_less, value_more, value_less) if not tolerance_from_bd: tolerance = MainappTolerance(time_more, time_less, value_more, value_less) session.add(tolerance) session.commit() return tolerance.id else: return tolerance_from_bd.id
def intervals_calculation(new_dots): """Формирует из массива объектов новых точек интервалы (как между ними, так и между ними и точками в БД) и записывает их в БД""" session = Session() while len(new_dots) > 0: work_dot = new_dots.pop() for dot in new_dots: interval = MainappIntervals(work_dot.id, dot.id, abs(work_dot.time - dot.time)) session.add(interval) for old_dot in OLD_DOTS: interval = MainappIntervals(work_dot.id, old_dot.id, abs(work_dot.time - old_dot.time)) session.add(interval) session.commit()
def make_comments(): """Создает комменты для вводимых пользователем точек.""" while True: user_choice = input('Хотите добавить коммент? y/n: ') if user_choice == 'y': input_time = input('Введите time точки: ') input_value = input('Введите value точки: ') session = Session() dot = MainappDots.get_dot_by_time_and_value( session, input_time, input_value) if dot: user_comment = input( 'Точку нашли. Какой комментарий оставить:') dot.comment = user_comment session.commit() print('Готово!') else: print('Нет такой точки.') session.close() else: exit()
def get_dots_and_put_to_bd(): """Обрабатывает файл с данными.""" new_dots_obj = list() with open(default_file_path, 'r') as f: HEADER = f.read(HEADER_LEN) tolerance_id = tolerance_handler(byte_to_int(f.read(1)), byte_to_int(f.read(1)), byte_to_int(f.read(1)), byte_to_int(f.read(1))) session = Session() for _ in range(TOTAL_DOTS): time = byte_to_int(f.read(1)) value = byte_to_int(f.read(1)) # ищем эту точку в БД: dot_in_bd = MainappDots.get_dot_by_time_and_value( session, time, value) if not dot_in_bd: dot = MainappDots(time, value, tolerance_id) session.add(dot) new_dots_obj.append(dot) session.commit() return new_dots_obj