Example #1
0
def delete_record(sex, tour_id, rnd, left_id, right_id):
    handle = dbsa.open_db(sex, instance=DB_INSTANCE)
    handle.query_matches()
    mrec = dbsa.MatchRec(
        date=datetime.date.today(),
        tour_id=tour_id,
        rnd=rnd,
        left_id=left_id,
        right_id=right_id,
        detailed_score="",
        score="",
    )
    mrecs = co.find_all(
        handle.records,
        (lambda o: o.tour_id == mrec.tour_id and o.rnd == mrec.rnd and o.
         left_id == mrec.left_id and o.right_id == mrec.right_id),
    )
    if mrecs and len(mrecs) == 1:
        handle.delete_obj(mrecs[0])
        handle.commit()
        print(
            f"deleted {sex} tour_id {tour_id} rnd {rnd} pid1 {left_id} pid2 {right_id}"
        )
    else:
        print(f"fail delete mrecs {mrecs}")
        print(
            f"fail delete {sex} tour_id {tour_id} rnd {rnd} pid1 {left_id} pid2 {right_id}"
        )
Example #2
0
    def ident_by_players(self, tours, fst_id, snd_id):
        def ident_in_tour():
            for matches in tour.matches_from_rnd.values():
                for m in matches:
                    if m.score is None and (
                        (
                            m.first_player.ident == fst_id
                            and m.second_player.ident == snd_id
                        )
                        or (
                            m.first_player.ident == snd_id
                            and m.second_player.ident == fst_id
                        )
                    ):
                        self.tour_id = tour.ident
                        self.tour_info.level = tour.level
                        self.tour_info.surface = tour.surface
                        return True
            return False

        for tour in co.find_all(tours, lambda t: t.name == self.tour_name):
            if ident_in_tour():
                return True
        # try find tour without tour_name equal (maybe Davis/Fed Cup?)
        for tour in tours:
            if ident_in_tour():
                return True
        return False
def find_tail_tour_by_attr(sex, tour_name, level, surface):
    if sex not in tail_tours_from_sex:
        init_tail_tours(sex)

    if not sex or not tour_name or not level or not surface:
        msg = (
            "nofull attr find_tail_tour_by_attr sex: {} tn: {} lev: {} surf: {}".format(
                sex, tour_name, level, surface
            )
        )
        log.error(msg)
    if level == "main":
        eq_cond = (
            lambda t: t.name == tour_name
            and t.level in ("main", "masters")
            and t.surface == surface
        )
    else:
        eq_cond = (
            lambda t: t.name == tour_name and t.level == level and t.surface == surface
        )
    tailtours = co.find_all(tail_tours_from_sex[sex], eq_cond)
    if len(tailtours) == 1:
        return tailtours[0]
    elif len(tailtours) == 2:
        t1, t2 = tailtours[0], tailtours[1]
        if t1.date != t2.date:
            return t1 if t1.date > t2.date else t2
Example #4
0
def gameIsOver(gameThread: list, filenames: list, server: IO) -> None:
    scores = []
    for gt in gameThread:
        gt.join()
    for filename in filenames:
        with open(filename, 'r') as fin:
            lastLine = fin.readlines()[-1]
        scores.append(numInStr(lastLine))
    winners = find_all(max(scores), scores)
    winstr = ["Player {} has won with a balance of {} money".format(w+1, scores[w]) for w in winners]
    server.tell("geustKDEV", "Yolo")
    for w in winstr:
        server.tell(P1, w)
        server.tell(P2, w)
        server.tell("geustKDEV", "Yolo")
        print(w)
    print("Game is over")
    exit()
import common

DRY_RUN = True  # if this script will actually change anything

new_values = {
    ("Simulation", "samples"): 1000,
    ("Simulation", "samples_spacing"): 1000,
}

if __name__ == "__main__":

    for file, data in common.find_all("Sims/Serie/"):
        assert data is not None
        setup, _ = common.load(file, data)
        print(f"Simulation {file}")
        for section, name in new_values.keys():
            old_val = setup.getint(section, name)
            if old_val != new_values[(section, name)]:
                print(f"Correcting old {name} {old_val} with new {new_values[(section, name)]}")
                setup.set(section, name, str(new_values[(section, name)]))  # changing data in memory...

        if not DRY_RUN:
            with open(file, "w") as out:
                setup.write(out)
import os
import common
import multiprocessing

if __name__ == "__main__":
    print(f"Detected {multiprocessing.cpu_count()} cpus...")
    pool = multiprocessing.Pool(processes=multiprocessing.cpu_count() - 1)

    for file, data in common.find_all("Sims"):
        print(f"Found setup file {file}")
        if data is not None:
            if not common.is_modified(file, data):  # simulation already done
                print(f"Found up-to-date data file {data}")
                continue
            print(f"Found old data file {data}")
        else:
            print("No data file found")
            data = os.path.splitext(file)[0] + common.DATA_EXT
        print(f"Adding {file} to the pool...")
        pool.apply_async(common.do_simulation,
                         (file, data))  # add the task to the pool

    pool.close()  # no more work
    print("Waiting for completion...")
    pool.join()  # wait until all work is done
    print("Done.")
Example #7
0
def testFindAll():
    tests = [(1, [1, 2, 3, 4, 5]), (2, [1, 2, 3, 3, 2]), (3, [3, 3, 3])]
    expected = [[0], [1, 4], [0, 1, 2]]
    for t, e in zip(tests, expected):
        result = common.find_all(t[0], t[1])
        yield result, result == e