| ← Back to Main Documentation | Core Systems Index |
Misplacement Detection System
This document defines the comprehensive misplacement detection capabilities enabled by the dual spatial predicate system (CURRENT_* vs NORMAL_* relationships).
Overview
The misplacement detection system compares where objects currently are (CURRENT_* relationships) with where they should be (NORMAL_* relationships) to identify and categorize different types of spatial inconsistencies.
Misplacement Categories
1. ✅ Correct Placement
Objects are exactly where they should be with the correct spatial relationship.
// Perfect match
(:Keys)-[:CURRENT_IN]->(:KeyDrawer)
(:Keys)-[:NORMAL_IN]->(:KeyDrawer)
// Status: Object is correctly placed
2. ⚠️ Wrong Position (Same Container/Support)
Objects are with the correct parent but in wrong relative position.
// Monitor on wrong side of computer
(:Monitor)-[:CURRENT_LEFT_OF]->(:Computer)
(:Monitor)-[:NORMAL_RIGHT_OF]->(:Computer)
// Status: Needs repositioning within same workspace
3. ❌ Wrong Container (Same Relationship Type)
Objects are using correct relationship type but with wrong target.
// Box on wrong pallet
(:Box_A)-[:CURRENT_ON]->(:Pallet_1)
(:Box_A)-[:NORMAL_ON]->(:Pallet_3)
// Status: Needs transfer to correct location
4. ❌ Wrong Relationship Type (Same Target)
Objects are with correct target but using wrong spatial relationship.
// Keys are contained but should be hanging
(:Keys)-[:CURRENT_IN]->(:KeyStation)
(:Keys)-[:NORMAL_ON]->(:KeyStation)
// Status: Needs relationship type change (remove from container, hang on hook)
5. ❌ Completely Misplaced
Objects have both wrong relationship type and wrong target.
// Emergency supplies in completely wrong location
(:EmergencyKit)-[:CURRENT_IN]->(:OfficeDesk)
(:EmergencyKit)-[:NORMAL_ON]->(:SafetyStation)
// Status: Needs complete relocation and relationship change
6. 🚫 Missing Normal Location
Objects have current location but no defined normal/expected location.
// Object exists but no expected location defined
(:NewItem)-[:CURRENT_ON]->(:ReceivingDock)
// No NORMAL_* relationship exists
// Status: Needs normal location assignment
7. 👻 Orphaned Normal Location
Objects have expected location but no current location (potentially missing/lost).
// Expected location but object not found
(:MissingTool)-[:NORMAL_IN]->(:ToolCabinet)
// No CURRENT_* relationship exists
// Status: Object may be lost, needs investigation
Detection Queries
Basic Misplacement Detection
MATCH (obj:ObjectInstance)
OPTIONAL MATCH (obj)-[current:CURRENT_IN|CURRENT_ON|CURRENT_LEFT_OF|CURRENT_RIGHT_OF|CURRENT_ABOVE|CURRENT_UNDER|CURRENT_NEXT_TO|CURRENT_ATTACHED_TO]->(currentTarget:ObjectInstance)
OPTIONAL MATCH (obj)-[normal:NORMAL_IN|NORMAL_ON|NORMAL_LEFT_OF|NORMAL_RIGHT_OF|NORMAL_ABOVE|NORMAL_UNDER|NORMAL_NEXT_TO|NORMAL_ATTACHED_TO]->(normalTarget:ObjectInstance)
RETURN {
objectId: obj.id,
objectName: obj.name,
currentRelationship: type(current),
currentTarget: {id: currentTarget.id, name: currentTarget.name},
normalRelationship: type(normal),
normalTarget: {id: normalTarget.id, name: normalTarget.name},
// Status flags
hasCurrentLocation: current IS NOT NULL,
hasNormalLocation: normal IS NOT NULL,
isCorrectLocation: (type(current) = type(normal) AND currentTarget.id = normalTarget.id),
isCorrectRelationship: (type(current) = type(normal)),
isCorrectTarget: (currentTarget.id = normalTarget.id),
// Classification
misplacementType: CASE
WHEN current IS NULL AND normal IS NOT NULL THEN 'orphaned_normal'
WHEN current IS NOT NULL AND normal IS NULL THEN 'missing_normal'
WHEN type(current) = type(normal) AND currentTarget.id = normalTarget.id THEN 'correct'
WHEN type(current) = type(normal) AND currentTarget.id <> normalTarget.id THEN 'wrong_target'
WHEN type(current) <> type(normal) AND currentTarget.id = normalTarget.id THEN 'wrong_relationship'
WHEN type(current) <> type(normal) AND currentTarget.id <> normalTarget.id THEN 'completely_misplaced'
ELSE 'unknown'
END
} as misplacementStatus
Misplacement Summary Report
MATCH (obj:ObjectInstance)
OPTIONAL MATCH (obj)-[current:CURRENT_IN|CURRENT_ON|CURRENT_LEFT_OF|CURRENT_RIGHT_OF|CURRENT_ABOVE|CURRENT_UNDER|CURRENT_NEXT_TO|CURRENT_ATTACHED_TO]->(currentTarget:ObjectInstance)
OPTIONAL MATCH (obj)-[normal:NORMAL_IN|NORMAL_ON|NORMAL_LEFT_OF|NORMAL_RIGHT_OF|NORMAL_ABOVE|NORMAL_UNDER|NORMAL_NEXT_TO|NORMAL_ATTACHED_TO]->(normalTarget:ObjectInstance)
WITH CASE
WHEN current IS NULL AND normal IS NOT NULL THEN 'orphaned_normal'
WHEN current IS NOT NULL AND normal IS NULL THEN 'missing_normal'
WHEN type(current) = type(normal) AND currentTarget.id = normalTarget.id THEN 'correct'
WHEN type(current) = type(normal) AND currentTarget.id <> normalTarget.id THEN 'wrong_target'
WHEN type(current) <> type(normal) AND currentTarget.id = normalTarget.id THEN 'wrong_relationship'
WHEN type(current) <> type(normal) AND currentTarget.id <> normalTarget.id THEN 'completely_misplaced'
ELSE 'unknown'
END as category
RETURN category, COUNT(*) as count
ORDER BY count DESC
GraphQL API Integration
MisplacementStatus Type
type MisplacementStatus {
isCorrect: Boolean!
misplacementType: MisplacementType!
currentLocation: SpatialReference
normalLocation: SpatialReference
correctionSuggestion: CorrectionSuggestion
}
enum MisplacementType {
CORRECT
WRONG_POSITION
WRONG_TARGET
WRONG_RELATIONSHIP
COMPLETELY_MISPLACED
MISSING_NORMAL
ORPHANED_NORMAL
}
type CorrectionSuggestion {
action: CorrectionAction!
description: String!
targetLocation: SpatialReference
relationshipType: String
}
enum CorrectionAction {
REPOSITION_WITHIN_CONTAINER
TRANSFER_TO_CONTAINER
CHANGE_RELATIONSHIP_TYPE
COMPLETE_RELOCATION
ASSIGN_NORMAL_LOCATION
INVESTIGATE_MISSING
}
Object Fields Enhancement
type ObjectInstance {
# ... existing fields
# Enhanced spatial fields
misplacementStatus: MisplacementStatus!
currentSpatialRelationship: SpatialRelationship
normalSpatialRelationship: SpatialRelationship
# Calculated fields
isCorrectlyPlaced: Boolean!
requiresAttention: Boolean!
lastMovedAt: DateTime
timeSinceMisplaced: Duration
}
Correction Workflows
1. Automated Correction Suggestions
def suggest_correction(object_id):
status = get_misplacement_status(object_id)
if status.misplacement_type == 'WRONG_TARGET':
return CorrectionSuggestion(
action='TRANSFER_TO_CONTAINER',
description=f'Move to {status.normal_location.name}',
target_location=status.normal_location,
relationship_type=status.normal_relationship_type
)
elif status.misplacement_type == 'WRONG_RELATIONSHIP':
return CorrectionSuggestion(
action='CHANGE_RELATIONSHIP_TYPE',
description=f'Change from {status.current_relationship} to {status.normal_relationship}',
target_location=status.current_location,
relationship_type=status.normal_relationship_type
)
# ... other cases
2. Bulk Correction Operations
// Find all boxes on wrong pallets
MATCH (box:ObjectInstance)-[:CURRENT_ON]->(currentPallet:ObjectInstance)
MATCH (box)-[:NORMAL_ON]->(normalPallet:ObjectInstance)
WHERE currentPallet.id <> normalPallet.id
RETURN box.id, box.name, currentPallet.name as currentLocation, normalPallet.name as correctLocation
ORDER BY normalPallet.name
// Move all misplaced boxes to correct pallets
MATCH (box:ObjectInstance)-[current:CURRENT_ON]->(currentPallet:ObjectInstance)
MATCH (box)-[:NORMAL_ON]->(normalPallet:ObjectInstance)
WHERE currentPallet.id <> normalPallet.id
DELETE current
CREATE (box)-[:CURRENT_ON]->(normalPallet)
RETURN COUNT(*) as correctedBoxes
User Interface Components
1. Misplacement Dashboard
- Summary cards: Show counts by misplacement type
- Priority list: Objects requiring immediate attention
- Trends: Misplacement patterns over time
- Quick actions: Bulk correction buttons
2. Object Detail View
- Status indicator: Visual cues for misplacement type
- Current vs Normal: Side-by-side location comparison
- Correction button: One-click fix for simple cases
- History: Timeline of location changes
3. Spatial Navigation Enhancements
- Misplacement overlay: Highlight misplaced objects in spatial view
- Expected location ghost: Show where objects should be
- Correction drag-and-drop: Visual repositioning interface
Automation and Alerts
1. Real-time Monitoring
# Monitor for new misplacements
def on_object_moved(object_id, new_location):
status = get_misplacement_status(object_id)
if not status.is_correct:
create_misplacement_alert(object_id, status)
if status.misplacement_type == 'COMPLETELY_MISPLACED':
create_urgent_alert(object_id, status)
2. Scheduled Audits
# Daily misplacement audit
def daily_audit():
misplacements = find_all_misplacements()
report = generate_misplacement_report(misplacements)
notify_managers(report)
# Auto-correct simple cases
simple_fixes = filter_simple_corrections(misplacements)
for fix in simple_fixes:
if auto_correction_enabled():
apply_correction(fix)
3. Misplacement Analytics
- Hotspot analysis: Areas with frequent misplacements
- Pattern detection: Common misplacement types by object class
- Efficiency metrics: Time to correction, success rates
- Trend analysis: Improvement or degradation over time
Migration Strategy
Phase 1: Dual Predicate Implementation
- Deploy dual predicate schema to Supabase
- Implement current location tracking with
CURRENT_*predicates - Begin collecting normal location data with
NORMAL_*predicates
Phase 2: Misplacement Detection
- Deploy misplacement detection queries
- Implement GraphQL API enhancements
- Create basic misplacement dashboard
Phase 3: Correction Workflows
- Implement correction suggestion engine
- Deploy bulk correction operations
- Add automated correction capabilities
Phase 4: Advanced Analytics
- Deploy real-time monitoring
- Implement predictive misplacement detection
- Add comprehensive analytics dashboard
Related Documentation
- Spatial Relationships System - Core dual predicate system
- Spatial Parent-Child Architecture - Movement and hierarchy rules
- Relationship Decision Guide - When to use different relationship types
Performance Considerations
Query Optimization
- Index strategies: Optimize for misplacement detection queries
- Caching: Cache misplacement status for frequently accessed objects
- Batch processing: Handle bulk corrections efficiently
Scalability
- Pagination: Handle large misplacement result sets
- Background processing: Run intensive audits asynchronously
- Real-time updates: Efficient change propagation for status updates