Skip to content

Instantly share code, notes, and snippets.

@dmcgrath
Last active May 25, 2019 12:31
Show Gist options
  • Save dmcgrath/0c404b5f2f17f1383e4f14631e579783 to your computer and use it in GitHub Desktop.
Save dmcgrath/0c404b5f2f17f1383e4f14631e579783 to your computer and use it in GitHub Desktop.
Collection Group Queries - Generate Sample Data
# Create example call center data
# Each agent has their own subcollection of calls
# You can run this generator multiple times in parallel
from google.cloud import firestore
import random
# Default values create 5000 documents.
MAX_AGENTS = 100
MAX_CALLS = 50
MAX_RATING = 5
CALL_TYPES = [u'Password', u'Billing', u'Sales', u'Complaint', u'Compliment', u'Other']
STATUSES = [u'Closed', u'Escalated', u'In Review', u'Terminated Early']
db = firestore.Client(project="<your project id here>")
agents_collection = db.collection(u'agents')
for agent in range(1,MAX_AGENTS):
agent_id = random.randrange(100000, 999999)
call_collection = agents_collection.document(str(agent_id)).collection(u'calls')
for call in range(1,MAX_CALLS):
# Create random data for call document
call_id = random.randrange(100000, 999999)
type = random.choice(CALL_TYPES)
status = random.choice(STATUSES)
rating = random.randrange(1,MAX_RATING)
sample = random.randrange(1,100)
call_log = u'gs://invalid_call_log_bucket/' +str(agent_id)+ u'/' +str(call_id)+ u'/.wav'
call_collection.document(str(call_id)).set({
u'type':type,
u'status':status,
u'rating':rating,
u'sample':sample,
u'log':call_log
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment