add progress bar when checking for infeasibility
This commit is contained in:
parent
29cae8f139
commit
2a230d1444
2 changed files with 21 additions and 21 deletions
|
@ -24,7 +24,7 @@ def update_trivially_feasible_games(variant_id):
|
|||
variant: variants.Variant = variants.Variant.from_db(variant_id)
|
||||
database.cur.execute("SELECT seed FROM seeds WHERE variant_id = (%s) AND feasible is null", (variant_id,))
|
||||
seeds = database.cur.fetchall()
|
||||
logger.info('Checking variant {} (id {}), found {} seeds to check...'.format(variant.name, variant_id, len(seeds)))
|
||||
logger.verbose('Checking variant {} (id {}), found {} seeds to check...'.format(variant.name, variant_id, len(seeds)))
|
||||
|
||||
with alive_progress.alive_bar(total=len(seeds), title='{} ({})'.format(variant.name, variant_id)) as bar:
|
||||
for (seed,) in seeds:
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
from enum import Enum
|
||||
from typing import List
|
||||
|
||||
import alive_progress
|
||||
|
||||
from hanabi import database
|
||||
from hanabi import logger
|
||||
from hanabi import hanab_game
|
||||
|
@ -172,24 +174,22 @@ def run_on_database(variant_id):
|
|||
(variant_id,)
|
||||
)
|
||||
res = database.cur.fetchall()
|
||||
logger.info("Checking {} seeds of variant {} for infeasibility".format(len(res), variant_id))
|
||||
for (seed, num_players, deck_str) in res:
|
||||
deck = compress.decompress_deck(deck_str)
|
||||
reasons = analyze(hanab_game.HanabiInstance(deck, num_players))
|
||||
if reasons:
|
||||
print("found infeasible seed {}: {}".format(seed, reasons))
|
||||
else:
|
||||
print("found nothing for seed {}".format(seed))
|
||||
for reason in reasons:
|
||||
database.cur.execute(
|
||||
"INSERT INTO score_upper_bounds (seed, score_upper_bound, reason) "
|
||||
"VALUES (%s,%s,%s) "
|
||||
"ON CONFLICT (seed, reason) DO UPDATE "
|
||||
"SET score_upper_bound = EXCLUDED.score_upper_bound",
|
||||
(seed, reason.score_upper_bound, reason.type.value)
|
||||
)
|
||||
database.cur.execute(
|
||||
"UPDATE seeds SET feasible = (%s) WHERE seed = (%s)",
|
||||
(False, seed)
|
||||
)
|
||||
logger.verbose("Checking {} seeds of variant {} for infeasibility".format(len(res), variant_id))
|
||||
with alive_progress.alive_bar(total=len(res), title='Check for infeasibility reasons in var {}'.format(variant_id)) as bar:
|
||||
for (seed, num_players, deck_str) in res:
|
||||
deck = compress.decompress_deck(deck_str)
|
||||
reasons = analyze(hanab_game.HanabiInstance(deck, num_players))
|
||||
for reason in reasons:
|
||||
database.cur.execute(
|
||||
"INSERT INTO score_upper_bounds (seed, score_upper_bound, reason) "
|
||||
"VALUES (%s,%s,%s) "
|
||||
"ON CONFLICT (seed, reason) DO UPDATE "
|
||||
"SET score_upper_bound = EXCLUDED.score_upper_bound",
|
||||
(seed, reason.score_upper_bound, reason.type.value)
|
||||
)
|
||||
database.cur.execute(
|
||||
"UPDATE seeds SET feasible = (%s) WHERE seed = (%s)",
|
||||
(False, seed)
|
||||
)
|
||||
bar()
|
||||
database.conn.commit()
|
||||
|
|
Loading…
Reference in a new issue