Example #1
0
def import_config(args):
    """
    Imports the config data of a csv file into the config table.

    :param args: A list with arguments from the argument parser
    :type args: namespace
    """
    Config.query().truncate()
    print "Importing config from", args.file

    try:
        csvfile, reader, hasHeader = utils.get_csv(args.file)
        line = 0

        for row in reader:
            if line != 0 or (line == 0 and not hasHeader):
                entry = Config(key=row[0], value=row[1])
                entry.save(commit=False)

            line = line + 1
        Config.commit()
        csvfile.close()
        print "Imported", line - 1, "config entries."
    except csv.Error:
        print "Error importing %s in line %d" % (args.file, line)
    except IOError:
        print "No such file: %s" % args.file
Example #2
0
def import_config(args):
    """
    Imports the config data of a csv file into the config table.

    :param args: A list with arguments from the argument parser
    :type args: namespace
    """
    Config.query().truncate()
    print "Importing config from", args.file

    try:
        csvfile, reader, hasHeader = utils.get_csv(args.file)
        line = 0

        for row in reader:
            if line != 0 or (line == 0 and not hasHeader):
                entry = Config(key=row[0], value=row[1])
                entry.save(commit=False)

            line = line + 1
        Config.commit()
        csvfile.close()
        print "Imported", line - 1, "config entries."
    except csv.Error:
        print "Error importing %s in line %d" % (args.file, line)
    except IOError:
        print "No such file: %s" % args.file
Example #3
0
def get_config(args):
    """
    Returns a dictionary of config values
    """

    dict = {}

    # ELO
    func = Config.query().get(key="elo.chess.function")
    if func is None:
        func = lambda x: (1 / (1 + (10 ** (x / 400.0))))
    else:
        func = eval(func.value.value)
    dict["elo.chess.function"] = func

    k = Config.query().get(key="elo.chess.k.fide.default")
    if k is None:
        k = 25
    else:
        k = float(k.value.value)
    dict["elo.chess.k"] = k

    return dict
Example #4
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from pychallenge.models import Config, Match1on1, Player, Rank_Elo, Rank_Glicko

if __name__ == "__main__":
    Config.create()
    Match1on1.create()
    Player.create()
    Rank_Elo.create()
    Rank_Glicko.create()