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)
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"]))
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"]))
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"])}
def load(): """load start list""" if os.path.exists("start.yaml"): raw = yaml.load("start.yaml") else: raw = None sanity_check(raw) return raw
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)
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)
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)
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"])}