Beispiel #1
0
def init_app(app):
    """Initialize the given Flask application.

    :type app: flask.Flask
    :param app: The application to configure.
    :rtype: flask.Flask
    :return: The configured application.
    """
    configure_app(app)
    init_logging(app)
    database.init_session(connection_string=app.config["DB_CONNECTION"])

    app.register_blueprint(register.bp, url_prefix='/register')
    app.register_blueprint(admin.bp, url_prefix='/admin')
    app.register_blueprint(public.bp, url_prefix='/public')

    app.mail = Mail(app)
    #make_dummy_data(30)

    @app.teardown_request
    def session_cleanup(_):
        database.session.remove()

    @app.route("/")
    def start():
        return redirect(url_for("public.landing_page"))

    return app
def cmd_distance_data(args):
    print "init db..."
    db.init_session(connection_string=config.DB_CONNECTION)

    print "fetch teams..."
    teams = db.session.query(Team).filter_by(deleted=False,
                                             confirmed=True,
                                             backup=False).order_by(Team.id)

    if args.group is not None:
        teams = teams.filter_by(groups=args.group)

    if args.slice is not None:
        teams = teams.limit(args.slice)

    fname = ""
    if args.name is not None:
        fname = "_%s" % args.name

    if args.separate is not None:
        write_planning_data(teams.filter(Team.id.in_(args.separate)).all(), "%s_1" % fname)
        write_planning_data(teams.filter(not_(Team.id.in_(args.separate))).all(), "%s_2" % fname)
    else:
        write_planning_data(teams.all(), fname)

    print "finish!"
def init_app(app):
    """Initialize the given Flask application.

    :type app: flask.Flask
    :param app: The application to configure.
    :rtype: flask.Flask
    :return: The configured application.
    """
    configure_app(app)
    init_logging(app)
    database.init_session(connection_string=app.config["DB_CONNECTION"])
    app.register_blueprint(register.bp, url_prefix='/register')
    app.register_blueprint(admin.bp, url_prefix='/admin')
    app.register_blueprint(public.bp, url_prefix='/public')

    app.mail = Mail(app)
    #make_dummy_data(30)

    app.config["REGISTER_END"] = datetime.strptime(app.config["REGISTER_END"], "%Y-%m-%d %H:%M")

    @app.teardown_request
    def session_cleanup(_):
        database.session.remove()

    @app.route("/")
    def start():
        return redirect(url_for("register.form"))

    return app
def cmd_distance_data(args):
    print "init db..."
    db.init_session(connection_string=config.DB_CONNECTION)

    print "fetch teams..."
    teams = db.session.query(Team).filter_by(deleted=False,
                                             confirmed=True,
                                             backup=False).order_by(Team.id)

    if args.group is not None:
        teams = teams.filter_by(groups=args.group)

    if args.slice is not None:
        teams = teams.limit(args.slice)

    fname = ""
    if args.name is not None:
        fname = "_%s" % args.name

    if args.separate is not None:
        write_planning_data(teams.filter(Team.id.in_(args.separate)).all(), "%s_1" % fname)
        write_planning_data(teams.filter(not_(Team.id.in_(args.separate))).all(), "%s_2" % fname)
    else:
        write_planning_data(teams.all(), fname)

    print "finish!"
arguments = argparse.ArgumentParser()
arguments.add_argument("-c", "--config", help="set the configfile",
                       default="config.yaml")

arguments.add_argument("max_teams", help="Max. number of teams to export")

args = arguments.parse_args()

print "load config..."
cfg.load_config(args.config)

MAX_TEAMS = args.max_teams

print "init db..."
db.init_session(connection_string=config.DB_CONNECTION)

print "fetch teams..."

teams = db.session.query(Team).filter_by(deleted=False).filter_by(confirmed=True, backup=False).order_by(Team.id).limit(
    MAX_TEAMS).all()
data = []
round_teams = defaultdict(list)

max_working = len(teams) - (len(teams) % 3)
divider = max_working / 3.0


def distance_sort(a, b):
    if a.location.center_distance > b.location.center_distance:
        return -1
Beispiel #6
0
    args.add_argument("-g", "--group", type=int, metavar="g", required=False,
                      help="Import data for a given group")

    convert_parser = subcommands.add_parser("convert")
    convert_parser.add_argument("-o", "--result", help="The output file")
    convert_parser.set_defaults(func=cmd_convert_plan)

    print_parser = subcommands.add_parser("print")
    print_parser.add_argument("--osm", action="store_true", help="build osm route links")
    print_parser.add_argument("--gmaps", action="store_true", help="build google maps route links")
    print_parser.set_defaults(func=cmd_print_plan)

    graph_parser = subcommands.add_parser("graph", help="Build a clustering graph")
    graph_parser.add_argument("-o", "--result", help="The filename for the output png")
    graph_parser.add_argument("-a", "--annonymize", help="Use numbers instead of names", action="store_true")
    graph_parser.add_argument("-d", "--distance", help="Use distances for graph lenghths", action="store_true")
    graph_parser.add_argument("-l", "--labels", help="Use distances for graph lenghths", action="store_true")
    graph_parser.set_defaults(func=cmd_graph_plan)

    import_parser = subcommands.add_parser("import")
    import_parser.set_defaults(func=cmd_import_plan)

    return args.parse_args()


if __name__ == "__main__":
    args = parse_args()
    cfg.load_config(args.config)
    db.init_session(connection_string=config.B_CONNECTION)
    args.func(args)
Beispiel #7
0
 def setUp(self):
     db.init_session(drop=True)
     self.maxDiff = None