-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
67 lines (50 loc) · 1.76 KB
/
app.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
import json
import os
from flask import Flask, request
from solver.rcpsp_solver import solve_rcpsp
from utils.dti_handler import DateTimeIndexParser
app = Flask(__name__)
@app.route("/schedule", methods=["POST"])
def schedule():
json_msg = request.get_data()
# Default return message.
message_dict = {'return_code': '200', 'result': False}
# Get data from json.
if json_msg is None:
message_dict['return_code'] = '5004'
message_dict['return_info'] = '请求参数为空'
return json.dumps(message_dict, ensure_ascii=False)
# Clear last result.
try:
os.remove('preview/json/result.json')
except:
pass
# Call algorithm.
try:
message_dict['result'] = solve_rcpsp(json_msg, timeout=10)
except:
print('Data Error!')
pass
return json.dumps(message_dict, ensure_ascii=False)
@app.route("/dti", methods=["POST"])
def dti():
json_msg = request.get_data()
# Default return message.
message_dict = {'return_code': '200', 'result': False}
# Get data from json.
if json_msg is None:
message_dict['return_code'] = '5004'
message_dict['return_info'] = '请求参数为空'
return json.dumps(message_dict, ensure_ascii=False)
# Call dti handler.
try:
data = json.loads(json_msg)
dti_parser = DateTimeIndexParser(data['start_date'], data['end_date'])
dti_parser.update(data['start_hour'], data['work_duration'], data['week_mask'])
message_dict['result'] = dti_parser.gen_json(data['result']) # ToDo: Can not use gen_json without data_handler.
except:
print('Data Error!')
pass
return json.dumps(message_dict, ensure_ascii=False)
if __name__ == "__main__":
app.run(debug=True)