Skip to main content

Mock Data Setup

This guide explains how to set up mock data for the tracking system using the setup_mock_data_direct.py script.

Overview

The script creates a comprehensive set of mock data for the tracking system, including:

  • Storage locations in European cities (Paris, Madrid, Copenhagen, Athens, Munich)
  • Delivery locations in European cities (Amsterdam, Prague, Helsinki, Ljubljana, Milan)
  • Status history for trackers showing progression through states:
    • CREATED → IN_TRANSIT → IN_STORAGE → IN_TRANSIT → DELIVERED
  • Location reports that align with status changes
  • Transit points between locations with varying confidence levels
  • Updated tracker records with current status, transit times, and storage times

Running the Script

To run the script:

python -m setup_mock_data_direct

The script uses a transaction to ensure data consistency and will roll back if any part of the process fails.

Data Distribution

The script creates a distribution of trackers in different states:

  • Approximately 20 trackers in DELIVERED status
  • A few trackers in IN_STORAGE status
  • Several trackers in IN_TRANSIT status
  • The majority of trackers in CREATED status

This distribution allows for testing various aspects of the tracking system, including:

  • Status change notifications
  • Transit time calculations
  • Storage time calculations
  • Location history visualization
  • Geofence processing

Verification

The script includes verification steps that output:

  • The count of trackers in each status
  • The total number of location reports
  • The count of status history entries by status

This information is logged to the console when the script runs.

Customization

If you need to modify the script:

  1. Adjust the number of trackers by changing the LIMIT value in the tracker_data CTE
  2. Modify the date distribution by adjusting the CASE statement in the tracker_data CTE
  3. Add or change cities by modifying the european_cities CTEs
  4. Adjust the status progression by modifying the status history INSERT statements

Materialized Views

The script includes commented-out lines for refreshing materialized views. If you need to refresh these views, uncomment the following lines:

CALL refresh_continuous_aggregate('location_history_hourly', (NOW() - INTERVAL '1 month')::timestamp without time zone, (NOW() + INTERVAL '1 hour')::timestamp without time zone);
CALL refresh_continuous_aggregate('location_history_daily', (NOW() - INTERVAL '1 month')::timestamp without time zone, (NOW() + INTERVAL '1 day')::timestamp without time zone);
REFRESH MATERIALIZED VIEW CONCURRENTLY location_history;
SELECT match_geofences();

Troubleshooting

If you encounter errors:

  1. Check that the database is accessible
  2. Verify that the required tables exist
  3. Ensure there are trackers in the database
  4. Check that the production runs exist
  5. Look for any constraint violations in the error messages