Ejemplo n.º 1
0
    
    # start generating result
    res = {
        'options': options.__dict__,
        'scenarios': []
    }
    
    # set the seed to random in order to get consistent results
    for random_seed in random_seeds:
        random.seed(random_seed)
    
        pregen_data = pregenerate(
             slot_qty,
             bidder_qty,
             bid_qty,
             slot_duration_max,
             advert_duration_max,
             slot_price_steps,
             advert_price_max,
             campaign_min_prio_range
        )
    
        for distribution in distributions:
            res_dist = generateScenario(pregen_data)
            res['scenarios'].append(res_dist)
    
    # print scenarios to stdout
    print json.encode(res['scenarios'])
    # and options for reference to stderr
    print >> sys.stderr, json.encode(res['options'])    
Ejemplo n.º 2
0
    return res


if __name__ == "__main__":
    import sys
    import os
    import optparse

    sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), ".."))
    from tvauction.common import json, convertToNamedTuples

    log_level = int(os.environ["LOG_LEVEL"]) if "LOG_LEVEL" in os.environ else logging.WARN
    logging.basicConfig(level=log_level)

    parser = optparse.OptionParser()
    parser.set_usage("%prog [options] < scenarios.json")
    if sys.stdin.isatty():
        print parser.format_help()
        sys.exit()

    for option in parser.option_list:
        if option.default != ("NO", "DEFAULT"):
            option.help += (" " if option.help else "") + "[default: %default]"
    options = parser.parse_args(sys.argv)[0]
    scenarios = json.decode(sys.stdin.read())
    # convert
    for scenario in scenarios:
        convertToNamedTuples(scenario)
        res = analyze(scenario)
        print json.encode(res)