-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
97 lines (83 loc) · 3.33 KB
/
script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# coding=utf-8
from flask import Flask, request
from flask_cors import CORS
import json
from classes import NeuralNetMaster
from db import *
app = Flask(__name__)
CORS(app)
# Добавление всех пациентов в БД
# @app.route("/add_patients", methods=["GET"])
# def add_patients():
# connector = connectToDB()
# result = add_pattients_to_db_from_csv(connector, 'data.csv')
# return result
# Добавление здорового пациента в БД Тест
@app.route("/add_patient_test", methods=["GET"])
def add_patient_test():
data = ['null', 0, 18, 1.64, 60, 78, 22.30814991, 35, 27,
37, 35696.20969, 69, 55, 55]
connector = connectToDB()
result = add_new_patient(connector, data)
return result
# Получить всех пользователей
@app.route("/getPatients", methods=["GET"])
def get_patients():
return json.dumps(get_all_users(connectToDB()))
# Удалить пользователя
@app.route("/deletePatient", methods=["POST"])
def delete_patients():
post = request.get_json(silent=True)
id = post['deletedPatient']
delete_patient(connectToDB(), id)
return json.dumps(get_all_users(connectToDB()))
# Добавление здорового пациента в БД
@app.route("/addPatient", methods=["POST"])
def add_patient():
post = request.get_json(silent=True)
print('post', post)
data = ['null', post['sex'], post['age'], post['height'], post['bodyMass'],
post['chest'], post['bodyMassIndex'], post['shoulder'],
post['forearm'], post['shin'], post['lean'],
post['mep'], post['mip'], post['snip']]
connector = connectToDB()
result = add_new_patient(connector, data)
return json.dumps(get_all_users(connectToDB()))
# Получение ответа
@app.route("/answer", methods=["POST"])
def get_answer():
post = request.get_json(silent=True)
data = [post['sex'], post['age'], post['height'], post['bodyMass'],
post['chest'], post['bodyMassIndex'], post['shoulder'],
post['forearm'], post['shin'], post['lean']]
query_type = 'get_answer'
type_for_analize = post['type']
answer = NeuralNetMaster("data.csv", type_for_analize, query_type, data)
return str(answer.RESULT)
# Получение ответа о конретном пациенте
@app.route("/answer_id", methods=["POST"])
def get_answer_by_id():
post = request.get_json(silent=True)
id = post['id']
connector = connectToDB()
print('say hello!')
return str('hey')
# Обучение нейронной сети
@app.route("/train_mep", methods=["GET"])
def send_for_train_mep():
NeuralNetMaster("data.csv", 'mep', 'train', None)
return "Обучение 'mep' прошло успешно!\n"
@app.route("/train_mip", methods=["GET"])
def send_for_train_mip():
NeuralNetMaster("data.csv", 'mip', 'train', None)
return "Обучение 'mip' прошло успешно!\n"
@app.route("/train_snip", methods=["GET"])
def send_for_train_snip():
NeuralNetMaster("data.csv", 'snip', 'train', None)
return "Обучение 'snip' прошло успешно!\n"
# Тестирование, что все работает
@app.route("/test", methods=["GET"])
def test():
return "Flask is working.\n"
if __name__ == '__main__':
app.run(debug=True, threaded=True)