コード例 #1
0
ファイル: io.py プロジェクト: sobulik/hooshek
def load():
    """return Event instance"""
    event = yaml.load("event.yaml")
    event = validate(event)

    # unique key check
    uniqueCounter = collections.Counter(
        map(lambda x: (x["age_min"], x["age_max"], x["sex"]), event["races"]))
    for i in uniqueCounter:
        if uniqueCounter[i] > 1:
            raise Exception("Event file race " + str(i) + " defined " +
                            str(uniqueCounter[i]) + " times")

    for race in event["races"]:
        if (int(race["age_min"]) > int(race["age_max"])):
            raise Exception("age_min higher than age_max for a race")

        if "eval" in race:
            for e in race["eval"]:
                if (int(e["age_min"]) > int(e["age_max"])):
                    raise Exception(
                        "age_min higher than age_max for an evaluation")
                if (int(e["age_min"]) < int(race["age_min"])):
                    raise Exception(
                        "age_min in evaluation lower than age_min for a race")
                if (int(e["age_max"]) > int(race["age_max"])):
                    raise Exception(
                        "age_max in evaluation higher than age_max for a race")

    return Event(event)
コード例 #2
0
def build(clubs, primaryKeyCheck=True):
    """return a list of Athlete instances"""
    athletes = yaml.load("athletes.yaml")
    athletes = validate(athletes)

    # primary key check
    if primaryKeyCheck:
        idCounter = collections.Counter(map(lambda x: x["id"], filter(lambda x: "id" in x, athletes["athletes"])))
        for i in idCounter:
            if idCounter[i] > 1:
                raise Exception("Athletes file athlete id " + str(i) + " defined " + str(idCounter[i]) + " times")

    # unique key check
    uniqueCounter = collections.Counter(map(lambda x: (x["name"], x["surname"], x["born"]), athletes["athletes"]))
    for i in uniqueCounter:
        if uniqueCounter[i] > 1:
            raise Exception("Athletes file athlete " + str(i) + " defined " + str(uniqueCounter[i]) + " times")

    # associate clubs
    for a in athletes["athletes"]:
        if "club" in a:
            if a["club"] in clubs:
                a["club"] = clubs[a["club"]]
            else:
                raise Exception("Club " + a["club"] + " of athlete " + a["surname"] + "not defined in clubs")

    return tuple(map(lambda x: Athlete(x), athletes["athletes"]))
コード例 #3
0
ファイル: io.py プロジェクト: janhalama/hooshek
def load():
    """return a list of Athlete instances"""
    if os.path.exists("athletes.yaml"):
        raw = yaml.load("athletes.yaml")
    else:
        raw = None

    sanity_check(raw)

    return tuple(map(lambda x: Athlete(x), raw["athletes"]))
コード例 #4
0
ファイル: io.py プロジェクト: janhalama/hooshek
def load():
    """return a dictionary of Club instances"""
    if os.path.exists("clubs.yaml"):
        raw = yaml.load("clubs.yaml")
    else:
        raw = None

    sanity_check(raw)

    return {c.id: c for c in map(lambda x: Club(x), raw["clubs"])}
コード例 #5
0
ファイル: io.py プロジェクト: janhalama/hooshek
def load():
    """load start list"""
    if os.path.exists("start.yaml"):
        raw = yaml.load("start.yaml")
    else:
        raw = None

    sanity_check(raw)

    return raw
コード例 #6
0
def load():
    """return Event instance"""
    if os.path.exists("event.yaml"):
        raw = yaml.load("event.yaml")
    else:
        raw = None

    sanity_check(raw)

    return Event(raw)
コード例 #7
0
ファイル: io.py プロジェクト: janhalama/hooshek
def load():
    """return a list of finish times"""
    if os.path.exists("finish.yaml"):
        raw = yaml.load("finish.yaml")
    else:
        raw = None

    sanity_check(raw)

    return tuple(raw)
コード例 #8
0
def load():
    """return a list of finish times"""
    finish = yaml.load("finish.yaml")
    finish = validate(finish)
        
    # primary key check
    idCounter = collections.Counter(map(lambda x: x["id"], finish))
    for i in idCounter:
        if idCounter[i] > 1:
            raise Exception("Finish file result for id " + str(i) + " defined " + str(idCounter[i]) + " times")

    return tuple(finish)
コード例 #9
0
def load():
    """return a dictionary of Club instances"""
    clubs = yaml.load("clubs.yaml")
    clubs = validate(clubs)

    # primary key check
    idCounter = collections.Counter(map(lambda x: x["id"], clubs["clubs"]))
    for i in idCounter:
        if idCounter[i] > 1:
            raise Exception("Clubs file club id " + i + " defined " +
                            str(idCounter[i]) + " times")

    return {c.id: c for c in map(lambda x: Club(x), clubs["clubs"])}