.cortex/skills/route-deviation/SKILL.md
Deploy the Route Deviation Analysis demo: create projection views from SYNTHETIC_DATASETS.UNIFIED, run 3-step ETL pipeline, and register React dashboard pages. Works with any vehicle type configured via CONFIG table. Use when: setting up route deviation demo, detour analytics, fleet deviation analysis. Do NOT use for: general fleet tracking, real-time GPS monitoring, or non-deviation routing tasks. Triggers: deploy route deviation, deploy detour analytics, setup deviation analysis, route deviation demo.
npx skillsauth add snowflake-labs/sfguide-create-a-route-optimisation-and-vehicle-route-plan-simulator route-deviationInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
End-to-end deployment of a Route Deviation Analysis demo comparing actual GPS paths against expected routes to detect detours, delays, and anomalies. Data Studio generates both actual and planned routes in SYNTHETIC_DATASETS.UNIFIED, so no ORS batch routing is needed. Vehicle-type agnostic -- works with trucks, taxis, e-bikes, e-scooters, or any fleet type via CONFIG table.
CRITICAL: Verify these before starting:
SYNTHETIC_DATASETS.UNIFIED (any vehicle type)| Privilege | Scope | Reason | |-----------|-------|--------| | CREATE DATABASE | Account | Creates FLEET_INTELLIGENCE database | | CREATE WAREHOUSE | Account | Creates ROUTING_ANALYTICS warehouse | | USAGE ON DATABASE SYNTHETIC_DATASETS | Database | Reads UNIFIED source data | | USAGE ON SCHEMA SYNTHETIC_DATASETS.UNIFIED | Schema | Reads FACT_VEHICLE_TELEMETRY, FACT_TRIPS, DIM_FLEET, DIM_POIS, DIM_TRIP_SCHEDULE | | CREATE SCHEMA | Database (FLEET_INTELLIGENCE) | Creates ROUTE_DEVIATION schema | | CREATE TABLE | Schema (FLEET_INTELLIGENCE.ROUTE_DEVIATION) | Creates ETL output tables | | CREATE VIEW | Schema (FLEET_INTELLIGENCE.ROUTE_DEVIATION) | Creates VW_ projection views |
Note: ACCOUNTADMIN is NOT required. Create a custom role with the above privileges, or use any role that has them.
| Parameter | Default | Description |
|-----------|---------|-------------|
| TARGET_DB | FLEET_INTELLIGENCE | Database for ETL output tables |
| TARGET_SCHEMA | ROUTE_DEVIATION | Schema for ETL output tables |
| WAREHOUSE | ROUTING_ANALYTICS | Warehouse for ETL execution |
Follow the Error Logging convention in AGENTS.md. Log file prefix:
route-deviation.
snowflake_sql_execute tool call. Multi-statement blocks can silently fail. This rule applies to the snowflake_sql_execute tool only; snow sql -f and other CLI execution is fine.{TARGET_DB}.{TARGET_SCHEMA}.<table>.COMMENT = '{"origin":"sf_sit-is-fleet","name":"oss-route-deviation",...}'. See references/sql-pipeline.md for tagged SQL.The fastest path to a working demo. Creates projection views over SYNTHETIC_DATASETS.UNIFIED tables (loaded by build-routing-solution Step 8), then runs ETL to produce analysis tables. No Data Studio generation needed.
SELECT COUNT(*) FROM FLEET_INTELLIGENCE.ROUTE_DEVIATION.TRIP_DEVIATION_ANALYSIS;
If the table exists and has rows, data is already loaded. Skip to Step 5 (Verify End-to-End).
Execute references/seed-data.sql. This creates CONFIG, 5 projection views, and 3 ETL tables (TRIP_DEVIATION_ANALYSIS, DRIVER_DEVIATION_SUMMARY, DAILY_DEVIATION_TRENDS) computed from the views.
Before executing SQL, consult references/sql-pipeline.md for the exact SQL statements. For dataset details, consult references/dataset-guide.md.
Set the session query tag for tracking. See references/sql-pipeline.md > Query Tag.
Create target database, schema, and warehouse. See references/sql-pipeline.md > Infrastructure Setup.
Check that Data Studio has generated data in SYNTHETIC_DATASETS.UNIFIED:
SELECT 'FACT_VEHICLE_TELEMETRY' AS TBL, COUNT(*) AS ROW_CNT
FROM FLEET_INTELLIGENCE.ROUTE_DEVIATION.VW_VEHICLE_TELEMETRY
UNION ALL SELECT 'FACT_TRIPS', COUNT(*) FROM FLEET_INTELLIGENCE.ROUTE_DEVIATION.VW_TRIP_DEVIATION
UNION ALL SELECT 'DIM_FLEET', COUNT(*) FROM FLEET_INTELLIGENCE.ROUTE_DEVIATION.VW_FLEET
UNION ALL SELECT 'DIM_POIS', COUNT(*) FROM FLEET_INTELLIGENCE.ROUTE_DEVIATION.VW_POIS;
STOP if any view returns 0 rows. Generate data via Data Studio first.
Execute all 3 ETL steps in order. Each is a CREATE OR REPLACE TABLE. Full SQL in references/sql-pipeline.md.
| Step | Table | Description | |------|-------|-------------| | 4.1 | TRIP_DEVIATION_ANALYSIS | Actual vs expected comparison with deviation flags | | 4.2 | DRIVER_DEVIATION_SUMMARY | Per-driver deviation statistics | | 4.3 | DAILY_DEVIATION_TRENDS | Daily aggregated deviation metrics |
Run the verification query after all 3 steps to confirm row counts.
references/dataset-guide.md)The React ORS Control Center pages query these exact tables and columns. If the ETL pipeline changes column names, the React pages must be updated to match.
| Column | Type | Used By | |--------|------|---------| | TRIP_ID | VARCHAR | DeviationDashboard, RouteComparison, RouteInspector | | DRIVER_ID | VARCHAR | DeviationDashboard | | VEHICLE_ID | VARCHAR | RouteInspector (vehicle selector) | | TRIP_DATE | DATE | RouteComparison | | DISTANCE_DEVIATION_PCT | FLOAT | DeviationDashboard, RouteComparison | | DISTANCE_DEVIATION_KM | FLOAT | DeviationDashboard, RouteComparison | | ACTUAL_DISTANCE_KM | FLOAT | RouteComparison, RouteInspector | | ACTUAL_PATH | GEOGRAPHY | RouteComparison (LATERAL FLATTEN ST_ASGEOJSON) | | EXPECTED_PATH | GEOGRAPHY | RouteComparison (LATERAL FLATTEN ST_ASGEOJSON) | | ORIGIN_NAME | VARCHAR | RouteComparison | | DEST_NAME | VARCHAR | RouteComparison |
| Column | Type | Used By | |--------|------|---------| | TRIP_DATE | DATE | DeviationDashboard | | TOTAL_TRIPS | NUMBER | DeviationDashboard | | DEVIATION_RATE_PCT | FLOAT | DeviationDashboard |
| Column | Type | Used By | |--------|------|---------| | DRIVER_ID | VARCHAR | DeviationDashboard | | TOTAL_TRIPS | NUMBER | DeviationDashboard | | AVG_DISTANCE_DEVIATION_PCT | FLOAT | DeviationDashboard | | MAX_DISTANCE_DEVIATION_PCT | FLOAT | DeviationDashboard | | TOTAL_EXCESS_KM | FLOAT | DeviationDashboard |
| Column | Type | Used By | |--------|------|---------| | TRIP_ID | VARCHAR | RouteInspector (filter) | | LATITUDE | FLOAT | RouteInspector (GPS track) | | LONGITUDE | FLOAT | RouteInspector (GPS track) | | SPEED_KMH | FLOAT | RouteInspector (speed chart) | | POSTED_SPEED_KMH | FLOAT | RouteInspector (speed limit line) | | GPS_ACCURACY_M | FLOAT | RouteInspector (accuracy chart, filter) | | IS_DETOUR | BOOLEAN | RouteInspector (detour highlight) | | IS_SPEEDING | BOOLEAN | RouteInspector | | TS | TIMESTAMP | RouteInspector (ordering, teleport detection) | | STATUS | VARCHAR | RouteInspector |
User says: "Deploy route deviation analysis" Actions:
references/seed-data.sql to create projection views and ETL tablesUser says: "Show deviation analysis for trucks instead of e-bikes" Actions:
UPDATE FLEET_INTELLIGENCE.ROUTE_DEVIATION.CONFIG SET VEHICLE_TYPE='hgv';references/sql-pipeline.mdCause: Data Studio has not generated data for the configured VEHICLE_TYPE + REGION Solution: Run Data Studio to generate fleet data, or update CONFIG to match an existing vehicle type and region
Cause: CONFIG table has wrong VEHICLE_TYPE
Solution: UPDATE FLEET_INTELLIGENCE.ROUTE_DEVIATION.CONFIG SET VEHICLE_TYPE='hgv', REGION='SanFrancisco'; then re-run ETL
Cause: Trips without planned routes or incomplete data Solution: Verify FACT_TRIPS has PLANNED_ROUTE_GEOG populated for the configured vehicle type
COUNT(*) AS ROWS syntax errorCause: ROWS is a reserved word in Snowflake
Solution: Use ROW_CNT as the column alias instead
Cause: Data Studio may not have populated this table yet Solution: LEFT JOINs to VW_TRIP_SCHEDULE will return NULLs for ROUTE_VARIATION and TRIP_TYPE columns -- this is acceptable and does not affect deviation calculations
All statements use CREATE OR REPLACE or IF NOT EXISTS, making re-runs safe. No manual cleanup needed -- fix the underlying issue and re-run from the failed step.
Complete Route Deviation Analysis demo with:
To remove all objects created by this skill:
DROP TABLE IF EXISTS FLEET_INTELLIGENCE.ROUTE_DEVIATION.DAILY_DEVIATION_TRENDS;
DROP TABLE IF EXISTS FLEET_INTELLIGENCE.ROUTE_DEVIATION.DRIVER_DEVIATION_SUMMARY;
DROP TABLE IF EXISTS FLEET_INTELLIGENCE.ROUTE_DEVIATION.TRIP_DEVIATION_ANALYSIS;
DROP TABLE IF EXISTS FLEET_INTELLIGENCE.ROUTE_DEVIATION.CONFIG;
DROP VIEW IF EXISTS FLEET_INTELLIGENCE.ROUTE_DEVIATION.VW_VEHICLE_TELEMETRY;
DROP VIEW IF EXISTS FLEET_INTELLIGENCE.ROUTE_DEVIATION.VW_TRIP_DEVIATION;
DROP VIEW IF EXISTS FLEET_INTELLIGENCE.ROUTE_DEVIATION.VW_FLEET;
DROP VIEW IF EXISTS FLEET_INTELLIGENCE.ROUTE_DEVIATION.VW_TRIP_SCHEDULE;
DROP VIEW IF EXISTS FLEET_INTELLIGENCE.ROUTE_DEVIATION.VW_POIS;
DROP SCHEMA IF EXISTS FLEET_INTELLIGENCE.ROUTE_DEVIATION;
Tip: Use the
cleanupskill to auto-discover all tagged objects via COMMENT tracking.
tools
Optimize, audit, create, and improve Cortex Code skills following official best practices from the Anthropic skill-building guide. Use when: creating a new skill, reviewing an existing skill, optimizing skill description or triggers, improving SKILL.md structure, auditing skill quality, fixing undertriggering or overtriggering, restructuring skill for progressive disclosure. Do NOT use for: general code review, non-skill markdown editing, MCP server development. Triggers: optimize skill, audit skill, review skill, create skill, improve skill, fix skill triggers, skill best practices, skill quality check.
testing
Discover and remove all Snowflake objects created by skills in this repo. Uses the COMMENT tracking tag (sf_sit-is-fleet) to find objects, generates DROP statements, and optionally executes them. Use when: cleaning up after a demo, removing all skill-created objects, tearing down an environment, uninstalling a specific skill's objects. Do NOT use for: dropping objects not created by these skills, production environment cleanup without review. Triggers: routing-solution-cleanup, cleanup, teardown, remove, uninstall, drop all, clean up demo, remove skill objects, reset environment.
tools
Check and install build prerequisites for the Routing Solution project. Use when: verifying environment setup before building, checking if Docker/Podman/snow CLI are installed, confirming readiness to build. Do NOT use for: building the routing solution itself (use build-routing-solution), deploying demos, or changing ORS configuration. Triggers: check prerequisites, check build prerequisites, am I ready to build, what do I need installed, verify environment setup, Docker installed, Podman installed, snow CLI installed.
tools
Enable or disable ORS routing profiles (driving-car, driving-hgv, cycling, walking, wheelchair). Subskill of routing-customization — must be invoked from the router, not independently. Use when: changing vehicle types as part of customization workflow. Do NOT use for: standalone execution, changing map region, or deploying demo apps. Triggers: change routing profile, change vehicle type, enable profile, disable profile.