Legacy Preview Update

This commit is contained in:
2026-04-20 16:16:54 -04:00
parent 8312b5bea6
commit 8be7e1e5f9
10 changed files with 358 additions and 81 deletions
+32 -35
View File
@@ -1,24 +1,6 @@
import random
from datetime import datetime, timedelta
from pymongo import MongoClient
MONGO_URI = "mongodb+srv://SarayuJ:[EMAIL_ADDRESS]/testing"
client = MongoClient(MONGO_URI)
db = client.study_buddy_db
collection = db.study_rooms
UMD_LOCATIONS = [
{ "id": 'esj', "name": 'Edward St. John (ESJ)', "lng": -76.94209511596014, "lat": 38.987133359608755 },
{ "id": 'mckeldin', "name": 'McKeldin Library', "lng": -76.94494907523277, "lat": 38.986021017749366 },
{ "id": 'hornbake', "name": 'Hornbake Library', "lng": -76.94161787005467, "lat": 38.988233373664826 },
{ "id": 'stem', "name": 'STEM Library', "lng": -76.93942003731279, "lat": 38.988991437126195 },
{ "id": 'clarice', "name": 'Clarice Library', "lng": -76.9500912552473, "lat": 38.990547823732285 },
{ "id": 'yahentamitsi', "name": 'Yahentamitsi', "lng": -76.9448027183373, "lat": 38.99108961575231 },
{ "id": 'iribe', "name": 'Iribe', "lng": -76.93643838603555, "lat": 38.98933701397555 },
{ "id": 'reckord', "name": 'Reckord Armory', "lng": -76.93897470250619, "lat": 38.98609556181066 },
{ "id": 'stamp', "name": 'Stamp Student Union', "lng": -76.94473083972326, "lat": 38.988130238874874 }
]
import os
def get_db_for_time_and_location(hour, loc_id):
"""
@@ -28,7 +10,6 @@ def get_db_for_time_and_location(hour, loc_id):
base_db = 40.0
if loc_id in ['mckeldin', 'esj']:
if 10 <= hour <= 16:
base_db = 75.0
elif 17 <= hour <= 22:
@@ -37,7 +18,6 @@ def get_db_for_time_and_location(hour, loc_id):
base_db = 45.0
elif loc_id in ['stem', 'iribe']:
if 14 <= hour <= 20:
base_db = 70.0
elif 9 <= hour <= 13:
@@ -46,7 +26,6 @@ def get_db_for_time_and_location(hour, loc_id):
base_db = 42.0
elif loc_id == 'stamp':
if 12 <= hour <= 14 or 17 <= hour <= 19:
base_db = 85.0
elif 10 <= hour <= 21:
@@ -55,33 +34,24 @@ def get_db_for_time_and_location(hour, loc_id):
base_db = 50.0
else:
if 9 <= hour <= 18:
base_db = 60.0
else:
base_db = 45.0
noise = random.uniform(-5.0, 5.0)
return max(30.0, min(100.0, base_db + noise))
def generate_fake_data():
print("Clearing existing study room data...")
collection.delete_many({})
def get_fake_data(locations):
now = datetime.utcnow()
start_time = now - timedelta(hours=24)
docs_to_insert = []
print("Generating 24 hours of fake data with patterns...")
docs = []
current_time = start_time
while current_time <= now:
hour = current_time.hour
for loc in UMD_LOCATIONS:
for loc in locations:
db_level = get_db_for_time_and_location(hour, loc["id"])
# Estimate people based on noise level.
@@ -99,9 +69,36 @@ def generate_fake_data():
"people": people_count,
"date": current_time
}
docs_to_insert.append(doc)
docs.append(doc)
current_time += timedelta(minutes=15)
return docs
def generate_fake_data():
from pymongo import MongoClient
MONGO_URI = os.getenv("MONGODB_URI", "mongodb+srv://SarayuJ:[EMAIL_ADDRESS]/testing")
client = MongoClient(MONGO_URI)
db = client.study_buddy_db
collection = db.study_rooms
UMD_LOCATIONS = [
{ "id": 'esj', "name": 'Edward St. John (ESJ)', "lng": -76.94209511596014, "lat": 38.987133359608755 },
{ "id": 'mckeldin', "name": 'McKeldin Library', "lng": -76.94494907523277, "lat": 38.986021017749366 },
{ "id": 'hornbake', "name": 'Hornbake Library', "lng": -76.94161787005467, "lat": 38.988233373664826 },
{ "id": 'stem', "name": 'STEM Library', "lng": -76.93942003731279, "lat": 38.988991437126195 },
{ "id": 'clarice', "name": 'Clarice Library', "lng": -76.9500912552473, "lat": 38.990547823732285 },
{ "id": 'yahentamitsi', "name": 'Yahentamitsi', "lng": -76.9448027183373, "lat": 38.99108961575231 },
{ "id": 'iribe', "name": 'Iribe', "lng": -76.93643838603555, "lat": 38.98933701397555 },
{ "id": 'reckord', "name": 'Reckord Armory', "lng": -76.93897470250619, "lat": 38.98609556181066 },
{ "id": 'stamp', "name": 'Stamp Student Union', "lng": -76.94473083972326, "lat": 38.988130238874874 }
]
print("Clearing existing study room data...")
collection.delete_many({})
print("Generating 24 hours of fake data with patterns...")
docs_to_insert = get_fake_data(UMD_LOCATIONS)
print(f"Inserting {len(docs_to_insert)} records into MongoDB...")
collection.insert_many(docs_to_insert)