Exemplo n.º 1
0
def device_start():
    patient_id = request.json['patient_id']
    device_id = request.json['device_id']
    connection = get_connection()
    date_time = datetime.datetime.now()
    data = {'start_time': date_time}
    table_name = 'dp_pair'
    condition = {'device_id': device_id, 'patient_id': patient_id}
    update_data(table_name, data, condition)

    close_connection(connection)
    return str(1)
Exemplo n.º 2
0
def paddle_count():
    patient_id = request.json['patient_id']
    device_id = request.json['device_id']
    connection = get_connection()
    date_time = datetime.datetime.now()
    data = {
        'patient_id': patient_id,
        'device_id': device_id,
        'medium_count': 1,
        'time': date_time
    }
    table_name = 'pedal'
    create_data(table_name, data, connection)
    close_connection(connection)
    return str(1)
Exemplo n.º 3
0
def device_refresh():
    patient_id = request.args.get('patient_id')
    print(patient_id)
    device_id = request.args.get('device_id')
    print(device_id)
    connection = get_connection()
    table_name = 'dp_pair'
    data = {'device_id': device_id, 'patient_id': patient_id}
    row = read_data(table_name, data)
    start_time = row.start_time
    current_time = datetime.datetime.now()
    if (device_id[0:3] == 'SPI'):
        table_name = 'spimo'
    elif (device_id[0:3] == 'PED'):
        table_name = 'pedal'
    row = read_count(table_name, start_time, current_time, device_id)
    result = row.total_count
    close_connection(connection)
    return str(result)
def handle_senti_score_request():
    session_id = request.json['session_id']
    seq = request.json['seq']
    text_senti_score = request.json['sentiment_score']
    again = request.json['again']
    # upadte if record exists
    table_name = 'transaction_table'
    data = {
        'session_id': session_id,
        'seq': seq,
        'text_senti_score': text_senti_score
    }
    connection = get_connection()
    if again == '1':
        condition = {'session_id': session_id, 'seq': seq}
        connection = update_data(table_name, data, condition, connection)
    elif again == '0':
        connection = insert_data(table_name, data, connection)
    close_connection(connection)
    return str(1)
Exemplo n.º 5
0
def register_device():
    patient_id = request.json['patient_id']
    spimo_id = request.json['spimo_id']
    pedal_id = request.json['pedal_id']
    date_time = datetime.datetime.now()
    connection = get_connection()
    table_name = 'dp_pair'

    data = {'device_id': spimo_id}
    row = read_data(table_name, data)
    #scenario 2: No such device_id
    if row is None:
        close_connection(connection)
        return str(2)
    #scenario 1: Successful
    elif row.patient_id is None:
        data = {'patient_id': patient_id, 'updated_date': date_time}
        condition = {'device_id': spimo_id}
        update_data(table_name, data, condition)
        condition = {'device_id': pedal_id}
        update_data(table_name, data, condition)
        close_connection(connection)
        return str(1)
    #scenario 2: duplicated id
    else:
        close_connection(connection)
        return str(0)
def handle_ml():
    session_id = request.json['session_id']
    seq = request.json['seq']
    table_name = 'transaction_table'
    connection = get_connection()
    text_senti_avg, text_senti_std, text_senti_min, text_senti_max = calculate_features(
        table_name, session_id, seq, connection)
    condition = {'session_id': session_id, 'seq': seq}
    features_data = {
        'text_senti_avg': text_senti_avg,
        'text_senti_std': text_senti_std,
        'text_senti_min': text_senti_min,
        'text_senti_max': text_senti_max
    }
    update_data(table_name, features_data, condition, connection)
    r_data = {'session_id': session_id, 'seq': seq}
    rows, number_rows = read_data(table_name, r_data, connection)
    emotion_label = send_request_to_ml(rows)
    features_data = {'result': emotion_label}
    update_data(table_name, features_data, condition, connection)
    close_connection(connection)
    return emotion_label
Exemplo n.º 7
0
def return_device():
    patient_id = request.json['patient_id']
    spimo_id = request.json['spimo_id']
    pedal_id = request.json['pedal_id']
    date_time = datetime.datetime.now()
    connection = get_connection()
    table_name = 'dp_pair'
    data = {'device_id': spimo_id}
    row = read_data(table_name, data)
    # device has been returned
    if row.patient_id is None:
        close_connection(connection)
        return str(0)
    else:
        data = {'patient_id': None, 'updated_date': None}
        condition = {'device_id': spimo_id}
        update_data(table_name, data, condition)
        condition = {'device_id': pedal_id}
        update_data(table_name, data, condition)

        close_connection(connection)
        return str(1)
def handle_request():
    api_result = json.loads(request.form.get('data'))
    seq = api_result["seq"]
    device_id = api_result["device_id"]
    session_id = api_result["session_id"]
    imagefile = request.files['image']
    filename = werkzeug.utils.secure_filename(imagefile.filename)
    imagefile.save(filename)
    with open(filename, 'rb') as f:
        data = f.read()
    _url = 'https://westus2.api.cognitive.microsoft.com/face/v1.0/detect'
    _key = 'bc027dc227484433a77d7b613807d230'  #Here you have to paste your primary key
    headers = dict()
    headers['Ocp-Apim-Subscription-Key'] = _key
    headers['Content-Type'] = 'application/octet-stream'

    json_ = None
    params = {
        'returnFaceId':
        'true',
        'returnFaceLandmarks':
        'false',
        'returnFaceAttributes':
        'age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise',
    }
    result = processRequest(json_, data, headers, params, _url)
    connection = get_connection()
    if result == []:
        date_time = datetime.datetime.now()
        data = {
            'date': date_time,
            'session_id': session_id,
            'seq': seq,
            'device_id': device_id,
            'face_smile': 0,
            'face_anger': 0,
            'face_contempt': 0,
            'face_disgust': 0,
            'face_fear': 0,
            'face_happiness': 0,
            'face_neutral': 0,
            'face_sadness': 0,
            'face_surprise': 0
        }
        table_name = 'transaction_table'
        condition = {'session_id': session_id, 'seq': seq}
        connection = update_data(table_name, data, condition, connection)
        close_connection(connection)
        return str(4)
    elif result is None:
        date_time = datetime.datetime.now()
        data = {
            'date': date_time,
            'session_id': session_id,
            'seq': seq,
            'device_id': device_id,
            'face_smile': 0,
            'face_anger': 0,
            'face_contempt': 0,
            'face_disgust': 0,
            'face_fear': 0,
            'face_happiness': 0,
            'face_neutral': 0,
            'face_sadness': 0,
            'face_surprise': 0
        }
        table_name = 'transaction_table'
        condition = {'session_id': session_id, 'seq': seq}
        connection = update_data(table_name, data, condition, connection)
        close_connection(connection)
        return str(5)
    elif result[0]['faceAttributes'] is None:
        date_time = datetime.datetime.now()
        data = {
            'date': date_time,
            'session_id': session_id,
            'seq': seq,
            'device_id': device_id,
            'face_smile': 0,
            'face_anger': 0,
            'face_contempt': 0,
            'face_disgust': 0,
            'face_fear': 0,
            'face_happiness': 0,
            'face_neutral': 0,
            'face_sadness': 0,
            'face_surprise': 0
        }
        table_name = 'transaction_table'
        condition = {'session_id': session_id, 'seq': seq}
        connection = update_data(table_name, data, condition, connection)
        close_connection(connection)
        return str(6)

    firstface_dic = result[0]
    faceAttributes_dic = firstface_dic['faceAttributes']
    smile = faceAttributes_dic['smile']
    #gender = faceAttributes_dic['gender']
    anger = faceAttributes_dic['emotion']['anger']
    contempt = faceAttributes_dic['emotion']['contempt']
    disgust = faceAttributes_dic['emotion']['disgust']
    fear = faceAttributes_dic['emotion']['fear']
    happiness = faceAttributes_dic['emotion']['happiness']
    neutral = faceAttributes_dic['emotion']['neutral']
    sadness = faceAttributes_dic['emotion']['sadness']
    surprise = faceAttributes_dic['emotion']['surprise']
    connection = get_connection()
    date_time = datetime.datetime.now()
    data = {
        'date': date_time,
        'session_id': session_id,
        'seq': seq,
        'device_id': device_id,
        'face_smile': smile,
        'face_anger': anger,
        'face_contempt': contempt,
        'face_disgust': disgust,
        'face_fear': fear,
        'face_happiness': happiness,
        'face_neutral': neutral,
        'face_sadness': sadness,
        'face_surprise': surprise
    }
    table_name = 'transaction_table'
    condition = {'session_id': session_id, 'seq': seq}
    connection = update_data(table_name, data, condition, connection)
    close_connection(connection)
    return str(1)
def handle_request():
    section_id = request.args.get('section_id')
    seq = request.args.get('seq')
    device_id = request.args.get('device_id')
    imagefile = request.files['image']
    filename = werkzeug.utils.secure_filename(imagefile.filename)
    imagefile.save(filename)
    with open(filename, 'rb') as f:
        data = f.read()
    _url = 'https://westus2.api.cognitive.microsoft.com/face/v1.0/detect'
    _key = 'bc027dc227484433a77d7b613807d230'  #Here you have to paste your primary key
    headers = dict()
    headers['Ocp-Apim-Subscription-Key'] = _key
    headers['Content-Type'] = 'application/octet-stream'

    json = None
    params = {
        'returnFaceId':
        'true',
        'returnFaceLandmarks':
        'false',
        'returnFaceAttributes':
        'age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise',
    }

    result = processRequest(json, data, headers, params, _url)

    if result == []:
        return 'no face'
    elif result is None:
        return 'no picture'
    firstface_dic = result[0]
    #print(result[0])
    faceAttributes_dic = firstface_dic['faceAttributes']
    #print(faceAttributes_dic)
    #interval = math.ceil(sec/10)
    smile = faceAttributes_dic['smile']
    gender = faceAttributes_dic['gender']
    #age = faceAttributes_dic['age']
    anger = faceAttributes_dic['emotion']['anger']
    contempt = faceAttributes_dic['emotion']['contempt']
    disgust = faceAttributes_dic['emotion']['disgust']
    fear = faceAttributes_dic['emotion']['fear']
    happiness = faceAttributes_dic['emotion']['happiness']
    neutral = faceAttributes_dic['emotion']['neutral']
    sadness = faceAttributes_dic['emotion']['sadness']
    surprise = faceAttributes_dic['emotion']['surprise']
    connection = get_connection()
    date_time = datetime.datetime.now()
    data = {
        'date': date,
        'session_id': section_id,
        'seq': section_id,
        'device_id': device_id,
        'face_smile': smile,
        'face_anger': anger,
        'face_contempt': contempt,
        'face_disgust': disgust,
        'face_fear': fear,
        'face_happiness': happiness,
        'face_neutral': neutral,
        'face_sadness': sadness,
        'face_surprise': surprise
    }
    #data = {'face_smile_prob':smile}
    table_name = 'test'
    create_data(table_name, data, connection)
    close_connection(connection)
Exemplo n.º 10
0
    data = ser.readline()
    if data != '' and data != "\r\n":
        data_new = data.decode('utf-8')
        data_number = (data_new[0:(len(data_new) - 2)])
        print(data_number)
        return data_number


if __name__ == "__main__":
    flag = True
    connection = get_connection()
    device_id = "001"
    patient_id = "001"
    while flag:
        id = "1"
        date = datetime.datetime.now()
        value = read_per_breath()
        data = {
            'id': id,
            'date': date,
            'value': value,
            'device_id': device_id,
            'patient_id': patient_id
        }
        table_name = 'lung_transaction'
        create_data(table_name, data, connection)

    close_connection(connection)

print("done")