-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample_project.py
62 lines (48 loc) · 1.65 KB
/
sample_project.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
import requests
import json
import pandas as pd
from solver.rcpsp_solver import solve_rcpsp
from utils.dti_handler import DateTimeIndexParser
def post(data, server="http://127.0.0.1:5000", page='/schedule'):
"""
Post data to server and get response.
:param data: dict.
:param server:
:param page:
:return: dict.
"""
with open('data%s_input.json' % page, 'w') as f:
f.write(json.dumps(data))
data = json.dumps(data)
r = requests.post(server + page, data=data)
result = json.loads(r.text)['result']
with open('data%s_output.json' % page, 'w') as f:
f.write(json.dumps(result))
return result
def run():
# Set calendar.
calendar = {'start_date': '2021-02-21',
'end_date': '2022-01-01',
'start_hour': '10:00',
'work_duration': 8,
'week_mask': 'Mon Tue Wed Thu Fri Sat Sun',
}
dti_parser = DateTimeIndexParser(
calendar['start_date'], calendar['end_date'])
dti_parser.update(weekmask=calendar['week_mask'])
# Load data set.
# input_data = dti_parser.data_handler(tasks_df, resource_df)
with open('data/schedule_input.json', 'r') as f:
input_data = json.loads(f.read())
# Solve problem.
output_data = post(input_data) # Call remote solver
# result = solve_rcpsp(json.loads(input_data), timeout=10) # Use local solver.
# Format result.
data = calendar
data['result'] = output_data
result = post(data, page='/dti')
with open('preview/json/result.json', 'w') as f:
f.write(json.dumps(result))
print('COMPLETED!')
if __name__ == "__main__":
run()