Skip to content

Commit fac21f2

Browse files
committed
./run.sh
1 parent e8673ac commit fac21f2

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ This Python API server provides endpoints for interacting with MobilityDB, a tem
1919
- Make script executable: chmod +x run.sh
2020
- Run only the server: ./run.sh
2121
#### RUN SERVER WITH TESTS
22-
- Download ships datasets from: [Denmark Ships DataSets](http://aisdata.ais.dk/?prefix=2024/) aisdk_2024-08-07.zip in data folder
23-
- Run with integration tests: ./run.sh --with-tests (note: this takes a while due to data preprocessing - expect 23 min )
22+
- Run with integration tests: ./run.sh --with-tests
23+
(note: this takes a while due to data preprocessing - expect 23 min if the json data file is not present, 21 sec otherwise )
24+
- If necessary, download ships datasets from: [Denmark Ships DataSets](http://aisdata.ais.dk/?prefix=2024/) aisdk_2024-08-07.zip in data folder
2425

2526
## Usage
2627
Send http requests to the api using any http service.

run.sh

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ DATA_ZIP_FILENAME="aisdk-2024-08-07.zip" # Expected name of the zip file in da
1313
MANUAL_DOWNLOAD_URL="http://aisdata.ais.dk/?prefix=2024/"
1414
CONFIG_FILE="config.json"
1515
REQUIREMENTS_FILE="requirements.txt"
16-
16+
TRAJECTORIES_FILE="data/trajectories_mf1.json"
1717
show_help() {
1818
echo "Usage: ./run.sh [OPTIONS]"
1919
echo ""
@@ -38,7 +38,7 @@ command -v docker >/dev/null 2>&1 || { echo -e "${RED}Docker not found. Please i
3838
command -v python3 >/dev/null 2>&1 || { echo -e "${RED}Python3 not found.${NC}"; exit 1; }
3939
command -v lsof >/dev/null 2>&1 || { echo -e "${YELLOW}lsof not found. Install it for automatic port killing.${NC}"; }
4040

41-
# CAS PORT ALREADY IN USE
41+
# Free port if already in use
4242
free_port() {
4343
local PORT=$1
4444
if command -v lsof >/dev/null 2>&1; then
@@ -88,7 +88,7 @@ EOF
8888
fi
8989
}
9090

91-
# API port <-fconig.json
91+
# Get API port from config.json
9292
get_api_port() {
9393
if [ -f "$CONFIG_FILE" ]; then
9494
python3 -c "import json; print(json.load(open('$CONFIG_FILE')).get('API_PORT', 8080))" 2>/dev/null || echo "8080"
@@ -136,7 +136,8 @@ start_container() {
136136
echo -e "${YELLOW}Waiting for database to be ready...${NC}"
137137
sleep 5
138138
}
139-
#check for dataset presence
139+
140+
# Check for dataset presence
140141
check_data() {
141142
DATA_DIR="data"
142143
mkdir -p "$DATA_DIR"
@@ -151,7 +152,7 @@ check_data() {
151152
fi
152153
}
153154

154-
# data preprocessing
155+
# Data preprocessing
155156
run_preprocessing() {
156157
if [ ! -f "data/ais_to_json.py" ]; then
157158
echo -e "${RED}Preprocessing script not found: data/ais_to_json.py${NC}"
@@ -181,14 +182,20 @@ run_tests() {
181182
exit $TEST_EXIT
182183
}
183184

184-
185185
setup_config
186186
setup_venv
187187
start_container
188188

189189
if [ "$WITH_TESTS" = true ]; then
190-
check_data
191-
run_preprocessing
190+
191+
if [ -f "$TRAJECTORIES_FILE" ] && [ -s "$TRAJECTORIES_FILE" ]; then
192+
echo -e "${GREEN}Found existing $TRAJECTORIES_FILE (non‑empty). Skipping preprocessing.${NC}"
193+
else
194+
echo -e "${YELLOW}Missing or empty $TRAJECTORIES_FILE. Running preprocessing...${NC}"
195+
check_data
196+
run_preprocessing
197+
fi
198+
192199
run_tests
193200
else
194201
API_PORT=$(get_api_port)

0 commit comments

Comments
 (0)