def setup(self, request): goodCount = 0 count = rand_int(1000) results = request.init('results', count) for i, result in enumerate(results): result.score = 1000 - i url_size = rand_int(100) result.url = "http://example.com/" + ''.join( [choice(ascii_letters) for _ in range(url_size)]) isCat = rand_bool() isDog = rand_bool() if isCat and not isDog: goodCount += 1 snippet = [choice(WORDS) for i in range(rand_int(20))] if isCat: snippet.append(" cat ") if isDog: snippet.append(" dog ") snippet += [choice(WORDS) for i in range(rand_int(20))] result.snippet = ''.join(snippet) return goodCount
def random_car(car): car.make = choice(MAKES) car.model = choice(MODELS) car.color = rand_int(len(COLORS)) car.seats = 2 + rand_int(6) car.doors = 2 + rand_int(3) for _ in range(4): wheel = car.wheel.add() wheel.diameter = 25 + rand_int(15) wheel.air_pressure = 30 + rand_double(20) wheel.snow_tires = rand_int(16) == 0 car.length = 170 + rand_int(150) car.width = 48 + rand_int(36) car.height = 54 + rand_int(48) car.weight = car.length * car.width * car.height / 200 engine = car.engine engine.horsepower = 100 * rand_int(400) engine.cylinders = 4 + 2 * rand_int(3) engine.cc = 800 + rand_int(10000) engine.uses_gas = True engine.uses_electric = rand_bool() car.fuel_capacity = 10.0 + rand_double(30.0) car.fuel_level = rand_double(car.fuel_capacity) car.has_power_windows = rand_bool() car.has_power_steering = rand_bool() car.has_cruise_control = rand_bool() car.cup_holders = rand_int(12) car.has_nav_system = rand_bool()
def random_car(car): car.make = choice(MAKES) car.model = choice(MODELS) car.color = choice(COLORS) car.seats = 2 + rand_int(6) car.doors = 2 + rand_int(3) for wheel in car.init('wheels', 4): wheel.diameter = 25 + rand_int(15) wheel.airPressure = 30 + rand_double(20) wheel.snowTires = rand_int(16) == 0 car.length = 170 + rand_int(150) car.width = 48 + rand_int(36) car.height = 54 + rand_int(48) car.weight = car.length * car.width * car.height // 200 engine = car.init('engine') engine.horsepower = 100 * rand_int(400) engine.cylinders = 4 + 2 * rand_int(3) engine.cc = 800 + rand_int(10000) engine.usesGas = True engine.usesElectric = rand_bool() car.fuelCapacity = 10.0 + rand_double(30.0) car.fuelLevel = rand_double(car.fuelCapacity) car.hasPowerWindows = rand_bool() car.hasPowerSteering = rand_bool() car.hasCruiseControl = rand_bool() car.cupHolders = rand_int(12) car.hasNavSystem = rand_bool()
def random_car(car): car.make = choice(MAKES) car.model = choice(MODELS) car.color = rand_int(len(COLORS)) car.seats = 2 + rand_int(6) car.doors = 2 + rand_int(3) for _ in range(4): wheel = car.wheel.add() wheel.diameter = 25 + rand_int(15) wheel.air_pressure = 30 + rand_double(20) wheel.snow_tires = rand_int(16) == 0 car.length = 170 + rand_int(150) car.width = 48 + rand_int(36) car.height = 54 + rand_int(48) car.weight = car.length * car.width * car.height // 200 engine = car.engine engine.horsepower = 100 * rand_int(400) engine.cylinders = 4 + 2 * rand_int(3) engine.cc = 800 + rand_int(10000) engine.uses_gas = True engine.uses_electric = rand_bool() car.fuel_capacity = 10.0 + rand_double(30.0) car.fuel_level = rand_double(car.fuel_capacity) car.has_power_windows = rand_bool() car.has_power_steering = rand_bool() car.has_cruise_control = rand_bool() car.cup_holders = rand_int(12) car.has_nav_system = rand_bool()
def setup(self, request): goodCount = 0 count = rand_int(1000) for i in range(count): result = request.result.add() result.score = 1000 - i url_size = rand_int(100) result.url = "http://example.com/" + ''.join([choice(letters) for _ in range(url_size)]) isCat = rand_bool() isDog = rand_bool() if isCat and not isDog: goodCount += 1 snippet = [choice(WORDS) for i in range(rand_int(20))] if isCat: snippet.append(" cat ") if isDog: snippet.append(" dog ") snippet += [choice(WORDS) for i in range(rand_int(20))] result.snippet = ''.join(snippet) return goodCount
def random_car(car): car.make = choice(MAKES) car.model = choice(MODELS) car.color = choice(COLORS) car.seats = 2 + rand_int(6) car.doors = 2 + rand_int(3) for wheel in car.init('wheels', 4): wheel.diameter = 25 + rand_int(15) wheel.airPressure = 30 + rand_double(20) wheel.snowTires = rand_int(16) == 0 car.length = 170 + rand_int(150) car.width = 48 + rand_int(36) car.height = 54 + rand_int(48) car.weight = car.length * car.width * car.height / 200 engine = car.init('engine') engine.horsepower = 100 * rand_int(400) engine.cylinders = 4 + 2 * rand_int(3) engine.cc = 800 + rand_int(10000) engine.usesGas = True engine.usesElectric = rand_bool() car.fuelCapacity = 10.0 + rand_double(30.0) car.fuelLevel = rand_double(car.fuelCapacity) car.hasPowerWindows = rand_bool() car.hasPowerSteering = rand_bool() car.hasCruiseControl = rand_bool() car.cupHolders = rand_int(12) car.hasNavSystem = rand_bool()