Ejemplo n.º 1
0
def main(argv):
    """
    When the model has built, then load data real-time to predict the state at the moment.

    :param argv:
    argv[0]: client ID
    argv[1]: connect_port_name

    :return:
    """
    _ID = argv[0]
    _PORT_NAME = argv[1]

    model = Model.read_from_file(_ID)
    p_model = PresentationModel.apply(model)

    print('>> Start to receive data...')

    # open serial port
    ser = serial.Serial(_PORT_NAME, 9600)
    for _ in range(20):
        ser.readline()

    while True:
        try:
            # retrieve the line
            line = ser.readline().decode()
            data = [float(val) for val in line.split(',')]

            # no missing column in the data
            if len(data) == 3:
                # calculate mean gap
                p_model.add(data)

                # is "gap" in K-envelope?
                state = p_model.predict()
                print("OK" if state == 0 else "warning !!!")

                # put result into the target file
                fp = open(p_model.TARGET_FILE, 'w')
                fp.write(str(state))
                fp.close()

        except KeyboardInterrupt:
            print('>> exiting !')
            break
        except IOError:
            continue
Ejemplo n.º 2
0
def main(argv):
    """
    When the model has built, then load data real-time to predict the state at the moment.

    :param argv:
    argv[0]: client_ID
    argv[1]: connect_port_name
    :return:
    """
    _ID = argv[0]
    _PORT_NAME = argv[1]

    model = Model.read_from_file(_ID)
    p_model = PresentationModel.apply(model)

    print('>> Start to receive data...')

    # open serial port
    ser = serial.Serial(_PORT_NAME, 9600)
    for _ in range(20):
        ser.readline()

    while True:
        try:
            line = ser.readline()
            data = [float(val) for val in line.decode().split(',')]
            if len(data) == 3:
                p_model.add_to_buffer(data)

                prediction = p_model.predict()
                p_model.add_to_pool(prediction)

                print(p_model.mean_buffer)
                print('%f => res:%d' % (p_model.now_mean, prediction))

                fp = open(p_model.TARGET_FILE, 'w')
                fp.write(str(p_model.take_result()))
                fp.close()

        except KeyboardInterrupt:
            break
    # close serial
    ser.flush()
    ser.close()
Ejemplo n.º 3
0
def main(argv):
    """
    When the model has built, then load data real-time to predict the state at the moment.

    :param argv:
    argv[0]: client_ID
    argv[1]: file_name (with .csv)
    :return:
    """
    _ID = argv[0]
    _FILE_NAME = argv[1]

    model = Model.read_from_file(_ID)
    p_model = PresentationModel.apply(model)

    print('>> Start to receive data...')

    fp = open(_FILE_NAME, 'r')

    for line in fp:
        try:
            data = [float(val) for val in line.split(',')[1:]]
            if len(data) == 3:
                p_model.add_to_buffer(data)

                prediction = p_model.predict()
                p_model.add_to_pool(prediction)

                print(p_model.mean_buffer)
                print('%f => res:%d' % (p_model.now_mean, prediction))

                fp = open(p_model.TARGET_FILE, 'w')
                fp.write(str(p_model.take_result()))
                fp.close()

        except KeyboardInterrupt:
            break
    # close serial
    fp.close()