2025-08-02 11:53:58 +02:00
|
|
|
|
2025-08-02 00:45:04 +02:00
|
|
|
docker compose down --remove-orphans
|
|
|
|
rm -rf data || true
|
|
|
|
cp -r data-copy data
|
|
|
|
chmod 777 data
|
|
|
|
docker volume rm c3nav-postgres c3nav-redis || true
|
|
|
|
docker volume create c3nav-postgres
|
|
|
|
docker volume create c3nav-redis
|
|
|
|
|
|
|
|
# Start only postgres and redis first (no build since we pre-built)
|
|
|
|
docker compose up -d postgres redis
|
|
|
|
|
2025-08-02 11:32:01 +02:00
|
|
|
sleep 10
|
2025-08-02 00:45:04 +02:00
|
|
|
cat ./db/auth_user.sql | docker exec -i local_run-postgres-1 su - postgres -c 'psql c3nav'
|
|
|
|
|
|
|
|
|
|
|
|
# Load database dump before starting the main app
|
2025-08-02 07:58:27 +02:00
|
|
|
cat ./db/dump.sql | docker exec -i local_run-postgres-1 su - postgres -c 'psql c3nav' > /dev/null
|
2025-08-02 00:45:04 +02:00
|
|
|
|
|
|
|
# Fix geometry access permissions for anonymous users
|
|
|
|
docker exec -i local_run-postgres-1 psql -U postgres -d c3nav -c "UPDATE mapdata_space SET base_mapdata_accessible = true;"
|
|
|
|
|
|
|
|
# Now start the main services (no build since we pre-built)
|
|
|
|
docker compose up --build -d
|
|
|
|
echo "Creating Django superuser"
|
|
|
|
# docker exec -i local_run-c3nav-core-1 sh -c "echo \"from django.contrib.auth.models import User; [0].set_password('admin'); User.objects.get(username='admin').save()\" | /app/env/bin/python manage.py shell"
|
|
|
|
docker exec -i local_run-c3nav-core-1 sh -c "echo \"
|
|
|
|
from django.contrib.auth.models import User
|
|
|
|
user = User.objects.get_or_create(username='admin', defaults={'email': 'admin@example.com', 'is_superuser': True, 'is_staff': True})[0]
|
|
|
|
user.set_password('admin')
|
|
|
|
user.save()
|
|
|
|
print('Password set successfully for user:', user.username)
|
|
|
|
\" | /app/env/bin/python manage.py shell"
|
|
|
|
|
|
|
|
|
2025-08-02 11:53:58 +02:00
|
|
|
# Apply migrations after loading dump
|
|
|
|
echo "Applying migrations..."
|
2025-08-02 00:45:04 +02:00
|
|
|
docker exec -i local_run-c3nav-core-1 sh -c '/app/env/bin/python manage.py migrate --fake'
|
2025-08-02 11:53:58 +02:00
|
|
|
echo "Creating new migrations for sensor_data field..."
|
|
|
|
docker exec -i local_run-c3nav-core-1 sh -c '/app/env/bin/python manage.py makemigrations mapdata'
|
|
|
|
echo "Applying new migrations..."
|
|
|
|
docker exec -i local_run-c3nav-core-1 sh -c '/app/env/bin/python manage.py migrate mapdata'
|
2025-08-02 00:45:04 +02:00
|
|
|
|
|
|
|
docker compose ps -a
|
|
|
|
docker exec -i local_run-c3nav-core-1 sh -c '/app/env/bin/python manage.py clearmapcache --include-history --include-geometries && /app/env/bin/python manage.py collectstatic -l --no-input'
|
|
|
|
|
|
|
|
# Fix NumPy compatibility issue
|
|
|
|
echo "Applying NumPy compatibility fix..."
|
|
|
|
docker exec -i local_run-c3nav-core-1 sed -i 's/np\.fromstring(/np.frombuffer(/g' /app/c3nav/mapdata/utils/cache/indexed.py
|
|
|
|
|
|
|
|
# Process map updates to rebuild cache with NumPy fix
|
|
|
|
echo "Processing map updates to rebuild cache..."
|
|
|
|
docker exec -i local_run-c3nav-core-1 sh -c '/app/env/bin/python manage.py processupdates'
|
|
|
|
|
2025-08-02 11:53:58 +02:00
|
|
|
# Setup sensor overlays
|
|
|
|
echo "Setting up sensor overlays..."
|
|
|
|
docker compose exec -T c3nav-core python manage.py shell << 'EOF'
|
|
|
|
from c3nav.mapdata.models import DataOverlay, DataOverlayFeature
|
|
|
|
|
|
|
|
# Clear old overlays to avoid conflicts
|
|
|
|
DataOverlay.objects.filter(titles__en__icontains='Environmental').delete()
|
|
|
|
DataOverlay.objects.filter(titles__en__icontains='Temperature').delete()
|
|
|
|
|
2025-08-02 12:03:57 +02:00
|
|
|
# Create single NOI environmental sensor overlay with multiple sensors configuration
|
2025-08-02 11:53:58 +02:00
|
|
|
overlay = DataOverlay.objects.create(
|
|
|
|
titles={'en': 'NOI Environmental Sensors'},
|
|
|
|
description='Real-time CO2 and temperature sensors from NOI Open Data Hub - displays current readings with values and units',
|
|
|
|
default_geomtype='point',
|
2025-08-02 12:03:57 +02:00
|
|
|
data_source_url='https://mobility.api.opendatahub.com/v2/flat/IndoorStation/*/latest',
|
2025-08-02 11:53:58 +02:00
|
|
|
sensor_config={
|
|
|
|
'data_path': 'data',
|
|
|
|
'mappings': {
|
|
|
|
'id_field': 'scode',
|
2025-08-02 12:03:57 +02:00
|
|
|
'name_field': 'sname',
|
|
|
|
'x_field': 'scoordinate.x',
|
|
|
|
'y_field': 'scoordinate.y'
|
|
|
|
},
|
|
|
|
'sensors': [
|
|
|
|
{
|
|
|
|
'id': 'NOI:FreeSoftwareLab-Temperature',
|
|
|
|
'coordinates': {'x': 291.0, 'y': 241.0},
|
|
|
|
'level': 'floor1'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'id': 'NOI:NOI-A1-Floor1-CO2',
|
|
|
|
'coordinates': {'x': 270.0, 'y': 241.0},
|
|
|
|
'level': 'floor1'
|
2025-08-02 11:53:58 +02:00
|
|
|
}
|
2025-08-02 12:03:57 +02:00
|
|
|
]
|
2025-08-02 11:53:58 +02:00
|
|
|
},
|
|
|
|
update_interval=120
|
|
|
|
)
|
|
|
|
print(f"NOI sensor overlay created with ID {overlay.id}")
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
2025-08-02 12:03:57 +02:00
|
|
|
# Scrape real NOI sensor data
|
2025-08-02 11:53:58 +02:00
|
|
|
echo "Scraping NOI sensor data..."
|
|
|
|
# Give the database a moment to settle after overlay creation
|
|
|
|
sleep 2
|
|
|
|
|
2025-08-02 12:03:57 +02:00
|
|
|
# Scrape the overlay data (should automatically discover all configured sensors)
|
|
|
|
echo "Scraping overlay data (ID: 1)..."
|
2025-08-02 11:53:58 +02:00
|
|
|
docker compose exec -T c3nav-core python manage.py manage_sensors --scrape-data --overlay-id 1
|
|
|
|
|
2025-08-02 12:03:57 +02:00
|
|
|
# List all sensors to verify setup
|
|
|
|
echo "Listing all sensors in the overlay..."
|
|
|
|
docker compose exec -T c3nav-core python manage.py list_sensors --overlay-id 1
|
2025-08-02 11:53:58 +02:00
|
|
|
|
|
|
|
echo "Sensor setup completed!"
|
2025-08-02 12:03:57 +02:00
|
|
|
echo ""
|
|
|
|
echo "To add a new sensor to the overlay, use:"
|
|
|
|
echo "docker compose exec -T c3nav-core python manage.py add_sensor --overlay-id 1 --sensor-id 'NOI:YourSensorID' --name 'Your Sensor Name' --x 300.0 --y 250.0 --level floor1"
|
|
|
|
echo ""
|
|
|
|
echo "To scrape data for all sensors:"
|
|
|
|
echo "docker compose exec -T c3nav-core python manage.py manage_sensors --scrape-data --overlay-id 1"
|
2025-08-02 11:53:58 +02:00
|
|
|
|