示例#1
0
    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 make_expression(exp, depth):
    exp.op = choice(OPERATIONS)

    if rand_int(8) < depth:
        left = rand_int(128) + 1
        exp.left.value = left
    else:
        left = make_expression(exp.left.init('expression'), depth + 1)

    if rand_int(8) < depth:
        right = rand_int(128) + 1
        exp.right.value = right
    else:
        right = make_expression(exp.right.init('expression'), depth + 1)

    op = exp.op
    if op == 'add':
        return clamp(left + right)
    elif op == 'subtract':
        return clamp(left - right)
    elif op == 'multiply':
        return clamp(left * right)
    elif op == 'divide':
        return div(left, right)
    elif op == 'modulus':
        return mod(left, right)
    raise RuntimeError("op wasn't a valid value: " + str(op))
示例#3
0
def make_expression(exp, depth):
    exp.op = rand_int(len(OPERATIONS))

    if rand_int(8) < depth:
        left = rand_int(128) + 1
        exp.left_value = left
    else:
        left = make_expression(exp.left_expression, depth+1)

    if rand_int(8) < depth:
        right = rand_int(128) + 1
        exp.right_value = right
    else:
        right = make_expression(exp.right_expression, depth+1)

    op = exp.op
    if op == 0:
        return clamp(left + right)
    elif op == 1:
        return clamp(left - right)
    elif op == 2:
        return clamp(left * right)
    elif op == 3:
        return div(left, right)
    elif op == 4:
        return mod(left, right)
    raise RuntimeError("op wasn't a valid value: " + str(op))
示例#4
0
def make_expression(exp, depth):
    exp.op = rand_int(len(OPERATIONS))

    if rand_int(8) < depth:
        left = rand_int(128) + 1
        exp.left_value = left
    else:
        left = make_expression(exp.left_expression, depth + 1)

    if rand_int(8) < depth:
        right = rand_int(128) + 1
        exp.right_value = right
    else:
        right = make_expression(exp.right_expression, depth + 1)

    op = exp.op
    if op == 0:
        return clamp(left + right)
    elif op == 1:
        return clamp(left - right)
    elif op == 2:
        return clamp(left * right)
    elif op == 3:
        return div(left, right)
    elif op == 4:
        return mod(left, right)
    raise RuntimeError("op wasn't a valid value: " + str(op))
示例#5
0
    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
示例#6
0
 def setup(self, request):
     result = 0
     for _ in range(rand_int(200)):
         car = request.car.add()
         random_car(car)
         result += calc_value(car)
     return result
示例#7
0
 def setup(self, request):
     result = 0
     for _ in range(rand_int(200)):
         car = request.car.add()
         random_car(car)
         result += calc_value(car)
     return result
示例#8
0
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()
示例#9
0
 def setup(self, request):
     result = 0
     for car in request.init('cars', rand_int(200)):
       random_car(car)
       result += calc_value(car)
     return result
示例#10
0
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()
示例#11
0
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()
示例#12
0
 def setup(self, request):
     result = 0
     for car in request.init('cars', rand_int(200)):
       random_car(car)
       result += calc_value(car)
     return result
示例#13
0
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()