File size: 7,663 Bytes
fd50325 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | from pymongo import MongoClient
from uuid import uuid4
from dotenv import load_dotenv
from datetime import datetime, timezone
import os
load_dotenv()
client = MongoClient(os.getenv("MONGO_URI", "mongodb://localhost:27017/detectifai"))
db = client.get_default_database()
users = db.users
video_files = db.video_files
event_descriptions = db.event_descriptions
subscription_plans = db.subscription_plans
events = db.events
# Add sample user if not exists
sample_user = {
"user_id": str(uuid4()),
"username": "testuser",
"email": "user@detectifai.test",
"password": "userpass",
"role": "user",
"created_at": datetime.now(timezone.utc),
"updated_at": datetime.now(timezone.utc),
"last_login": None
}
if users.count_documents({"email": "user@detectifai.test"}) == 0:
users.insert_one(sample_user)
print("Added sample user: user@detectifai.test / userpass")
else:
print("Sample user already exists")
# Add sample subscription plans
sample_plans = [
{
"plan_id": str(uuid4()),
"plan_name": "Basic",
"description": "Basic surveillance features",
"price": 9.99,
"features": "basic_ai,email_support",
"storage_limit": 10,
"is_active": True
},
{
"plan_id": str(uuid4()),
"plan_name": "Pro",
"description": "Advanced AI features with priority support",
"price": 29.99,
"features": "advanced_ai,priority_support,face_recognition",
"storage_limit": 100,
"is_active": True
},
{
"plan_id": str(uuid4()),
"plan_name": "Enterprise",
"description": "Full enterprise features with 24/7 support",
"price": 99.99,
"features": "premium_ai,24_7_support,face_recognition,custom_integrations",
"storage_limit": 1000,
"is_active": True
}
]
for plan in sample_plans:
if subscription_plans.count_documents({"plan_id": plan["plan_id"]}) == 0:
subscription_plans.insert_one(plan)
print(f"Added subscription plan: {plan['plan_name']}")
else:
print(f"Subscription plan {plan['plan_name']} already exists")
# Get existing video files to add sample events and descriptions
existing_videos = list(video_files.find({}))
if not existing_videos:
print("No video files found. Upload some videos first, then run this script.")
else:
# Add sample events and descriptions to the first video
video = existing_videos[0]
video_id = video["video_id"]
# Create sample events
sample_events = [
{
"event_id": str(uuid4()),
"video_id": video_id,
"event_type": "person_detection",
"confidence_score": 0.95,
"start_timestamp_ms": 0,
"end_timestamp_ms": 5000,
"bounding_boxes": {"x": 100, "y": 150, "width": 200, "height": 300},
"visual_embedding": [],
"is_verified": False,
"is_false_positive": False,
"verified_by": None,
"verified_at": None
},
{
"event_id": str(uuid4()),
"video_id": video_id,
"event_type": "object_detection",
"confidence_score": 0.87,
"start_timestamp_ms": 5200,
"end_timestamp_ms": 12800,
"bounding_boxes": {"x": 300, "y": 200, "width": 150, "height": 100},
"visual_embedding": [],
"is_verified": False,
"is_false_positive": False,
"verified_by": None,
"verified_at": None
}
]
# Insert events
for event in sample_events:
if events.count_documents({"event_id": event["event_id"]}) == 0:
events.insert_one(event)
print(f"Added event: {event['event_type']}")
# Add sample descriptions for the events
sample_descriptions = [
{
"description_id": str(uuid4()),
"event_id": sample_events[0]["event_id"],
"caption": "Person walking into the room carrying a briefcase",
"text_embedding": [],
"confidence": 0.92,
"created_at": datetime.now(timezone.utc),
"updated_at": datetime.now(timezone.utc)
},
{
"description_id": str(uuid4()),
"event_id": sample_events[1]["event_id"],
"caption": "Individual sits down at desk and opens laptop computer",
"text_embedding": [],
"confidence": 0.88,
"created_at": datetime.now(timezone.utc),
"updated_at": datetime.now(timezone.utc)
}
]
# Insert descriptions
for desc in sample_descriptions:
if event_descriptions.count_documents({"description_id": desc["description_id"]}) == 0:
event_descriptions.insert_one(desc)
print(f"Added description: {desc['caption'][:50]}...")
# If there are more videos, add different events to the second one
if len(existing_videos) > 1:
video2 = existing_videos[1]
video2_id = video2["video_id"]
sample_events2 = [
{
"event_id": str(uuid4()),
"video_id": video2_id,
"event_type": "security_patrol",
"confidence_score": 0.93,
"start_timestamp_ms": 2100,
"end_timestamp_ms": 15400,
"bounding_boxes": {"x": 50, "y": 100, "width": 180, "height": 250},
"visual_embedding": [],
"is_verified": False,
"is_false_positive": False,
"verified_by": None,
"verified_at": None
}
]
for event in sample_events2:
if events.count_documents({"event_id": event["event_id"]}) == 0:
events.insert_one(event)
print(f"Added event: {event['event_type']}")
sample_descriptions2 = [
{
"description_id": str(uuid4()),
"event_id": sample_events2[0]["event_id"],
"caption": "Security guard patrolling the hallway with flashlight",
"text_embedding": [],
"confidence": 0.91,
"created_at": datetime.now(timezone.utc),
"updated_at": datetime.now(timezone.utc)
}
]
for desc in sample_descriptions2:
if event_descriptions.count_documents({"description_id": desc["description_id"]}) == 0:
event_descriptions.insert_one(desc)
print(f"Added description: {desc['caption'][:50]}...")
print("\n--- Database Seeding Complete ---")
print("You can now test search functionality with terms like:")
print("- 'briefcase' or 'laptop'")
print("- 'security' or 'guard'")
print("- 'person' or 'detection'")
print("- 'desk' or 'computer'")
print("- 'patrol' or 'hallway'")
# Show summary
total_videos = video_files.count_documents({})
total_events = events.count_documents({})
total_descriptions = event_descriptions.count_documents({})
total_users = users.count_documents({})
total_plans = subscription_plans.count_documents({})
print(f"\nDatabase Summary:")
print(f"Total users: {total_users}")
print(f"Total subscription plans: {total_plans}")
print(f"Total video files: {total_videos}")
print(f"Total events: {total_events}")
print(f"Total event descriptions: {total_descriptions}")
|