def main(): # large data DB example car_count = 250_000 owner_count = 100_000 # simple DB example # car_count = 200 # owner_count = 100 mongo_setup.init() clear_db() t0 = datetime.now() fake = create_faker_and_seed() owners = create_owners(fake, count=owner_count) print("Created {:,.0f} owners".format(len(owners))) cars = create_cars(count=car_count) print("Created {:,.0f} cars".format(len(cars))) if cars and owners: add_cars_to_owners(owners, cars) create_service_records(cars, fake) dt = datetime.now() - t0 print("Done in {} sec".format(dt.total_seconds()))
def main(): mongo_setup.init() print("Computing stats, this WILL take awhile...", flush=True) cars = list(Car.objects()) print("There are {:,} cars.".format(len(cars))) owners = list(Owner.objects()) print("There are {:,} owners.".format(len(owners))) owned_cars = sum((len(o.car_ids) for o in owners)) print("Each owner owns an average of {:.2f} cars.".format(owned_cars / len(owners))) service_histories = sum((len(c.service_history) for c in cars)) print("There are {:,} service histories.".format(service_histories)) print("Each car has an average of {:.2f} service records.".format(service_histories / len(cars)))
def main(): mongo_setup.init() print("Computing stats, this WILL take awhile...", flush=True) cars = list(Car.objects()) print("There are {:,} cars.".format(len(cars))) owners = list(Owner.objects()) print("There are {:,} owners.".format(len(owners))) owned_cars = sum((len(o.car_ids) for o in owners)) print("Each owner owns an average of {:.2f} cars.".format(owned_cars / len(owners))) service_histories = sum((len(c.service_history) for c in cars)) print("There are {:,} service histories.".format(service_histories)) print("Each car has an average of {:.2f} service records.".format( service_histories / len(cars)))
from nosql.car import Car from nosql.owner import Owner from datetime import datetime import nosql.mongo_setup as mongo_setup def timed(msg, func): t0 = datetime.now() func() dt = datetime.now() - t0 print("{} Time: {:,.3f} ms".format(msg, dt.total_seconds() * 1000.0), flush=True) mongo_setup.init() print("Time to ask some questions") timed( 'How many owners?', lambda: Owner.objects().filter().count() ) timed( 'How many cars?', lambda: Owner.objects().filter().count() ) timed( 'Find the 10,000th owner by name?', lambda: Owner.objects().order_by('name')[10000:10001][0]