Example #1
0
def create_character_data_list(request, formatter):
    table = Table()

    characters = load_json_from_page(request, None, u"CharacterList", u"characters") or []
    header_row = TitleRow()
    newline = formatter.linebreak(preformatted=False)
    header_row.cells.append(TitleCell(u"キャラクター", formatted=True, cls=["center"]))
    header_row.cells.append(TitleCell(u"よろけにくさ", formatted=True, cls=["center"]))
    header_row.cells.append(TitleCell(u"ジャンプ%s上昇力" % newline, formatted=True, cls=["center"]))
    header_row.cells.append(TitleCell(u"空中ダッシュ%s初速度" % newline, formatted=True, cls=["center"]))
    header_row.cells.append(TitleCell(u"空中ダッシュ%s最終速度" % newline, formatted=True, cls=["center"]))
    header_row.cells.append(TitleCell(u"腕力", formatted=True, cls=["center"]))
    header_row.cells.append(TitleCell(u"格闘距離", formatted=True, cls=["center"]))
    table.rows.append(header_row)

    for character_name in characters:
        c = load_json_from_page(request, None, character_name, u"character") or {}
        data = c.get(u"キャラクターデータ", {})
        row = Row()
        row.cells.append(Cell(None, character_name, cls=["center"]))
        row.cells.append(Cell(None, data.get(u"よろけにくさ", u""), cls=["center"]))
        row.cells.append(Cell(None, data.get(u"ジャンプ上昇力", u""), cls=["center"]))
        row.cells.append(Cell(None, data.get(u"空中ダッシュ初速度", u""), cls=["center"]))
        row.cells.append(Cell(None, data.get(u"空中ダッシュ最終速度", u""), cls=["center"]))
        row.cells.append(Cell(None, data.get(u"腕力", u""), cls=["center"]))
        row.cells.append(Cell(None, u"%dm" % data.get(u"格闘距離", 0), cls=["right"]))
        table.rows.append(row)

    html_table = table.toHtmlTable(generate_header=False)
    return html_table.format(formatter)
Example #2
0
def create_wp_data(request, parser, formatter, requested_wps):
    j = load_json_from_page(request, parser, requested_wps[0], u'wp') or {}
    if not j:
        return u'no wp data'
    wp_name = j.get(u'名称', u'')

    table = Table()

    text = formatter.linebreak(preformatted=False)
    text += u"""
    コスト: %(cost)s 耐久力: %(life)s 格闘補正: x%(melee)s倍 タイプ: %(type)s 入手条件: %(howtoget)s\n
    """ % { u'cost': j.get(u'コスト', None) or u'???',
            u'life': j.get(u'耐久力', None) or u'???',
            u'melee': j.get(u'格闘補正', None) or u'???',
            u'type': j.get(u'タイプ', None) or u'???',
            u'howtoget': j.get(u'入手条件', u'') or u'???'}

    weapon_names = (j[u'右手武器'], j[u'左手武器'],
                    j[u'サイド武器'], j[u'タンデム武器'])
    place_names = (u'右手', u'左手', u'サイド', u'タンデム')
    for place_name, weapon_name in zip(place_names, weapon_names):
        name = weapon_name.get(u'名称', u'unknown')
        level = weapon_name.get(u'レベル', 0)
        row, subrow = get_leveled_weapon_and_subweapon_rows(
            request, j, formatter, name, level, place_name, wp_name)
        table.rows.append(row)
        if subrow:
            table.rows.append(subrow)
    html_table = table.toHtmlTable()
    text += html_table.format(formatter)
    text += get_tune_table(j, formatter)
    return text
Example #3
0
def create_weapon_data(request, parser, formatter, requested_weapons, **kw):
    j = load_json_from_page(request, parser, requested_weapons[0], u'weapon') or {}
    if not j:
        return u'No weapon data'
    table = Table()
    create_table(request, j, table, formatter, **kw)
    html_table = table.toHtmlTable()
    return (formatter.linebreak(preformatted=False)
            + formatter.text(u'弾種: %s' % j[u'弾種'])
            + html_table.format(formatter))
Example #4
0
    def process_callback(self, callback: CallbackQuery) -> None:
        records = self.collector.get_removal_queue(callback.chat_id)
        page = callback.data.get("page")
        table = Table(records, cast(int, page))

        self.client.edit_message_text(
            callback.chat_id,
            callback.message_id,
            table.build(),
            parse_mode="HTML",
            **table.get_reply_markup(),
        )

        self.client.answer_callback_query(callback.id)
Example #5
0
def create_temp_table(table: Table, connection) -> int:
    create_query = table.get_query_with_dist_sort_keys()
    grant_select = table.load_grant_select_statements()
    full_query = f"""
        drop table if exists {table.name}{temp_postfix};
        {create_query}
        {grant_select};
        """
    try:
        with connection.cursor() as cursor:
            cursor.execute(full_query)
    except psycopg2.ProgrammingError as e:
        raise TableCreationError(table, str(e))
    return arrow.now().timestamp
Example #6
0
class Game:
    def __init__(self, n_players):
        self.n_players = n_players
        self.player_names = []
        self.table = None

    def set_table(self, names):
        self.player_names = names
        self.table = Table([Player(n) for n in self.player_names])

    def remove_player(self, name):
        self.table.remove_player(name)

    def play_round_n(self, round_num=5):
        r = Round(self.table, round_num)
Example #7
0
def load_table_details(db_str: str, table: str) -> Table:
    with sqlite3.connect(db_str) as connection:
        connection.row_factory = sqlite3.Row
        try:
            cursor = connection.cursor()
            cursor.execute(
                """
                SELECT query, interval, 
                    config, last_created, 
                    force, waiting
                FROM tables
                WHERE table_name = ?
            """,
                (table, ),
            )
            row = cursor.fetchone()

            # noinspection PyTypeChecker
            return Table(
                name=table,
                query=row["query"],
                interval=row["interval"],
                config=json.loads(row["config"]),
                last_created=row["last_created"],
                force=row["force"],
                waiting=row["waiting"],
            )

        except TypeError:
            raise TableNotFoundInDBError(table)
Example #8
0
def macro_IncludeWeapons(macro, _trailing_args=[]):
    request = macro.request
    formatter = macro.formatter
    parser = macro.parser

    requested_weapons = _trailing_args
    if not requested_weapons:
        # assume the caller requested to show a weapon data of the current page.
        requested_weapons = [macro.formatter.page.page_name]
    else:
        parser = None
    requested_weapons.reverse()
    
    tables = []
    all_rows = []
    existing_weapons = []
    for weapon_name in requested_weapons:
        w = load_json_from_page(request, parser, weapon_name, u'weapon') or {}
        table = Table()
        if w:
            WeaponData.create_table(request, w, table, formatter, show_wp_owners=True)
            existing_weapons.append(weapon_name)
            all_rows.extend(table.rows)
            tables.append(table)

    table.remove_empty_columns(all_rows)

    html_tables = []
    for table in tables:
        html_tables.append(table.toHtmlTable(remove_empty_columns=False))

    html_rows = []
    for (weapon_name, html_table) in zip(existing_weapons, html_tables):
        row_cells = []
        row_cells.append(HtmlCell(
            formatter.pagelink(True, weapon_name) + formatter.text(weapon_name) + formatter.pagelink(False),
            attrs={u'colspan': (u'%d' % len(all_rows[0].cells))},
            formatted=True
        ))
        # row_cells has only 1 column because the all cells are colspan-ed.
        html_rows.append(HtmlRow(row_cells, cls=[u'wheader left']))
        html_rows.extend(html_table.rows)

    final_table = HtmlTable(html_rows)
    return final_table.format(formatter)
Example #9
0
def build_table_configs(graph: nx.DiGraph, views_path: str) -> List[Table]:
    nodes = dict(graph.nodes(data=True))
    return [
        Table(
            table,
            data["contents"],
            data["interval"],
            parse_table_config(table, views_path),
        ) for table, data in nodes.items()
    ]
Example #10
0
 def process(self, message: Message) -> None:
     records = self.collector.get_removal_queue(message.chat.id)
     table = Table(records, 1)
     self.client.reply(message, table.build(), **table.get_reply_markup())
Example #11
0
 def set_table(self, names):
     self.player_names = names
     self.table = Table([Player(n) for n in self.player_names])
Example #12
0
 def initialize_table(self):
     self.table = Table(self.players)
Example #13
0
from play.play_round import Round
from utils.player import Player
from utils.table import Table
import random

player_names = ['anil', 'pogo', 'mangal', 'ramya', 'harsha']
players = [Player(name) for name in player_names]
table = Table(players)

r = Round(table)
print(r.table)
r.table.move_player_to_front_by_name('ramya')
print(r.table)
r.table.move_player_to_front_by_name('harsha')
print(r.table)
# r.table.move_dealer()
# print(r.table)
r.table.remove_player("anil")
print(r.table)

print("Trump is : {}".format(r.trump_card))

# cards_played = {'anil': random.choice(players[0].hand.cards),
#                 'pogo': random.choice(players[1].hand.cards),
#                 'mangal': random.choice(players[2].hand.cards),
#                 'ramya': random.choice(players[3].hand.cards),
#                 'harsha': random.choice(players[4].hand.cards)}
#
# r.play_round(cards_played)
# print(r.players)
    if not test_results:
        drop_temp_table(table.name, connection)
        return

    replace_old_table(table.name, connection)
    drop_old_table(table.name, connection)
    connection.close()


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("table", help="table to create", type=str)
    parser.add_argument("--path",
                        "-p",
                        default="./views/",
                        help="folder containing the views")
    parser.add_argument("--verbose",
                        "-v",
                        default=False,
                        help="Verbose",
                        action="store_true")
    args = parser.parse_args()

    table = Table(
        name=args.table,
        query=load_select_query(args.path, args.table),
        interval=None,
        config=parse_table_config(args.table, args.path),
    )
    create_table(table, args.path, args.verbose)