Skip to content

Instantly share code, notes, and snippets.

@Netzach-Nyss
Created January 20, 2025 12:59
Show Gist options
  • Select an option

  • Save Netzach-Nyss/6286fa8b34445e04100e3418e27bf537 to your computer and use it in GitHub Desktop.

Select an option

Save Netzach-Nyss/6286fa8b34445e04100e3418e27bf537 to your computer and use it in GitHub Desktop.
Small mock sensor data generator
import time
import random
import uuid
from faker import Faker
from pydantic import BaseModel
from datetime import datetime
from ravendb import DocumentStore
doc_store = DocumentStore(urls=["http://127.0.0.1:8080"], database="TrafficData")
doc_store.initialize()
class TrafficEntry(BaseModel):
Id: str = None
entry_id: str
location_id: int
vehicle_plates: str
time: str
color: str
faker = Faker()
colors = ["Red", "Blue", "Green", "Black", "White", "Gray", "Silver", "Yellow", "Orange", "Brown"]
while True:
entry = TrafficEntry(
entry_id=str(uuid.uuid4()), # Generate a unique UUID
location_id=random.randint(1, 3), # Limit location ID from 1 to 3
vehicle_plates=faker.license_plate(),
time=datetime.now().strftime("%Y-%m-%d %H:%M:%SZ"),
color=random.choice(colors)
)
with doc_store.open_session() as session:
session.store(entry)
session.save_changes()
print(entry.json())
time.sleep(random.randint(1, 10))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment