Skip to content

Commit 3b1b143

Browse files
authored
Merge pull request #28 from datakind/input_config_manager
Refactor input and output data.
2 parents ba4b477 + 1b476bd commit 3b1b143

31 files changed

+1676
-964
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ __pycache__/
33
*.py[cod]
44
*$py.class
55

6+
gdrive_creds.json
7+
dkroutingtool/src/creds
8+
69
# C extensions
710
*.so
811

dkroutingtool/README.md

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Within this folder (dkroutingtool) run:
1414
`sh s_build_docker_dev.sh`
1515

1616

17-
### Running Model
17+
### Running Application
1818
You can run the image interactively with the following:
1919

2020
`sh local_start.sh`
@@ -55,16 +55,42 @@ data otherwise), you can force an osm update by running the following script (be
5555
<br>
5656

5757
-----------------------------------------------------------
58+
### File input and output structure
5859

59-
## Other Options
60+
Running in cloud mode:
61+
When running using the cloud provider the tool will download all input data from the cloud
62+
into the local data directory in WORKING_DATA_DIR/input_data/<scenario>-datetime/ folder and
63+
then read from that directory. All outputs are put into WORKING_DATA_DIR/output_data/<scenario>-datetime/.
64+
This is then zipped and uploaded to the output/ directory in the root cloud folder.
6065

61-
### Running the Manual Update (Dev)
62-
Download `manual_routes_edit.xlsx` file from the docker container, edit as needed and copy back into the docker container.
63-
Then get into the docker container and run:
66+
Running in local mode:
67+
When running locally the tool will read from the data/ directory and write to the same
68+
WORKING_DATA_DIR/output_data/<scenario>-datetime/ directory. for the output.
6469

65-
`PYTHONPATH=./py-lib:src/py /opt/conda/bin/python src/py/main_application.py --local --manual`
70+
------------------------------------------------------------------------------
71+
### Running the model with google drive output (for DEVELOPERS)
72+
You can run the model with google drive by putting your credentials in src/creds/gdrive_creds.json
6673

67-
<br>
68-
<br>
74+
Then create a version of scripts/run_app.sh with the folder ids filled in (you can access these) by right
75+
clicking your files in google drive -> copy link -> and extracting the id in the URI.
76+
77+
Then you can run it in the docker environment as follows:
78+
79+
export CLOUDCONTEXT=gdrive
80+
export GDRIVECUSTOMERFILEID=...
81+
export GDRIVEEXTRAFILEID=...
82+
export GDRIVEROOTFOLDERID=...
83+
export GDRIVECREDSFILE=src/creds/gdrive_creds.json
84+
85+
# Local mode
86+
/opt/conda/bin/python src/py/main_application.py --input test_scenario --local
87+
88+
# Local Manual Mode
89+
/opt/conda/bin/python src/py/main_application.py --input test_scenario --manual_input_path WORKING_DATA_DIR/output_data/test_scenario_2022_09_16_19_38/manual_edits --local
90+
91+
# Cloud mode
92+
/opt/conda/bin/python src/py/main_application.py --input test_scenario
93+
94+
# Cloud manual mode
95+
/opt/conda/bin/python src/py/main_application.py --input test_scenario --manual
6996

70-
------------------------------------------------------------------------------

dkroutingtool/local_start.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
docker run -it \
22
--mount src=`pwd`/src,target=/src,type=bind \
33
--mount src=`pwd`/scripts,target=/scripts,type=bind \
4-
-p 8080:8080 dkroutingtool:dev bash
4+
-p 8080:8080 \
5+
-p 5001:5001 \
6+
dkroutingtool:dev bash
57

dkroutingtool/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ cryptography==3.2
1010
decorator==4.4.0
1111
docutils==0.14
1212
et-xmlfile==1.0.1
13+
flask==2.1.3
1314
folium==0.9.1
1415
geojson==2.4.1
1516
idna==2.8
@@ -55,5 +56,6 @@ google-api-python-client==1.12.5
5556
google-auth==1.23.0
5657
google-auth-httplib2==0.0.4
5758
google-auth-oauthlib==0.4.2
59+
oauth2client==3.0.0
5860
googleapis-common-protos==1.52.0
5961
ruamel.yaml==0.16.12
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export CLOUDCONTEXT=gdrive
2+
export GDRIVECUSTOMERFILEID=
3+
export GDRIVEEXTRAFILEID=
4+
export GDRIVEROOTFOLDERID=
5+
export GDRIVECREDSFILE=src/creds/gdrive_creds.json
6+
7+
# Local mode
8+
#/opt/conda/bin/python src/py/main_application.py --input test_scenario --local
9+
10+
# Local Manual Mode
11+
#/opt/conda/bin/python src/py/main_application.py --input test_scenario --manual_input_path WORKING_DATA_DIR/output_data/test_scenario_2022_09_16_19_38/manual_edits --local
12+
13+
# Cloud mode
14+
/opt/conda/bin/python src/py/main_application.py --input test_scenario
15+
16+
# Cloud manual mode
17+
#/opt/conda/bin/python src/py/main_application.py --input test_scenario --manual
18+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
export PYTHONPATH=py-lib:src/py
3+
4+
/opt/conda/bin/python src/py/main_application.py --local --manual
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export PYTHONPATH=./py-lib:./src/py
2+
3+
/opt/conda/bin/python src/py/api/main.py

dkroutingtool/src/py/api/main.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""Simple Flask API stub.
2+
3+
/route
4+
Currently runs the route optimization and returns the solution text
5+
6+
"""
7+
8+
import time
9+
from flask import Flask
10+
from run_routing import run_routing_from_config
11+
from config.config_manager import ConfigManager, GPSInputPaths, ConfigFileLocations
12+
from output.route_solution_data import SolutionOutput
13+
14+
15+
app = Flask(__name__)
16+
PORT = 5001
17+
18+
@app.route('/route', methods=['POST'])
19+
def route():
20+
root_dir = './'
21+
config_manager = ConfigManager.load(
22+
ConfigFileLocations(
23+
routing_config_file=f"{root_dir}/data/config.json",
24+
build_parameters_file=f"{root_dir}build_parameters.yml",
25+
gps_input_files=GPSInputPaths(
26+
gps_file=f"{root_dir}data/customer_data.xlsx",
27+
custom_header_file=f"{root_dir}data/custom_header.yaml",
28+
gps_extra_input_file=f"{root_dir}data/extra_points.csv"
29+
),
30+
manual_edits_input_files=None
31+
)
32+
)
33+
solution_data, vis_data = run_routing_from_config(config_manager)
34+
# TODO: come up with better way to serialize this data.
35+
solution_output = SolutionOutput(solution_data)
36+
solution_txt = solution_output.serialize_solution()
37+
38+
# Return the solution text.
39+
return {"solution": solution_txt}
40+
41+
if __name__ == '__main__':
42+
app.run(host="0.0.0.0", port=PORT)

0 commit comments

Comments
 (0)